Send Email with CDO using ASP .NET and Send Email with Authentication using ASP.NET

Send Email with Authentication using ASP.NET

This tutorial will show you how to send a simple email message with authentication using ASP.NET 2.0 and C#


First, you will need to import the System.Net.Mail namespace.

The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email and specify the user credentials necessary to send authenticated email.

We use the btnSubmit_Click event to do the work.

We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page. We also instantiate a System.Net.NetworkCredential object with the necessary authentication info and then assign that object to the Credentials property of our SmtpClient object.

In button submit click you add the following code:-

MailMessage mail = new MailMessage(FromMail, ToMail, Subject, Body);

mail.IsBodyHtml = true;
try
{
SmtpClient emailClient = new SmtpClient(“smtpserver.com”);
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(”username”, “password”);
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(mailcontent);

}
catch (Exception exception)
{
}

Send Email with CDO using ASP .NET

This tutorial will show you how to send a simple email message with CDO in ASP.NET 2.0 and C#


First, you will need to import the
System.Web.Mail  namespace.

We use the btnSubmit_Click event to do the work.

In button submit click you add the following code:-

MailMessage mail=new MailMessage();
mail.Fields.Add(”http://schemas.microsoft.com/cdo/configuration/smtpserver”,”smtpserver”);
mail.Fields.Add(”http://schemas.microsoft.com/cdo/configuration/smtpserverport”,26);
mail.Fields.Add(”http://schemas.microsoft.com/cdo/configuration/sendusing”,2);
mail.Fields.Add(”http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”,60);
mail.From=”from Email address”;
mail.To=”to Email address”;
mail.Subject=”Subject”;
mail.Body=”Mail content”;
mail.BodyFormat=MailFormat.Html;
SmtpMail.SmtpServer=”smtpserver”;
SmtpMail.Send(mail);

Tags:

View Live Demo Download Source

Back to Main Top of Page

Search Resources

Subscribe Free Resource