部署时发送SMTP

时间:2018-03-15 04:15:27

标签: c#

本地我的smtp代码工作得很好,当我部署到plesk - godaddy托管时,它似乎不再工作了。我可以获得一些协助,说明为什么它在部署后会停止?

using (var mail = new MailMessage())
{
    const string smtp = "smtp.gmail.com";
    const int port = 587;

    var loginInfo = new NetworkCredential("xxxxxx@gmail.com", "xxxxxxxx");


    mail.From = new MailAddress(fromAddress);
    mail.To.Add(new MailAddress(toAddress));
    mail.Subject = subject;
    mail.Body = message.ToString();
    mail.IsBodyHtml = true;

    try
    {
        using (var smtpClient = new SmtpClient(smtp, port))
        {
            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;
            smtpClient.Send(mail);
        }

    }

    finally
    {
        //dispose the client
        mail.Dispose();
    }

}

0 个答案:

没有答案