ASP.Net Host

SMTP Mail .Net 1.1

This code sample shows how to send SMTP authenticated email using ASP.Net 1.1.  You will need to have an email account setup on the SMTP server, and that will be what is used for the 'SMTPUser' and 'SMTPPassword' fields.

At Aquest Hosting, the SMTP user name is always the full email addres (ex: bob@somedomain.com).

public void 

public void SendEmail(string Server, string SmtpUser, string SmtpPassword,string To, string From,
string Body, string Subject,
string CC,string BCC)

   {                            

      System.Web.Mail.SmtpMail.SmtpServer = Server;

      System.Web.Mail.MailMessage mssg = new System.Web.Mail.MailMessage();

 

      mssg.BodyFormat = System.Web.Mail.MailFormat.Html;

      mssg.Body = Body;

      mssg.Subject = Subject;

      mssg.To = To;

      mssg.From = From;

      if(BCC.Trim().Length > 0)    

          mssg.Bcc = BCC.Trim();             

      if(CC.Trim().Length > 0)

          mssg.Cc = CC.Trim();

 

      //Set the SMTP authentication

mssg.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;

      if(SmtpUser.Trim().Length > 0)

          mssg.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = SmtpUser.Trim();

      if(SmtpPassword.Trim().Length > 0)

          mssg.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = SmtpPassword.Trim();

                 

      //send the email

      System.Web.Mail.SmtpMail.Send(mssg);

                 

}

 

0 Comments

Leave your comment.
Name:
Email: (not shared or made public)
Website:   http://
Comments:

This is a public forum. Aquest Solutions and its affiliates are not responsible for, and do not control what is posted herein. Aquest Solutions makes no warranties or guarantees concerning any advice dispensed by its staff, members, or readers.

Community standards in this comment area do not permit hate language, excessive profanity, or other patently offensive language. Please be aware that all information posted to this comment area becomes the property of Aquest Solutions and may be edited and republished in print or electronic format as outlined in Aquest Solutions' Terms of Use.

Important Note: This comment area is NOT intended for commercial messages or solicitations of business.

We recommend Aquest Hosting for your ASP.Net 2.0 hosting, Community Server hosting, and DotNetNuke hosting.