473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Email error

Hello

I have the following code in a contact form field in my aspx file:

Expand|Select|Wrap|Line Numbers
  1. <input type="email" name="user_email" class="form-control" placeholder="Email Address" required="required">
In my aspx.vb file, I have:

Expand|Select|Wrap|Line Numbers
  1. Dim Email As String = "useremail"
  2.  
  3. 'Request.Form - extract data from form fields
  4.  
  5. Dim useremail As String = Request.Form("user_email")
  6.  
  7. 'create the mail message
  8.  
  9. myMessage.From = New MailAddress("user_email") 'User email completed by user
When I look at the contact form through a browser, I see this:



My understanding with that error is that it is looking for a valid email address and it is not possible to do that because the Webmaster, who is creating this SMTP form, cannot possibly know the user's email address before he types it in.

user_email is not the variable, it is the name of the email field. Should it be the variable useremail? When I try that with the quotation marks it gives that same 'not in the form required for an email address error', and when I try it without the quotation marks, I get: Value cannot be null. Parameter name: address

Thanks for any advice.
Attached Images
File Type: jpg source_error.jpg (40.1 KB, 394 views)
Nov 29 '17 #1

✓ answered by Frinavale

So, when you are working with a Web Forms application it is probably best to stick with the way that it was intended to be used.

Microsoft has made tools available to you, such as the asp.net TextBox control that makes it easier than you think to interact with data in your server code.

The TextBox control is a .net object that exposes properties like the "Text" property so that you can retrieve this information without having to go through the Request object like you would have to do in classic asp or php type environments.

For example, say you have your ASP.NET web form as such:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4.     <title></title>
  5.     <style type="text/css">
  6.         .prompt
  7.         {
  8.             display: block;
  9.             font-weight: bold;
  10.         }
  11.         .messageTextArea, .textInput
  12.         {
  13.             width: 20em;
  14.         }
  15.         .messageTextArea
  16.         {
  17.             height: 20em;
  18.         }
  19.     </style>
  20. </head>
  21. <body>
  22.     <form id="form1" runat="server">
  23.     <div>
  24.         <div>
  25.             <span class="prompt">Please provide your email:</span>
  26.             <asp:TextBox ID="user_email" runat="server" CssClass="textInput" /></div>
  27.         <div>
  28.             <span class="prompt">Please provide your subject:</span>
  29.             <asp:TextBox ID="user_subject" runat="server" CssClass="textInput" />
  30.         </div>
  31.         <div>
  32.             <span class="prompt">Please provide your message:</span>
  33.             <asp:TextBox ID="user_message" runat="server" Wrap="true" TextMode="MultiLine" CssClass="messageTextArea" />
  34.         </div>
  35.         <asp:Button ID="SendEmail" runat="server" Text="Send Email" />
  36.     </div>
  37.     </form>
  38. </body>
  39. </html>
When ASP.NET sends this to the browser, it is converted into HTML and it looks like this:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head><title>
  4.  
  5. </title>
  6.     <style type="text/css">
  7.         .prompt
  8.         {
  9.             display: block;
  10.             font-weight: bold;
  11.         }
  12.         .messageTextArea, .textInput
  13.         {
  14.             width: 20em;
  15.         }
  16.         .messageTextArea
  17.         {
  18.             height: 20em;
  19.         }
  20.     </style>
  21. </head>
  22. <body>
  23.     <form method="post" action="./contact.aspx" id="form1">
  24. <div class="aspNetHidden">
  25. <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIODY2MjY4OThkZJqkRtnq0NOON5F088ku42vFoM2qk5VPCGYvsOj1lnC3" />
  26. </div>
  27.  
  28. <div class="aspNetHidden">
  29.  
  30.     <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CD2448B2" />
  31.     <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAWoASbgPc0NVNHyADJ8kYTN8WW+kaztJcywh7J3De2DyObVknTnR8DQ8XKfcR0YLpUfjPWxNAflCdG320Un8qULhm2+bBR3PLoxYiWNvjlmDhwLAUvc6M1f26OT+paV9sDCllv7rOjBDebf7FFjtYC1" />
  32. </div>
  33.     <div>
  34.         <div>
  35.             <span class="prompt">Please provide your email:</span>
  36.             <input name="user_email" type="text" id="user_email" class="textInput" /></div>
  37.         <div>
  38.             <span class="prompt">Please provide your subject:</span>
  39.             <input name="user_subject" type="text" id="user_subject" class="textInput" />
  40.         </div>
  41.         <div>
  42.             <span class="prompt">Please provide your message:</span>
  43.             <textarea name="user_message" rows="2" cols="20" id="user_message" class="messageTextArea">
  44. </textarea>
  45.         </div>
  46.         <input type="submit" name="SendEmail" value="Send Email" id="SendEmail" />
  47.     </div>
  48.     </form>
  49. </body>
  50. </html>
  51.  
