Pergunta

Estou enviando um e-mail simples com anexo usando SmtpClient mas eu recebo este erro:

Mailbox indisponíveis. A resposta do servidor foi: host não locais example.com, não um gateway

System.Net.Mail.SmtpFailedRecipientException: Mailbox indisponíveis.

A resposta do servidor foi: não example.com host local, não um gateway no System.Net.Mail.SmtpTransport.SendMail (MailAddress remetente, destinatários MailAddressCollection, String deliveryNotify, SmtpFailedRecipientException & exceção) na System.Net.Mail.SmtpClient.Send (mensagem MailMessage)

E o código:

public static void CreateMessageWithAttachment(byte[] compressed)
    {
        // Create a message and set up the recipients.
        MailMessage message = new MailMessage(
           "noreply@example.com",
           "recepient@example.com",
           "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();
    }

É claro que o domínio e IP é válido no código original. Eu tentei usar tanto "localhost" e IP, mas recebendo mesmo erro. Googling 3 resultados obtidos dos quais o útil parece ser em chinês e firewall me impedindo de traduzi-lo.

Agradecemos antecipadamente.

Foi útil?

Solução

Eu procurei por: C# smtpclient error The server response was: not local host example.com, not a gateway e tem 27k + resultados

Se você estiver usando localhost ter um olhar para desta página diz :

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top