问题描述
我正在使用带有smtp的hotmail或Outlook电子邮件发送电子邮件:asp.net mvc中的smtp-mail.outlook.com。它在本地工作正常,但是在尝试实时发送时会出现此错误“值不能为空。参数名称innerstream”。请提出任何解决方案。感谢adavace。 下面是我的代码,在本地代码上可以完美运行。
------------------------------------这是我的代码------- ------------------
公共静态字符串SendMail(字符串来自,字符串SenderName,字符串[]收件人,字符串主题,字符串主体,字符串_smtp,字符串_autEmail,字符串_autPass,字符串ReplyTo =“”) {
try
{
ComponentInfo.SetLicense("EN-2020Apr13-bFAW7hA9rpnwz2EimPfupBFO+Zvn7eAJFmwMDry8bw3XBOwrbN8zT5uOUMlwhwErECColZkcu0J9Nnp+k91PYjA+yVw==A");
MailMessage message = new MailMessage();
message.From.Add(new MailAddress(from,SenderName));
foreach(var to in recipient)
{
message.To.Add(new MailAddress(to.Trim()));
}
if (!string.IsNullOrEmpty(ReplyTo))
{
message.To.Add(new MailAddress(ReplyTo.Trim()));
}
message.Subject = subject;
message.BodyHtml = body;
RemoteCertificateValidationCallback validationDelegate =
(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors errors) =>
{
if (errors == SslPolicyErrors.None || errors == SslPolicyErrors.RemoteCertificateNameMismatch)
{
return true;
}
else
{
return false;
}
};
// Create new SmtpClient and specify host,port,security and certificate validation callback.
using (SmtpClient smtp = new SmtpClient(
_smtp,465,ConnectionSecurity.Auto,validationDelegate))
{
smtp.Connect();
smtp.Authenticate(_autEmail,_autPass,SmtpAuthentication.Login);
smtp.SendMessage(message);
return "1";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)