问题描述
以下是我使用smtp.outlook365.com发送电子邮件的代码, 我收到以下错误消息-
消息="无法从传输连接读取数据:net_io_connectionclosed. "
是什么原因导致此错误?
--- ****************************************
string smtpClient =(string)Dts.Variables ["$ Project :: SmtpConnectionString"].Value;
字符串smtpPort =(string)Dts.Variables ["$ Project :: SmtpPort"].Value;
字符串smtpUserName =(string)Dts.Variables ["$ Project :: SMTPUsername"].Value;
字符串smtpPwd = Dts.Variables ["$ Project :: SMTPPassword"].GetSensitiveValue().ToString();
字符串mailFrom =(string)Dts.Variables ["$ Project :: EmailFrom".Value;
字符串mailTo =(string)Dts.Variables ["$ Project :: EmailTo"].Value;
字符串mailCc =(string)Dts.Variables ["$ Project :: EmailCc"].Value;
字符串dbServer =(string)Dts.Variables ["$ Project :: OSEDBServer"].Value;
字符串dbName =(string)Dts.Variables ["$ Project :: OSEDBName"].Value;
字符串mailSubject ="Some Subject";
字符串mailBody ="Some Body Text";
MailMessage邮件=新的MailMessage();
SmtpClient SmtpServer =新的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); //已经尝试了587、25和
SmtpServer.Credentials =新的System.Net.NetworkCredential(smtpUserName,smtpPwd);
SmtpServer.EnableSsl = true;
SmtpServer.TargetName = smtpClient;
SmtpServer.Send(mail);
这篇关于发送邮件(使用SMTP.office365.com)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!