2009-09-11 2 views
1

Я посылаю простую почту с приложением, используя SmtpClient, но я получаю эту ошибку:Ошибка C# SmtpClient: не локальный хост?

Mailbox unavailable. The server response was: not local host example.com, not a gateway

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable.

The server response was: not local host example.com, not a gateway at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message)

И код:

public static void CreateMessageWithAttachment(byte[] compressed) 
    { 
     // Create a message and set up the recipients. 
     MailMessage message = new MailMessage(
      "[email protected]", 
      "[email protected]", 
      "Hello.", 
      "How are you?"); 

     // Create the file attachment for this e-mail message. 
     Stream attachStream = new MemoryStream(compressed); 
     Attachment attachment = new Attachment(attachStream, MediaTypeNames.Application.Octet); 
     message.Attachments.Add(attachment); 

     //Send the message. 
     SmtpClient client = new SmtpClient("123.12.12.123"); 
     // Add credentials if the SMTP server requires them. 
     client.Credentials = CredentialCache.DefaultNetworkCredentials; 

     client.Send(message); 

     attachment.Dispose(); 
    } 

Конечно домен и IP является действительным в исходном коде. Я пробовал использовать «localhost» и IP, но получал такую ​​же ошибку. Googling возвратил 3 результата, из которых полезный, кажется, находится в китайском и брандмауэре, мешающем мне перевести его.

Заранее спасибо.

+0

Является ли это с вашего сервера? Я обнаружил, что большинство ISP, здесь, в Швеции, имеют собственный SMTP для каждого домена на своих серверах, к которому вы должны подключиться, в этом случае я бы smtp.example.com –

+0

Да, собственный сервер. – syaz

ответ

3

Я искал: C# smtpclient error The server response was: not local host example.com, not a gateway и получил результаты 27K +.

Если вы используете локальный посмотреть на this page он говорит:

This is a relay error. Make sure you can relay through the SmtpMail.SmtpServer 
either by your IP address, by your MailMessage.From address, or if you need to 
authenticate, check out 3.8 How do I authenticate to send an email? 

If SmtpMail.SmtpServer is set to "127.0.0.1" or "localhost", and you are using 
the built in IIS SMTP Service, you can allow relaying for 127.0.0.1 by 

1) Opening the IIS Admin MMC 
2) Right-Clicking on the SMTP Virtual Server and selecting Properties 
3) On the Access tab, click the Relay button 
4) Grant 127.0.0.1 (or the IP address used by System.Web.Mail) to the 
    Computers list. 
5) Close all dialogs 
6) Restarting the SMTP Service 
+1

Не совсем мой стиль поиска. Я искал: C# smtpclient "не локальный хост" – syaz