SMTP-AUTH in ASP.net's System.Net.Mail |
Article ID: 1930 |
Back to Search
|
Sending Email with System.Net.Mail using SMTP-auth
For ASP.net 1.0 and the older System.Web.Mail see:
http://knowledge.3essentials.com/web-hosting/article/1048/SMTP-AUTH-in-ASP.nets-System.Web.Mail.html
For ASP.NET 2.0 includes much richer Email API support within the System.Net.Mail code namespace. Here is a simple snippet of how to send an email message from “me@mydomain.com” to multiple email recipients (note that the To a CC properties are collections and so can handle multiple address targets):
MailMessage message = new MailMessage();
message.From = new MailAddress("me@mydomain.com");
message.To.Add(new MailAddress("recipient1@yourdomain.com"));
message.To.Add(new MailAddress("recipient2@yourdomain.com"));
message.To.Add(new MailAddress("recipient3@yourdomain.com"));
message.CC.Add(new MailAddress("carboncopy@yourdomain.com"));
message.Subject = "This is my subject";
message.Body = "This is the body of my email";
SmtpClient client = new SmtpClient();
client.Send(message);
System.Net.Mail reads SMTP configuration data out of the standard .NET configuration system (so for ASP.NET applications you’d configure this in your application’s web.config file). Here is an example of how to configure it:
<system.net>
<mailSettings>
<smtp from="me@mydomain.com">
<network host="mail.mydomain.com" port="25" userName="me@mydomain.com" password="mypassword" />
</smtp>
</mailSettings>
</system.net>
Tips:
-
Of course, anywhere you ssee "me@mydomain.com" or "mydomain.com", replace the mydomain.com with your actual domain that's hosted with 3Essentials.
-
The host="mail.mydomain.com" parameter can also be set as host="localhost"
|
|
Downloads Associated With This Article |
No downloads are currently associated with this article. |