Cannot send email using in

Posted on 2010-08-31
Last Modified: 2012-05-10
I am trying to send an email using the net.mail class in but am getting an error "The specified string is not in the form required for an e-mail address.". I have placed each variable in the watch folder and nothing I can find is out of the ordinary. In fact, I turned all variables off and still get the error. I have attached the code and the stack error information. Can someone help?

--Stack Error Message
System.FormatException was unhandled by user code
  Message="The specified string is not in the form required for an e-mail address."
       at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)
       at System.Net.Mail.MailAddress.ParseValue(String address)
       at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding)
       at System.Net.Mail.MailAddress..ctor(String address)
       at System.Net.Mail.MailMessage..ctor()
       at RemitWeb.RemitWeb.Email_Services.Email.Email_Response_Send(String EmailBC, String EmailBody, String EmailCC, String EmailFrom, String EmailSubject, String EmailTo) in C:\Documents and Settings\rwas\My Documents\Visual Studio 2008\Projects\RemitWebNew\RemitWeb\code\EmailServices.vb:line 170
       at RemitWeb.RemitWeb.Email_Services.Email.Response(String FirstName, String LastName, String EmailBC, String EmailID, String EmailCC, String EmailFrom, String EmailSubject, String EmailTo, String EmailTitle, String Misc1, String Misc2, String Misc3) in C:\Documents and Settings\rwas\My Documents\Visual Studio 2008\Projects\RemitWebNew\RemitWeb\code\EmailServices.vb:line 28
       at RemitWeb.exec_UploadSummaryDaily.send_daily_file_upload_summary() in C:\Documents and Settings\rwas\My Documents\Visual Studio 2008\Projects\RemitWebNew\RemitWeb\utilities\exec_UploadSummaryDaily.aspx.vb:line 18
       at RemitWeb.exec_UploadSummaryDaily.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\rwas\My Documents\Visual Studio 2008\Projects\RemitWebNew\RemitWeb\utilities\exec_UploadSummaryDaily.aspx.vb:line 6
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

--Code to send e-mail
        Private Shared Sub Email_Response_Send(ByVal EmailBC As String, ByVal EmailBody As String, ByVal EmailCC As String, ByVal EmailFrom As String, ByVal EmailSubject As String, ByVal EmailTo As String)

            Dim mMailMessage As New MailMessage()
            Dim objPicture As LinkedResource
            Dim objPicture2 As LinkedResource
            Dim objAVHTML As AlternateView

            'Action to send entire e-mail
            objAVHTML = AlternateView.CreateAlternateViewFromString(EmailBody, Nothing, "Text/html")

            'Header Image
            objPicture = New LinkedResource("E:\Web_Resources\images\test_email_header.jpg")
            objPicture.ContentId = "emailheader01"

            'Footer Image
            objPicture2 = New LinkedResource("E:\Web_Resources\images\test_email_logo.jpg")
            objPicture2.ContentId = "emailfooter01"

            mMailMessage.From = New MailAddress(EmailFrom)
            mMailMessage.To.Add(New MailAddress(EmailTo))

            'Add BCC if populated
            If EmailBC <> "" Then
                mMailMessage.Bcc.Add(New MailAddress(EmailBC))
            End If

            'Add CC if populated
            If EmailCC <> "" Then
                mMailMessage.CC.Add(New MailAddress(EmailCC))
            End If

            'Add Subject line to email
            mMailMessage.Subject = EmailSubject

            'Add Body to email
            mMailMessage.Body = EmailBody

            'Set Format of email to html
            mMailMessage.IsBodyHtml = True

            'Set Priority of email to high
            mMailMessage.Priority = MailPriority.High

            'Initiates a new instance of SmtpClient
            Dim mSmtpClient As New SmtpClient("", 2525)

            'Send the e-mail
            Catch ex As Exception

            End Try

        End Sub
Question by:OB1Canobie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 17

Accepted Solution

Zhaolai earned 500 total points
ID: 33567689
Apparently it complaints the format of email address, double check all the email addresses in To, CC and BCC. If it has more than one email address in any one of them, they need to be separated by comma ",".

Author Comment

ID: 33567739
I'm really confused because I cannot find where the e-mail is an issue. Each e-mail is valid. Nothing really out of the ordinary.

Author Comment

ID: 33567767
Actually, the error stops on the line where I declare the mMailMessage As New MailMessage.  I didn't even add the e-mail to the variable yet. Does this make any sense?
LVL 30

Expert Comment

ID: 33567925
That does not make sense. Sounds more like you are runing code that hasnt compiled or are debugging with the incorrect version of the file.

Author Comment

ID: 33567965
Found the issue. It was in the Web Config which was assigning a default from ..incorrect format. Thanks for the help.

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question