Question

J'envoie un courrier simple avec pièce jointe à l'aide de SmtpClient mais j'obtiens cette erreur:

  

Boîte aux lettres indisponible. La réponse du serveur était: pas d'hôte local   example.com, pas une passerelle

     

System.Net.Mail.SmtpFailedRecipientException:   Boîte aux lettres indisponible.

     

La réponse du serveur était: pas un hôte local example.com, pas une passerelle à   System.Net.Mail.SmtpTransport.SendMail (expéditeur de MailAddress, destinataires de MailAddressCollection, String deliveryNotify, SmtpFailedRecipientException & exception) à l'adresse   System.Net.Mail.SmtpClient.Send (message MailMessage)

Et le code:

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();
    }

Bien sûr, le domaine et l'adresse IP sont valides dans le code d'origine. J'ai essayé d'utiliser les deux " localhost " et IP mais obtenir la même erreur. Google a renvoyé 3 résultats dont le plus utile semble être en chinois et un pare-feu m'empêche de le traduire.

Merci d'avance.

Était-ce utile?

La solution

J'ai cherché: C # smtpclient error La réponse du serveur était: non l'hôte local example.com, pas une passerelle et a obtenu 27K + résultats.

Si vous utilisez localhost, consultez la 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top