Send mail using authenticate mode in VB2010

Dear experts:

I need to send messages under vb2010 using authenticate mode, I'm trying to do this:

Dim m As New MailMessage
m.Fields.Add("", "1")
m.Fields.Add("", "username")
m.Fields.Add("", "password")
but I receive "Fields is not a member of" error.
I'm using vb2010, then, using Framework 4.

Any idea to solve this or to send email with authentication under vb2010?
Who is Participating?
it_saigeConnect With a Mentor DeveloperCommented:
Thats because it is not a member of System.Net.Mail.Mailmessage.  It is a member of System.Web.Mail.Mailmessage and is obsolete in .NET 4.0.

You really want something like this:
Dim Message As MailMessage = New MailMessage()
Dim Smtp As New SmtpClient()

Dim SmtpUser As New System.Net.NetworkCredential()
'-- Build Message
Message.From = New MailAddress("", "Some Username")
Message.To.Add(New MailAddress("", "Some Recipient"))
Message.IsBodyHtml = False

Message.Subject = "Sending mail is fun."
Message.Body = "Mail sent from application"
'-- Define Authenticated User
SmtpUser.UserName = "someUsername"
SmtpUser.Password = "somePassword"
SmtpUser.Domain = ""

'-- Send Message
Smtp.UseDefaultCredentials = False
Smtp.Credentials = SmtpUser
Smtp.Host = ""
Smtp.DeliveryMethod = SmtpDeliveryMethod.Network

Open in new window


Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.