0

I receive this error when my code executes from my Windows 2003 server, however from my Windows 7 dev machine the mail process works flawlessly every time. Project is configured for 2.0 framework. Is there a missing component that is needed on the server??

Error Detail.

[FormatException: The specified e-mail address is currently not supported.]
   System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName) +1138987
   System.Net.Mail.MailAddress.ParseValue(String address) +240
   System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) +85
   System.Net.Mail.MailAddress..ctor(String address) +8
   BizHelp.WebForm1.btnSendEmail_Click(Object sender, EventArgs e) +117
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Web.Config details (this is non-standard format for GoDaddy, but I must run my code on local network, hence I cannot use their relay server - and this works on my Windows 7 box)

<mailSettings>
      <smtp>
        <network host="smtpout.secureserver.net" defaultCredentials="false"
                 userName="xxxxx@sendtome.us" password="xxxxx"  enableSsl="false" port="80"/>
      </smtp>
</mailSettings>

VB Code:

Imports System.Net.Mail

Dim mm As New MailMessage(lblEmail.Text, "2manybooks@sentome.us")
mm.Subject = "Welcome to xxxx"
mm.IsBodyHtml = True

mm.Body = lblMail.Text.ToString
Dim smtp As New SmtpClient
smtp.Send(mm)

Note: lblEmail.text is a field containing a standard email address; that field is loaded from a database.

Any thoughts or suggestions? Thanks!!

Mike
  • 5
  • 1
  • 4
  • It looks as if the code is crashing on one particular address. Does it fail on every address or just one? – Ann L. Feb 26 '13 at 16:50
  • I've tried changing the From address - stills fails. Then I tried changing the To address - stills fails. – Mike Feb 26 '13 at 19:40
  • Note: the smtp.Send(mm) code is inside a TryCatch loop, but when the page fails, it fails without executing the Catch portion. – Mike Feb 26 '13 at 19:42
  • The stack trace you posted doesn't match the code sample you provided. The stack trace says you're instantiating the class `MailAddress`. The code has you instantiating `MailMessage`. Are you sure the error is occurring where you think it is? – Ann L. Feb 26 '13 at 20:21
  • I've been trying various alternatives, here's my original code: Dim ToAddress As New MailAddress(lblEmail.Text.ToString) Dim FromAddress As New MailAddress("2manybooks@sendtome.us") Dim mm As New MailMessage(FromAddress, ToAddress) mm.Subject = "Welcome to xxx" mm.IsBodyHtml = True – Mike Feb 27 '13 at 02:43

1 Answers1

0

The most likely thing to be happening is that one or more of the values for your ToAddress is just not a valid email address. I'm thinking it's the ToAddress because your FromAddress is hard-coded and looks valid.

Try putting a Debug.WriteLine("\"" + lblEmail.Text + "\"") statement right before you attempt to create the ToAddress. (The quotation marks are there in case the value is empty.) After the crash, inspect the Output window, Debug pane. Is there anything weird there? Anything that doesn't look like a valid address?

Ann L.
  • 13,760
  • 5
  • 35
  • 66
  • The error is with the ToAddress. I moved my project over to an XP box running VS2008 - it encountered the same error. And since I was debugging, it shows the specific line of code - the ToAddress. Now I can do some troubleshooting. I'll post what I discover. Thanks – Mike Feb 27 '13 at 15:56
  • I found the problem. When I pulled the ToAddress from the database, to improve Readability on the form, I inserted 'Email: ' prior to the actual address. Then I tried to send to that string - wrong. So I added code to strip out the 'Email: ' and now life is wonderful. Thanks! – Mike Mar 02 '13 at 19:27