ICantSee
asked on
The specified string is not in the form required for an e-mail address system.net.mail
I am trying to email the results of a form to myself, for now. I keep getting "The specified string is not in the form required for an e-mail address"
The address is hard coded in and is correct:
When I view the mailbody it has all of the information that I want in it.
the odd thing is I copied and pasted this code from another project that I have done. It works fine.
Any help will be appreciated
The address is hard coded in and is correct:
Dim myMessage As MailMessage = New MailMessage()
myMessage.Subject = "New Benefit Time Request"
myMessage.Body = mailBody
myMessage.From = New MailAddress("kba_forms@keystoneblind.org")
myMessage.IsBodyHtml = True
myMessage.To.Add(New MailAddress("kevin@keystoneblind.org"))
When I view the mailbody it has all of the information that I want in it.
the odd thing is I copied and pasted this code from another project that I have done. It works fine.
Any help will be appreciated
ASKER
System.FormatException was unhandled by user code
HResult=-2146233033
Message=The specified string is not in the form required for an e-mail address.
Source=System
StackTrace:
at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)
at System.Net.Mail.MailAddressParser.ParseAddress(String data)
at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding)
at System.Net.Mail.MailMessage..ctor()
at BenefitTime_KevinBly_Default.SubmitFormButton_Click(Object sender, EventArgs e) in \\data\kba\UserFiles\kevin\My Documents\Projects\websites\2014\Service Forms\BenefitTime\kevinbly\Default.aspx.vb:line 76
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
If you create a mailaddress with just one parameter it should be in the form
"Tom Smith <tsmith@hotmail.com>"
if the format is not recognised then a format exception will be thrown
Exception - Condition
ArgumentNullException - address is null.
ArgumentException - address is String.Empty ("").
FormatException - address is not in a recognized format.
"Tom Smith <tsmith@hotmail.com>"
if the format is not recognised then a format exception will be thrown
Exception - Condition
ArgumentNullException - address is null.
ArgumentException - address is String.Empty ("").
FormatException - address is not in a recognized format.
The code you show us is not the code that triggers the exception, so we do not see the whole thing.
Your third post shows that the problem in on line 76. A lot can happen between the code in your first post and line 76.
Looking at your second post, there is something about a DateTime (Date) object, which is strange for an error in a mail address parsing routine. Is it possible that your MailAddress is modified somewhere with something that has a date in it?
Your third post shows that the problem in on line 76. A lot can happen between the code in your first post and line 76.
Looking at your second post, there is something about a DateTime (Date) object, which is strange for an error in a mail address parsing routine. Is it possible that your MailAddress is modified somewhere with something that has a date in it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@james. I have no clue what you are trying to tell me. I have sifted through the items you mentioned before I posted this question and have not been able to resolve my issue. Sorry.
Did you try changing the format of your email addresses as I posted?
ASKER
my email address is hand coded in. kevin@keystoneblind.org
no misspelling, even retyped it a few times.
this same code was copied and pasted from another app that I have running right now. No issues with it.
no misspelling, even retyped it a few times.
this same code was copied and pasted from another app that I have running right now. No issues with it.
ASKER
I' sorry. I didn't realize you were the same person.
I don't understand what line 76 in the actual sub routine means?
I don't understand what line 76 in the actual sub routine means?
I'm not, there are two experts commenting on this.
It should be "kevin <kevin@keystoneblind.org>" rather than "kevin@keystoneblind.org"
The mail message doesn't understand the format of the string that you are providing
It should be "kevin <kevin@keystoneblind.org>"
The mail message doesn't understand the format of the string that you are providing
ASKER
myMessage.To.Add(New MailAddress("kevin <kevin@keystoneblind.org>"))
Throws the same error.
I am using VB and system.net.mail
As I said, the copy and pasted the exact code from another app that I built, and it runs flawlessly. I really don't get it.
What version of VB are you using and what version of the framework
And did you change the "from" address to be in that format as well as the "to"
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It was the final answer. No one really steered me to the web.config file.
ASKER