GoDaddy的SMTP发送邮件的问题及解决方法

时间:2021-08-24 15:11:56

采用Asp.net通过SMTP发送邮件时,会受到服务器限制,需要通过relay-hosting.secureserver.net来发送。

private bool sendMail()
{
try
{
MailAddress from = new MailAddress("Ur email address applied from GoDaddy.");
MailAddress to = new MailAddress("The email address you will send to.");
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = body;
SmtpClient client = new SmtpClient("relay-hosting.secureserver.net", 25); //这里不是smtpout.secureserver.net
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = CredentialCache.DefaultNetworkCredentials; //无需用户名密码
client.Send(message);

return true;
}
catch (System.Exception ex)
{
lbNotes.Text = ex.ToString();
return false;
}
}