ASP.NET automatically converts its objects into HTML for you when it sends the data down to the browser. Likewise, it automatically creates the .NET objects (the button and TextBox objects) and populates them with what the user supplies in the browser when the user submits the form.

So, this would be the VB.NET server code that would retrieve the information from the user based on what the user supplied in the browser:

Expand|Select|Wrap|Line Numbers
  1. Public Class contact
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.  
  6.     End Sub
  7.  
  8.  
  9.     Private Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click
  10.         Dim suppliedEmailText = user_email.Text
  11.         Dim suppliedSubjectText = user_subject.Text
  12.         Dim suppliedMessageText = user_message.Text
  13.  
  14.  
  15.     End Sub
  16. End Class
Notice that the SendEmail button object has a Click event? That event is created by ASP.NET when the user submits the form by clicking the button. When the button is created, the TextBoxes are also created. After they are initialized, they are populated with data that the user provided in the form in the browser.

After the event is created and the text boxes are populated, the server-side code for the page that handles the Click event is executed to do stuff...like retrieve the information the user provided (validate the information the user provided) and send the email (or not if the data isn't valid).

You should familiarize yourself with the ASP.NET Page Life Cycle so that you can understand how the process of sending and retrieving data works in Web Forms projects (along with understanding the events that occur in this process too)

For more information on how to send an email using .NET check out this Bytes article: Quick Reference on how to send an email using .NET

Let me know if you have any questions or problems.

ASP.NET is a pretty big topic!

10 2442
Frinavale
9,735 Expert Mod 8TB
Try adding an ID to your field so that you can get it properly on the server.
Expand|Select|Wrap|Line Numbers
  1. <input id="user_email"  type="email" name="user_email" class="form-control" placeholder="Email Address" required="required">
Nov 29 '17 #2
Hello Frinavale

Many thanks for your reply.

With that line of code you suggest in the aspx file and with this in the aspx.vb file

Expand|Select|Wrap|Line Numbers
  1. Line 26: 'create the mail message
  2. Line 27: 
  3. Line 28: myMessage.From = New MailAddress("user_email") 'User email completed by user I get the following error:
  4.  
Exception Details: System.FormatException: The specified string is not in the form required for an e-mail address.

However, with Line 28 like this:

Expand|Select|Wrap|Line Numbers
  1. Line 28: myMessage.From = New MailAddress(useremail) 'User email completed by user I get the following error:
I get the 'Value cannot be null. Parameter name: address' error.

Thanks again
Nov 29 '17 #3
Frinavale
9,735 Expert Mod 8TB
Hi Bluenose,

What type of web application did you create?
MVC or Web Forms?
Nov 30 '17 #4
Hello Frinavale

Thanks again for your reply.

It is a Web Forms site which, so far, only consists of 2-files (contact.aspx and contact.aspx.vb).
Nov 30 '17 #5
Hello Frinavale

Am I right in saying that when I have the following (stripped of HTML/CSS) code in my contact.asp code for the form fields:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="user_name" runat="server">
  2.  <input id="user_email" type="email" name="user_email">
  3.  <input type="text" name="user_subject">
  4.  <textarea name="message" id="user_message"></textarea>
that the following in my contact.aspx.vb is also correct:

Expand|Select|Wrap|Line Numbers
  1. Dim Name As String = "username" 'where username is the unknown variable of the user's name
  2.  
  3. Dim Email As String = "useremail" 'where useremail is the unknown variable of the user's email
  4.  
  5. Dim Subject As String = "usersubject" 'where usersubject is the unknown subject of the user
  6.  
  7. Dim Message As String = "usermessage" 'where usermessage is the unknown message the user will write
  8.  
  9. 'Request.Form - extract data from form fields
  10.  
  11. Dim username As String = Request.Form("user_name") 'where "user_name" is the known ID of the name field
  12.  
  13. Dim useremail As String = Request.Form("user_email") 'where "user_email" is the known ID of the email field
  14.  
  15. Dim usersubject As String = Request.Form("user_subject") 'where "user_subect" is the known ID of the subject field
  16.  
  17. Dim usermessage As String = Request.Form("user_message") 'where "user_message" is the known ID of the message field
  18.  
  19. 'create the mail message
  20.  
  21. myMessage.From = New MailAddress(useremail) 'User email completed by user
  22.  
  23. myMessage.To.Add(New MailAddress("info@mysite.net")) 'Address of the Webmaster who will receive the user's email message
  24.  
  25. myMessage.CC.Add(New MailAddress("info2@mysite.com")) 'Address of the Webmaster's assistant who will receive a copy of the user's message to the Webmaster
  26.  
  27. myMessage.Body = usermessage 'user's message to the Webmaster 
I get no green or red underlines in Visual Studio 2017 with the above.

Thank you again for your time.
Nov 30 '17 #6
Frinavale
9,735 Expert Mod 8TB
So, when you are working with a Web Forms application it is probably best to stick with the way that it was intended to be used.

Microsoft has made tools available to you, such as the asp.net TextBox control that makes it easier than you think to interact with data in your server code.

The TextBox control is a .net object that exposes properties like the "Text" property so that you can retrieve this information without having to go through the Request object like you would have to do in classic asp or php type environments.

For example, say you have your ASP.NET web form as such:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4.     <title></title>
  5.     <style type="text/css">
  6.         .prompt
  7.         {
  8.             display: block;
  9.             font-weight: bold;
  10.         }
  11.         .messageTextArea, .textInput
  12.         {
  13.             width: 20em;
  14.         }
  15.         .messageTextArea
  16.         {
  17.             height: 20em;
  18.         }
  19.     </style>
  20. </head>
  21. <body>
  22.     <form id="form1" runat="server">
  23.     <div>
  24.         <div>
  25.             <span class="prompt">Please provide your email:</span>
  26.             <asp:TextBox ID="user_email" runat="server" CssClass="textInput" /></div>
  27.         <div>
  28.             <span class="prompt">Please provide your subject:</span>
  29.             <asp:TextBox ID="user_subject" runat="server" CssClass="textInput" />
  30.         </div>
  31.         <div>
  32.             <span class="prompt">Please provide your message:</span>
  33.             <asp:TextBox ID="user_message" runat="server" Wrap="true" TextMode="MultiLine" CssClass="messageTextArea" />
  34.         </div>
  35.         <asp:Button ID="SendEmail" runat="server" Text="Send Email" />
  36.     </div>
  37.     </form>
  38. </body>
  39. </html>
When ASP.NET sends this to the browser, it is converted into HTML and it looks like this:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head><title>
  4.  
  5. </title>
  6.     <style type="text/css">
  7.         .prompt
  8.         {
  9.             display: block;
  10.             font-weight: bold;
  11.         }
  12.         .messageTextArea, .textInput
  13.         {
  14.             width: 20em;
  15.         }
  16.         .messageTextArea
  17.         {
  18.             height: 20em;
  19.         }
  20.     </style>
  21. </head>
  22. <body>
  23.     <form method="post" action="./contact.aspx" id="form1">
  24. <div class="aspNetHidden">
  25. <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUIODY2MjY4OThkZJqkRtnq0NOON5F088ku42vFoM2qk5VPCGYvsOj1lnC3" />
  26. </div>
  27.  
  28. <div class="aspNetHidden">
  29.  
  30.     <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CD2448B2" />
  31.     <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAWoASbgPc0NVNHyADJ8kYTN8WW+kaztJcywh7J3De2DyObVknTnR8DQ8XKfcR0YLpUfjPWxNAflCdG320Un8qULhm2+bBR3PLoxYiWNvjlmDhwLAUvc6M1f26OT+paV9sDCllv7rOjBDebf7FFjtYC1" />
  32. </div>
  33.     <div>
  34.         <div>
  35.             <span class="prompt">Please provide your email:</span>
  36.             <input name="user_email" type="text" id="user_email" class="textInput" /></div>
  37.         <div>
  38.             <span class="prompt">Please provide your subject:</span>
  39.             <input name="user_subject" type="text" id="user_subject" class="textInput" />
  40.         </div>
  41.         <div>
  42.             <span class="prompt">Please provide your message:</span>
  43.             <textarea name="user_message" rows="2" cols="20" id="user_message" class="messageTextArea">
  44. </textarea>
  45.         </div>
  46.         <input type="submit" name="SendEmail" value="Send Email" id="SendEmail" />
  47.     </div>
  48.     </form>
  49. </body>
  50. </html>
  51.  
ASP.NET automatically converts its objects into HTML for you when it sends the data down to the browser. Likewise, it automatically creates the .NET objects (the button and TextBox objects) and populates them with what the user supplies in the browser when the user submits the form.

So, this would be the VB.NET server code that would retrieve the information from the user based on what the user supplied in the browser:

Expand|Select|Wrap|Line Numbers
  1. Public Class contact
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.  
  6.     End Sub
  7.  
  8.  
  9.     Private Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click
  10.         Dim suppliedEmailText = user_email.Text
  11.         Dim suppliedSubjectText = user_subject.Text
  12.         Dim suppliedMessageText = user_message.Text
  13.  
  14.  
  15.     End Sub
  16. End Class
Notice that the SendEmail button object has a Click event? That event is created by ASP.NET when the user submits the form by clicking the button. When the button is created, the TextBoxes are also created. After they are initialized, they are populated with data that the user provided in the form in the browser.

After the event is created and the text boxes are populated, the server-side code for the page that handles the Click event is executed to do stuff...like retrieve the information the user provided (validate the information the user provided) and send the email (or not if the data isn't valid).

You should familiarize yourself with the ASP.NET Page Life Cycle so that you can understand how the process of sending and retrieving data works in Web Forms projects (along with understanding the events that occur in this process too)

For more information on how to send an email using .NET check out this Bytes article: Quick Reference on how to send an email using .NET

Let me know if you have any questions or problems.

ASP.NET is a pretty big topic!
Dec 1 '17 #7
Many thanks for your detailed reply.

I will try to digest your code and go through the link you have kindly sent.

I have to admit, I almost never go to the Toolbox and seldom use anything in VS itself. I have never used 'Design View'. I was never really sure if those controls could be stylised - I know the 'file upload' box cannot be because I tried changing it once over hours and I was unsuccessful.

I think what you are saying is bypass what I have done so far (which is fine), and use the tools in VS and attempt to make them prettier than the default.

I have been doing it the hard way!

Many thanks, again, Frinavale, and I will copy and paste your reply and try to come to terms with it sooner rather than later.
Dec 1 '17 #8
Frinavale
9,735 Expert Mod 8TB
Since the tools provided in .NET are converted to HTML so that they can be displayed in a web browser, you can use CSS to style them just like any HTML element.

There are ways to style a file upload control; however it typically involves hiding the upload control on the page and hooking up the features it offers to other, style-able, controls like buttons and text inputs.
Dec 5 '17 #9
Yes, thanks.

I have started to style the <asp:TextBox> in Visual Studio 2017 - I will post a link when I have completed the 'contact' page (the one with the SMTP in it that you offered me advice about).

I have a couple of errors to resolve concerning

Expand|Select|Wrap|Line Numbers
  1. LblDate.Text = ReturnDate()
  2.  
  3.         user_name.Focus()
which I am trying to sort out.

Thanks again, Frinavale.
Dec 5 '17 #10
Frinavale
9,735 Expert Mod 8TB
Please remember that VB.NET code is run on the server which means using VB.NET code like user_name.Focus() won't accomplish anything.

You will have to use client-side technology (JavaScript) to set the focus on the field in the web browser.
Dec 5 '17 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Corey | last post by:
Hello, I have created a form that is sent via email and am getting the following error: Warning: mail() expects at most 5 parameters, 14 given in /home/sites/site324/web/order_form_test1.php...
0
by: David Stockwell | last post by:
Thanks to all who helped me learn the basics of python. I just completed my first project in python. It's not the best code in the world but it appears to work. It uses pythons 'class' ability...
1
by: jam | last post by:
Dear All, I am writing a console and it send a email out when it hits error it calls this static void SendErrorEmail(string error) { System.Web.Mail.MailMessage mail = new...
9
by: Hazz | last post by:
If I were to deploy components to clients whose Windows infrastructure is unknown, ie. not sure they have Microsoft Exchange running or not, how would I set up a kind of Dr. Watson like mechanism?...
0
by: hb | last post by:
Hi, I am migrate an ASP.Net site from a Windows 2000 Server to a Windows 2003 Server. But the email function stops working on Windows 2003 Server for this error: === The server rejected one or...
1
by: --=|3s|=-- | last post by:
I have added an email program to my vb .net project. 1 problem, everytime i press the send button, an error occurs... "CDO.message". Some help please :shock: Greetz ----== Posted via...
1
by: liuage | last post by:
Hello. I have a strange question about send email in .net. I use the following code to send email. Sub SendMail(ByVal mailFrom As String, _ ByVal mailTo As String, _ ByVal mailSubject As...
2
by: sunnyko | last post by:
Dear all I am using asp.net in a Small Business Server to send email out ! The programe work fine in XP but show the following error in Small Business Server. I don't know why.... Sunny ...
1
by: Sammy | last post by:
I am using the following code on a company that hosts our web site. I have noticed lately that their mail server/smtp is unavailable several times a minute for a second or two. This is causing my...
2
by: gduggan | last post by:
I hope someone can help me solve this problem. I have a client who is hosting their website on an Exchange server running Windows Server 2003 OS. They are currently unable to receive email from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.