add the following reference to your project:
Microsoft CDO for Windows 2000
add the following imports to the top of your code behind page:
using System;
using System.Web;
using System.Web.Mail;
No security:
CDO.MessageClass oMsg = new CDO.MessageClass();
//string sAttachFile = this.txtAttachFile.Text; // uncomment for attachments
oMsg.To = " dwaterfield@mycompany.com" ;
oMsg.From = (char)34 + " Admin" + (char)34 + " " + strFrom;
oMsg.Subject = " this is a test email." ;
oMsg.TextBody = " Testing 123..." ;
//oMsg.AddAttachment(sAttachFile," " ," " ); //no username or login // uncomment for attachments
oMsg.Send();
With security:
MailMessage mail = new MailMessage();
mail.To = " dwaterfield@mycompany.com" ;
mail.From = (char)34 + " Admin" + (char)34 + " " + strFrom;
mail.Subject = " this is a test email." ;
mail.BodyFormat = MailFormat.Html;
mail.Body = " Testing 123..." ;
mail.Body += " Line 2" + Environment.NewLine;
mail.Body += " Line 3" + Environment.NewLine;
mail.Body += " Line 4" + Environment.NewLine;
mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ," 1" );
mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusername" , sEUser);
mail.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword" , sEPass);
SmtpMail.SmtpServer = sEmailServer;
SmtpMail.Send( mail );
|