How to send an email from a BizTalk Expression shape (without using the SMTP Send Ports).
Note: There are two mail objects, the older one is System.Web.Mail and the newer one It also shows how to connect to an SMTP Host (Server) that requires userid/password authentication.

Note: The SMTPHost, from email, user/password were retrieved in the previous expression shape from the <AppSettings> of the BTNTSVC.exe.config file.

<code>
objMail = new System.Net.Mail.MailMessage();

objMailAddressFrom = new System.Net.Mail.MailAddress(strMailFrom);
objMail.From = objMailAddressFrom;

objMailAddressTo = new System.Net.Mail.MailAddress(msgEmailFromSQL.EmailAddress);
objMail.To.Add(objMailAddressTo);

objMail.Subject = msgEmailFromSQL.Status_Code.Description;

objMail.Body =
    msgEmailFromSQL.Status_Code.Text +
    "&lt;BR&gt;&lt;BR&gt;" +
    "&lt;a href='" + msgEmailFromSQL.WebPageAddress + "'&gt;" +
    msgEmailFromSQL.WebPageAddress + "&lt;/a&gt;";

objMail.IsBodyHtml = true;

objCredentials = new System.Net.NetworkCredential(strMailUser, strMailPassword);
objSmtpClient = new System.Net.Mail.SmtpClient(strMailServer);
objSmtpClient.Credentials = objCredentials;
objSmtpClient.Send(objMail);



</code>

Tagged with:

Filed under: C#