I am new to SSIS and trying to figure out a way to set up a SMTP connection for an email. I did some online research about this but didn't find a clear explanation on how set up a smtp connection. Can I use outlook 2013 to send an email from SSIS? If yes then how do I create a new smtp connection using outlook 2013
I am trying to send an email from ssis with the ID like donotreply@abc.com
Here i used System.Net.Mail
assembly to send email notification.
Add a script task in your SSIS package and include this code provided that your smtp server is working.
private void SendMail(
string sendTo,
string from,
string subject,
string body,
bool isBodyHtml,
string SMTPServer,
string userName,
string password,
string domain,
string attachments,
string sendCC)
{
System.Net.Mail.MailMessage oMessage = default(System.Net.Mail.MailMessage);
System.Net.Mail.SmtpClient mySmtpClient = default(System.Net.Mail.SmtpClient);
oMessage = new System.Net.Mail.MailMessage(from, sendTo, subject, body);
oMessage.CC.Add(sendCC);
oMessage.IsBodyHtml = isBodyHtml;
mySmtpClient = new System.Net.Mail.SmtpClient(SMTPServer, 25);
if (string.IsNullOrEmpty(userName))
{
mySmtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
}
else
{
mySmtpClient.Credentials = new System.Net.NetworkCredential(userName, password, domain);
}
mySmtpClient.Send(oMessage);
}