C#smtp gmail无法在服务器上运行,但在本地主机上运行良好

时间:2019-12-08 10:31:46

标签: c# dns smtp vps

我的应用程序具有通过smtp.gmail.com发送电子邮件的功能

当我在本地运行时,效果很好,但是在发布到vps之后,电子邮件未发送。

MX(10)的

dns设置指向smtp.gmail.com dns setting for mx(10) was pointing to smtp.gmail.com

这是我使用的代码:

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,并且代码运行良好。

0 个答案:

没有答案