Frage

Ich bin eine einfache Mail mit Anhang senden mit SmtpClient aber ich bekomme diese Fehlermeldung:

  

Mailbox nicht verfügbar. Die Serverantwort war: nicht lokaler Host   example.com, kein Gateway

     

System.Net.Mail.SmtpFailedRecipientException:   Mailbox nicht verfügbar.

     

Die Serverantwort war: nicht lokale Host example.com, kein Tor zu   System.Net.Mail.SmtpTransport.SendMail (Mailaddress Absender, Empfänger MailAddressCollection, String deliveryNotify, SmtpFailedRecipientException & Ausnahme) bei   System.Net.Mail.SmtpClient.Send (Mailmessage message)

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

Natürlich ist die Domäne und IP ist im ursprünglichen Code gültig. Ich habe versucht, sowohl „localhost“ und IP verwenden, aber gleiche Fehler. zurück googeln 3 Ergebnisse von denen die hilfreich in der chinesischen und Firewall zu sein scheint mich aus der Übersetzung zu verhindern.

Vielen Dank im Voraus.

War es hilfreich?

Lösung

Ich habe gesucht: C# smtpclient error The server response was: not local host example.com, not a gateway und bekam 27K + Ergebnisse

Wenn Sie mit localhost einen Blick auf dieser Seite es sagt :

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top