在ASP.Net中发送邮件失败

时间:2016-06-04 07:42:31

标签: asp.net exception smtpclient

我开发了一个发送邮件的网站。这是我的方法:

public string sendMail() {
    try {
        result = "Message Sent Successfully..!!";
        string senderID = "mymailid@gmail.com";
        const string senderPassword = "mypassword";
        SmtpClient smtp = new SmtpClient {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new System.Net.NetworkCredential(senderID,senderPassword),
            Timeout = 30000,
        };
        MailMessage message = new MailMessage(senderID, txtToEmail.Text, 
        txtSubject.Text, txtBody.Text);
        smtp.Send(message);
    }
    catch (Exception ex) {
        result = ex.Message;
    }

    return result;
}

详细例外是:

  

无法连接到远程服务器。

我尝试使用Gmail和Outlook。两者都有相同的例外。当我更改为端口25时,它显示连接超时

0 个答案:

没有答案