Send Mail (using SMTP.office365.com) error

  • Thread starter Thread starter SQLDev555
  • Start date Start date
S

SQLDev555

Guest
Below is my code for sending email using smtp.outlook365.com , I get the following error message -

"Message = "Unable to read data from the transport connection: net_io_connectionclosed." "

What is causing this error ?



---***********************************

string smtpClient = (string)Dts.Variables["$Project::SmtpConnectionString"].Value;
string smtpPort = (string)Dts.Variables["$Project::SmtpPort"].Value;
string smtpUserName = (string)Dts.Variables["$Project::SMTPUsername"].Value;
string smtpPwd = Dts.Variables["$Project::SMTPPassword"].GetSensitiveValue().ToString();
string mailFrom = (string)Dts.Variables["$Project::EmailFrom"].Value;
string mailTo = (string)Dts.Variables["$Project::EmailTo"].Value;
string mailCc = (string)Dts.Variables["$Project::EmailCc"].Value;
string dbServer = (string)Dts.Variables["$Project::OSEDBServer"].Value;
string dbName = (string)Dts.Variables["$Project::OSEDBName"].Value;
string mailSubject = "Some Subject";
string mailBody = "Some Body Text";

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(smtpClient);

mail.From = new MailAddress(mailFrom);
mail.To.Add(mailTo);
mail.CC.Add(mailCc);
mail.Subject = mailSubject;
mail.Body = mailBody;
mail.Priority = MailPriority.Normal;

SmtpServer.Host = "smtp.office365.com";
SmtpServer.Port = Int32.Parse(smtpPort); //Have tried both 587 , 25
SmtpServer.Credentials = new System.Net.NetworkCredential(smtpUserName, smtpPwd);
SmtpServer.EnableSsl = true;
SmtpServer.TargetName = smtpClient;
SmtpServer.Send(mail);

Continue reading...
 
Back
Top