MailMessage Problem

Discussion in 'ASP .Net' started by Wayne Wengert, Mar 12, 2006.

  1. Using the code below, I am trying to send an email from an ASP.NET 2.0 page
    but I get the error " The specified string is not in the form required for
    an e-mail address." when the "Dim Mailmsg..." line is executed. Since I
    haven't defined the from/to yet, I don't understand what it wants? Any
    insight on what causes this?


    =========================================
    Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    Dim Mailmsg As New System.Net.Mail.MailMessage
    Mailmsg.To.Clear()
    Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name
    <>")
    Mailmsg.From = New System.Net.Mail.MailAddress("From Name
    <>")
    Mailmsg.Subject = "(subject text)"
    Try
    Mailmsg.Body = "(message text here)"
    obj.Send(Mailmsg)
    Catch ex As Exception
    Response.Write("Error: " & ex.ToString())
    End Try
    =========================================
     
    Wayne Wengert, Mar 12, 2006
    #1
    1. Advertising

  2. re:
    > Since I haven't defined the from/to yet


    Actually, you *have* defined it, as :

    Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name <>")
    Mailmsg.From = New System.Net.Mail.MailAddress("From Name <>")

    It's expecting a mail address in the form :

    new MailAddress("", "Some Name");

    Try :

    Mailmsg.To.Add(New System.Net.Mail.MailAddress("", "To Name")
    Mailmsg.From = New System.Net.Mail.MailAddress("", "From Name")




    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Wayne Wengert" <> wrote in message
    news:%...
    > Using the code below, I am trying to send an email from an ASP.NET 2.0 page but I get the error "
    > The specified string is not in the form required for an e-mail address." when the "Dim Mailmsg..."
    > line is executed. Since I haven't defined the from/to yet, I don't understand what it wants? Any
    > insight on what causes this?
    >
    >
    > =========================================
    > Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    > Dim Mailmsg As New System.Net.Mail.MailMessage
    > Mailmsg.To.Clear()
    > Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name <>")
    > Mailmsg.From = New System.Net.Mail.MailAddress("From Name <>")
    > Mailmsg.Subject = "(subject text)"
    > Try
    > Mailmsg.Body = "(message text here)"
    > obj.Send(Mailmsg)
    > Catch ex As Exception
    > Response.Write("Error: " & ex.ToString())
    > End Try
    > =========================================
    >
     
    Juan T. Llibre, Mar 12, 2006
    #2
    1. Advertising

  3. I hsould have added...

    See http://msdn2.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx
    and http://msdn2.microsoft.com/en-us/library/1s17zfkf(VS.80).aspx



    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Juan T. Llibre" <> wrote in message
    news:...
    > re:
    >> Since I haven't defined the from/to yet

    >
    > Actually, you *have* defined it, as :
    >
    > Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name <>")
    > Mailmsg.From = New System.Net.Mail.MailAddress("From Name <>")
    >
    > It's expecting a mail address in the form :
    >
    > new MailAddress("", "Some Name");
    >
    > Try :
    >
    > Mailmsg.To.Add(New System.Net.Mail.MailAddress("", "To Name")
    > Mailmsg.From = New System.Net.Mail.MailAddress("", "From Name")
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "Wayne Wengert" <> wrote in message
    > news:%...
    >> Using the code below, I am trying to send an email from an ASP.NET 2.0 page but I get the error "
    >> The specified string is not in the form required for an e-mail address." when the "Dim
    >> Mailmsg..." line is executed. Since I haven't defined the from/to yet, I don't understand what it
    >> wants? Any insight on what causes this?
    >>
    >>
    >> =========================================
    >> Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    >> Dim Mailmsg As New System.Net.Mail.MailMessage
    >> Mailmsg.To.Clear()
    >> Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name <>")
    >> Mailmsg.From = New System.Net.Mail.MailAddress("From Name <>")
    >> Mailmsg.Subject = "(subject text)"
    >> Try
    >> Mailmsg.Body = "(message text here)"
    >> obj.Send(Mailmsg)
    >> Catch ex As Exception
    >> Response.Write("Error: " & ex.ToString())
    >> End Try
    >> =========================================
    >>

    >
    >
     
    Juan T. Llibre, Mar 12, 2006
    #3
  4. I'm confused. The error occurs on the "Dim Mailmsg..." before the To and
    From addresses are set?

    Wayne

    "Juan T. Llibre" <> wrote in message
    news:...
    > re:
    >> Since I haven't defined the from/to yet

    >
    > Actually, you *have* defined it, as :
    >
    > Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name
    > <>")
    > Mailmsg.From = New System.Net.Mail.MailAddress("From Name
    > <>")
    >
    > It's expecting a mail address in the form :
    >
    > new MailAddress("", "Some Name");
    >
    > Try :
    >
    > Mailmsg.To.Add(New System.Net.Mail.MailAddress("", "To
    > Name")
    > Mailmsg.From = New
    > System.Net.Mail.MailAddress("", "From Name")
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "Wayne Wengert" <> wrote in message
    > news:%...
    >> Using the code below, I am trying to send an email from an ASP.NET 2.0
    >> page but I get the error " The specified string is not in the form
    >> required for an e-mail address." when the "Dim Mailmsg..." line is
    >> executed. Since I haven't defined the from/to yet, I don't understand
    >> what it wants? Any insight on what causes this?
    >>
    >>
    >> =========================================
    >> Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    >> Dim Mailmsg As New System.Net.Mail.MailMessage
    >> Mailmsg.To.Clear()
    >> Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name
    >> <>")
    >> Mailmsg.From = New System.Net.Mail.MailAddress("From Name
    >> <>")
    >> Mailmsg.Subject = "(subject text)"
    >> Try
    >> Mailmsg.Body = "(message text here)"
    >> obj.Send(Mailmsg)
    >> Catch ex As Exception
    >> Response.Write("Error: " & ex.ToString())
    >> End Try
    >> =========================================
    >>

    >
    >
     
    Wayne Wengert, Mar 12, 2006
    #4
  5. Sure, that's standard OOP procedure.

    When you call an object, all of its components are called, too.



    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "Wayne Wengert" <> wrote in message
    news:...
    > I'm confused. The error occurs on the "Dim Mailmsg..." before the To and From addresses are set?
    >
    > Wayne
    >
    > "Juan T. Llibre" <> wrote in message
    > news:...
    >> re:
    >>> Since I haven't defined the from/to yet

    >>
    >> Actually, you *have* defined it, as :
    >>
    >> Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name <>")
    >> Mailmsg.From = New System.Net.Mail.MailAddress("From Name <>")
    >>
    >> It's expecting a mail address in the form :
    >>
    >> new MailAddress("", "Some Name");
    >>
    >> Try :
    >>
    >> Mailmsg.To.Add(New System.Net.Mail.MailAddress("", "To Name")
    >> Mailmsg.From = New System.Net.Mail.MailAddress("", "From Name")
    >>
    >>
    >>
    >>
    >> Juan T. Llibre, asp.net MVP
    >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> asp.net faq : http://asp.net.do/faq/
    >> foros de asp.net, en español : http://asp.net.do/foros/
    >> ===================================
    >> "Wayne Wengert" <> wrote in message
    >> news:%...
    >>> Using the code below, I am trying to send an email from an ASP.NET 2.0 page but I get the error
    >>> " The specified string is not in the form required for an e-mail address." when the "Dim
    >>> Mailmsg..." line is executed. Since I haven't defined the from/to yet, I don't understand what
    >>> it wants? Any insight on what causes this?
    >>>
    >>>
    >>> =========================================
    >>> Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    >>> Dim Mailmsg As New System.Net.Mail.MailMessage
    >>> Mailmsg.To.Clear()
    >>> Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name <>")
    >>> Mailmsg.From = New System.Net.Mail.MailAddress("From Name <>")
    >>> Mailmsg.Subject = "(subject text)"
    >>> Try
    >>> Mailmsg.Body = "(message text here)"
    >>> obj.Send(Mailmsg)
    >>> Catch ex As Exception
    >>> Response.Write("Error: " & ex.ToString())
    >>> End Try
    >>> =========================================
    >>>

    >>
    >>

    >
    >
     
    Juan T. Llibre, Mar 12, 2006
    #5
  6. Wayne Wengert

    sloan Guest

    I have 2.0 example mail code at my blog.

    with several different authentication options.

    http://spaces.msn.com/sholliday

    2/8/2006 entry


    "Wayne Wengert" <> wrote in message
    news:%...
    > Using the code below, I am trying to send an email from an ASP.NET 2.0

    page
    > but I get the error " The specified string is not in the form required for
    > an e-mail address." when the "Dim Mailmsg..." line is executed. Since I
    > haven't defined the from/to yet, I don't understand what it wants? Any
    > insight on what causes this?
    >
    >
    > =========================================
    > Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    > Dim Mailmsg As New System.Net.Mail.MailMessage
    > Mailmsg.To.Clear()
    > Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name
    > <>")
    > Mailmsg.From = New System.Net.Mail.MailAddress("From Name
    > <>")
    > Mailmsg.Subject = "(subject text)"
    > Try
    > Mailmsg.Body = "(message text here)"
    > obj.Send(Mailmsg)
    > Catch ex As Exception
    > Response.Write("Error: " & ex.ToString())
    > End Try
    > =========================================
    >
    >
     
    sloan, Mar 12, 2006
    #6
  7. Sloan;

    Thanks for that response - You pointed me in what I am sure is the right
    direction. I am trying to get the web.config settings right for my
    environment (Comcast). It seems that comcast does not require authorization
    but there must be something else I overlooked as I am getting the following
    error;

    Mailbox unavailable. The server response was: [PERMFAIL] comcast.net
    requires valid sender domain

    I am not sure exactly what it wants - I did try my comcast login and PW but
    that had no effect?

    Wayne


    "sloan" <> wrote in message
    news:...
    >I have 2.0 example mail code at my blog.
    >
    > with several different authentication options.
    >
    > http://spaces.msn.com/sholliday
    >
    > 2/8/2006 entry
    >
    >
    > "Wayne Wengert" <> wrote in message
    > news:%...
    >> Using the code below, I am trying to send an email from an ASP.NET 2.0

    > page
    >> but I get the error " The specified string is not in the form required
    >> for
    >> an e-mail address." when the "Dim Mailmsg..." line is executed. Since I
    >> haven't defined the from/to yet, I don't understand what it wants? Any
    >> insight on what causes this?
    >>
    >>
    >> =========================================
    >> Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    >> Dim Mailmsg As New System.Net.Mail.MailMessage
    >> Mailmsg.To.Clear()
    >> Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name
    >> <>")
    >> Mailmsg.From = New System.Net.Mail.MailAddress("From Name
    >> <>")
    >> Mailmsg.Subject = "(subject text)"
    >> Try
    >> Mailmsg.Body = "(message text here)"
    >> obj.Send(Mailmsg)
    >> Catch ex As Exception
    >> Response.Write("Error: " & ex.ToString())
    >> End Try
    >> =========================================
    >>
    >>

    >
    >
     
    Wayne Wengert, Mar 12, 2006
    #7
  8. I got it working. That last problem was caused by my use of a domain that
    had not been activated yet in the From address.

    Wayne

    "Wayne Wengert" <> wrote in message
    news:emOj$...
    > Sloan;
    >
    > Thanks for that response - You pointed me in what I am sure is the right
    > direction. I am trying to get the web.config settings right for my
    > environment (Comcast). It seems that comcast does not require
    > authorization but there must be something else I overlooked as I am
    > getting the following error;
    >
    > Mailbox unavailable. The server response was: [PERMFAIL] comcast.net
    > requires valid sender domain
    >
    > I am not sure exactly what it wants - I did try my comcast login and PW
    > but that had no effect?
    >
    > Wayne
    >
    >
    > "sloan" <> wrote in message
    > news:...
    >>I have 2.0 example mail code at my blog.
    >>
    >> with several different authentication options.
    >>
    >> http://spaces.msn.com/sholliday
    >>
    >> 2/8/2006 entry
    >>
    >>
    >> "Wayne Wengert" <> wrote in message
    >> news:%...
    >>> Using the code below, I am trying to send an email from an ASP.NET 2.0

    >> page
    >>> but I get the error " The specified string is not in the form required
    >>> for
    >>> an e-mail address." when the "Dim Mailmsg..." line is executed. Since I
    >>> haven't defined the from/to yet, I don't understand what it wants? Any
    >>> insight on what causes this?
    >>>
    >>>
    >>> =========================================
    >>> Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
    >>> Dim Mailmsg As New System.Net.Mail.MailMessage
    >>> Mailmsg.To.Clear()
    >>> Mailmsg.To.Add(New System.Net.Mail.MailAddress("To Name
    >>> <>")
    >>> Mailmsg.From = New System.Net.Mail.MailAddress("From Name
    >>> <>")
    >>> Mailmsg.Subject = "(subject text)"
    >>> Try
    >>> Mailmsg.Body = "(message text here)"
    >>> obj.Send(Mailmsg)
    >>> Catch ex As Exception
    >>> Response.Write("Error: " & ex.ToString())
    >>> End Try
    >>> =========================================
    >>>
    >>>

    >>
    >>

    >
    >
     
    Wayne Wengert, Mar 13, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anthony Fine
    Replies:
    3
    Views:
    3,197
    Jure Spik
    Feb 12, 2004
  2. Frank

    ASP.NET MailMessage in XP fails

    Frank, Jul 29, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    509
    Yan-Hong Huang[MSFT]
    Jul 31, 2003
  3. khawar
    Replies:
    1
    Views:
    483
  4. lostman

    MailMessage Class

    lostman, Aug 11, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,027
    lostman
    Aug 12, 2003
  5. =?Utf-8?B?TWlja2VCb3k=?=

    Problem with System.Web.Mail.MailMessage and HTML mail

    =?Utf-8?B?TWlja2VCb3k=?=, Jun 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    916
    =?Utf-8?B?TWlja2VCb3k=?=
    Jun 21, 2005
Loading...

Share This Page