i am sending email using hotmail or outlook email with smtp : smtp-mail.outlook.com in asp.net mvc. it works fine local but when try to send live it gives this error "value cannot be null. parameter name innerstream". please suggest any solution. Thanks in adavace. below is my code which work perfect on local..
------------------------------------Here is my code -------------------------
public static string SendMail(string from,string SenderName,string[] recipient, string subject,string body, string _smtp,string _autEmail,string _autPass, string 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;
}
}