我正在使用以下代码使用smtp gmail发送电子邮件,它可以在我的机器上运行,但是当我在azure上部署时它不起作用。
try
{
// Gmail Address from where you send the mail
var fromAddress = new MailAddress( "k4@gmail.com","From Name");
var toAddress = new MailAddress("mghazanfar@hotmail.co.uk", "To Name");
const string fromPassword = "Meabana";
string subject = "Feedback for Comic Maker from " + Request["name"];
string body = Request["message"]+"\n\n\n\n\n\n";
body += Request["email"];
body += Request["phone"];
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message1 = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message1);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Email sent successfully')", true);
email.Value = "";
phone.Value = "";
name.Value = "";
message.Value = "";
}
}
catch {
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Some problem occurred')", true);
}
我收到了这个错误 SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。
了解更多信息