Knowledge Essentials - 3Essentials Hosting

SMTP-AUTH in's System.Web.Mail

Article ID: 1048

 Back to Search

Sending Email with System.Web.Mail using SMTP-auth


This article details usage of 1.0's older System.Web.Mail. 

For ASP.NET 2.0 includes much richer Email API support within the System.Net.Mail code namespace, discussed in the following article.

Many people think that you cannot authenticate a SMTP server using the System.Web.Mail.MailMessage class and opt for using a 3rd party component (like JMAIL which we have on our shared hosting servers) or .Net's newer System.Net.Mail (which would be the recommended solution).  While System.Net.Mail was added to replace System.Web.Mail and definitely supports SMTP-auth more gracefully, you can actually SMTP-authenticate with System.Web.Mail using the following approach:

Dim Msg As New System.Web.Mail.MailMessage
Msg.Fields("") = "smtpserver"
Msg.Fields("") = 25
Msg.Fields("") = 2
Msg.Fields("") = 1
Msg.Fields("") = ""
Msg.Fields("") = "password"
Msg.To = ""
Msg.From = ""
Msg.Subject = "Subject"
Msg.Body = "Message"
System.Web.Mail.SmtpMail.SmtpServer = "smtpserver"

If you're sending via a remote, non-3essentials server, update the SMTPSERVER values (both of them) to the mail server's hostname. If you're sending via our servers, update the SMTPSERVER value to simply "localhost".

The sendusername and msg.from fields generally are both the same... specifying the email address you're using to send the mail... but you do have the option to make them different, i.e., the sendusername parameter is the email address you are authenticating to the smtp server with, and you can then actually specify a different FROM/SENDER address by way of the msg.from parameter.

Downloads Associated With This Article
No downloads are currently associated with this article.