Security Verified
Browse Categories
 Affiliates
 Backup & Restore
 Billing & MyAccount FAQs
 Control Panels
 Customer Tools
 Databases
 Dedicated Servers
 DNS and Domain Registration
 Email
 Glossary
 Network
 News
 PCI Compliance
 Postmaster
 Pre-sales FAQ
 Publishing Your Site
 Reseller Tips
 Search Engine Optimization
 Security Topics
 SSL and HTTPS
 Support: Getting Help
 Virtual Desktops
 Virtual Servers
 Website Design & Development
 Website Errors

DotNetNuke Hosting
SQL 2008 R2 / IIS 7.5 Hosting
WordPress Hosting
Forex Trader Hosting
Personal Desktop Hosting

SMTP-AUTH in ASP.net's System.Web.Mail

Article ID: 1048

 Back to Search

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 System.Net.Mail.  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("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserver"
Msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "you@yourdomain.com"
Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
Msg.To = "recipient@recipientdomain.com"
Msg.From = "sender@senderdomain.com"
Msg.Subject = "Subject"
Msg.Body = "Message"
System.Web.Mail.SmtpMail.SmtpServer = "smtpserver"
System.Web.Mail.SmtpMail.Send(Msg)

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.

© 2001 - 2012 3Essentials Inc.
Terms Of Service | Privacy Policy | Copyright Policy | Affiliates