MailMessage Problem

W

Wayne Wengert

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
<[email protected]>")
Mailmsg.From = New System.Net.Mail.MailAddress("From Name
<[email protected]>")
Mailmsg.Subject = "(subject text)"
Try
Mailmsg.Body = "(message text here)"
obj.Send(Mailmsg)
Catch ex As Exception
Response.Write("Error: " & ex.ToString())
End Try
=========================================
 
J

Juan T. Llibre

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 <[email protected]>")
Mailmsg.From = New System.Net.Mail.MailAddress("From Name <[email protected]>")

It's expecting a mail address in the form :

new MailAddress("(e-mail address removed)", "Some Name");

Try :

Mailmsg.To.Add(New System.Net.Mail.MailAddress("(e-mail address removed)", "To Name")
Mailmsg.From = New System.Net.Mail.MailAddress("(e-mail address removed)", "From Name")
 
W

Wayne Wengert

I'm confused. The error occurs on the "Dim Mailmsg..." before the To and
From addresses are set?

Wayne
 
J

Juan T. Llibre

Sure, that's standard OOP procedure.

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

Wayne Wengert

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
 
W

Wayne Wengert

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 said:
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 said:
I have 2.0 example mail code at my blog.

with several different authentication options.

http://spaces.msn.com/sholliday

2/8/2006 entry
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top