Tuesday, May 3, 2011

Send email outside network/organization through MS-Exchange using asp.net

You can use below code to send email using Microsoft Exchange server outside the organization (email address other then current organization)

private void Page_Load(object sender, System.EventArgs e)
{
 MailMessage mail = new MailMessage();
 mail.To = "me@mycompany.com";
 mail.From = "you@yourcompany.com";
 mail.Subject = "this is a test email.";
 mail.Body = "Some text goes here";
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

 SmtpMail.SmtpServer = "mail.mycompany.com";  //your real server goes here
 SmtpMail.Send( mail );
}

Share This!


No comments:

Powered By Blogger · Designed By Seo Blogger Templates