2013-04-20 113 views
-1

我正在开发一个C#应用程序来使用我们公司邮件的SMTP服务器发送邮件。以下是代码。SMTP邮件错误

MailMessage mail = new MailMessage(); 
SmtpClient SmtpServer = new SmtpClient("10.203.195.48"); 

mail.From = new MailAddress(""); 
mail.To.Add(""); 
mail.Subject = "filename"; 
mail.Body = "Report"; 

SmtpServer.Host = "ip address fo smtp mail server."; 
SmtpServer.Port = 25; 
SmtpServer.Credentials = new System.Net.NetworkCredential("", ""); 

SmtpServer.Send(mail); 

但我得到这个错误:

mailbox unavailable.unable to relay.The system doesn't have internet connection.

+1

你确实传递了'mail.To.Add'和'System.Net.NetworkCredential'的空白值吗?错误信息(s?)很明显。 “无法中继” - 默认情况下,大多数公司邮件服务器会关闭中继,以便它们不能用于发送垃圾邮件。 – Tim 2013-04-20 07:30:02

+0

看看这个线程 - ['错误:邮箱不可用。服务器响应是5.7.1无法中继(电子邮件)'](http://forums.devshed.com/net-development-87/error-mailbox-unavailable-the-server-response-was-5-7 -1T-315971.html) – Tim 2013-04-20 07:32:42

回答

1

下面的代码是使用端口587你只需要改变你的端口,SMTP GmailSMTP

添加命名空间

using system.net 
MailMessage MyMailMessage = new MailMessage(); 
MyMailMessage.From = new MailAddress("emailid"); 
MyMailMessage.To.Add("To"); 
MyMailMessage.Subject = "Feedback Form"; 
MyMailMessage.Body = "This is the test message"; 
MyMailMessage.IsBodyHtml = true; 

SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com"); 
SMTPServer.Port = 587; 
SMTPServer.Credentials = new System.Net.NetworkCredential("Username","password"); 
SMTPServer.EnableSsl = true; 

try 
{ 
    SMTPServer.Send(MyMailMessage); 
} 

catch (Exception ex) 
{ 
    ex.message("error"); 
} 
1

Error: Mailbox unavailable. The server response was 5.7.1 Unable to relay for (email)

Generally it occurs when you have a mail server (e.g. mailserver.com) from one domain, and the addresses are from other domains. Either the From or the To address need to belong to the domain ([email protected] or [email protected]). If neither of the addresses belong to a domain that the mail server 'owns', then you are relaying, which is a spam technique and is generally not allowed nowadays."

参见博客文章Mailbox unavailable. The server response was: 5.7.1 Unable to relay sendername