我的邮件发送代码如下,已在服务器上托管:
try
{
MailMessage msgMail = new MailMessage();
MailMessage myMessage = new MailMessage();
myMessage.From = new MailAddress("*****");
myMessage.To.Add(TextBox1.Text);
myMessage.Subject = "Subject";
myMessage.IsBodyHtml = true;
myMessage.Body = "Message Body";
SmtpClient mySmtpClient = new SmtpClient();
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("email", "password");
mySmtpClient.Host = "****"; //Have specified the smtp host name
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = myCredential;
mySmtpClient.Send(myMessage);
myMessage.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
我继续收到此错误
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: #5.1.0 Address rejected abc@yahoo.com at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Mail.Button1_Click(Object sender, EventArgs e) in d:\hosting\9110120\html\FB\Mail.aspx.cs:line 37
我已经尝试了一切。它一直给出同样的错误
我的网站托管在Godaddy服务器上
答案 0 :(得分:2)
您的代码似乎很好,显然您可能需要对其进行配置:http://support.godaddy.com/help/article/5444
答案 1 :(得分:1)
它失败了,因为电子邮件地址不存在。只需处理异常就可以了。
How to check if an email address exists without sending an email?
答案 2 :(得分:0)
我有同样的问题,通过下面一行中的一个小改动来修复它
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential(" email"," password");
验证您的凭据,这对我有用:) ..