2013-04-20 12 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?) Довольно понятно. 'Unable to relay' - по умолчанию большинство корпоративных почтовых серверов отключает ретрансляцию, поэтому они не могут использоваться для отправки спама, например. – Tim

+0

Взгляните на эту тему - ['Ошибка: почтовый ящик недоступен. Ответ сервера был 5.7.1 Не удалось передать (по электронной почте) '] (http://forums.devshed.com/net-development-87/error-mailbox-unavailable-the-server-response-was-5-7 -1t-315971.html) – Tim

ответ

1

Следующий код для GmailSMTP через порт 587. Вы просто изменить порт и SMTP.

Добавить пространство имен

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.

Смежные вопросы