我开发了一个发送邮件的网站。这是我的方法:
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时,它显示连接超时