Introduction
SMTP Authentication - expensive third party control or roll-you-own with System.Net
and sockets? Not required: The CDOSYS Schema is accessible directly from your code and you can use MailMessage.Fields
to access and change schema values to control the attributes of your email.
Using the code
Create your email using the MailMessage
class - then set the Schema Fields of Interest to you. For example, to send via an external SMTP server on port 25 with SMTP authentication name and password:
eMail = new MailMessage();
eMail.BodyFormat = MailFormat.Text;
eMail.From = _SendFrom;
eMail.Fields[http:
= "SMTPServerName";
eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
if (SMTPUser != null && SMTPPassword != null)
{
eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/sendusername"] =
"SMTPAUTHUser";
eMail.Fields[
"http://schemas.microsoft.com/cdo/configuration/sendpassword"] =
"SMTPAUTHPassword";
}
eMail.To = "recipients";
SmtpMail.SmtpServer = SMTPServerName;
SmtpMail.Send(eMail);
Check MSDN for the CDOSYS and enumerated values.
History