我的应用程序具有通过smtp.gmail.com发送电子邮件的功能
当我在本地运行时,效果很好,但是在发布到vps之后,电子邮件未发送。
MX(10)的这是我使用的代码:
public ServiceResult SendEmailOrder(string Email)
{
ServiceResult result = new ServiceResult();
try
{
const string fromPassword = "password";
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.From = new MailAddress("senderaddress@gmail.com");
mail.Subject = "subject mail";
mail.Body = "Body Mail";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("senderaddress@gmail.com", fromPassword);
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
mail.To.Add(new MailAddress(Email));
SmtpServer.Send(mail);
}
catch (Exception ex)
{
result.Error("Failed Send Email", ex.InnerException.Message);
}
return result;
}
我想念的东西吗?
*注意: -我的vps已连接到互联网, -我以前使用过Google Cloud,并且代码运行良好。