2

SmtpClient を使用して添付ファイル付きの簡単なメールを送信していますが、次のエラーが発生します。

メールボックスを利用できません。サーバーの応答は次のとおりでした: ローカル ホスト example.com ではなく、ゲートウェイではありません

System.Net.Mail.SmtpFailedRecipientException: メールボックスを利用できません。

サーバーの応答は次のとおりでした: ローカル ホスト example.com ではなく、System.Net.Mail.SmtpTransport.SendMail(MailAddress 送信者、MailAddressCollection 受信者、文字列 deliveryNotify、SmtpFailedRecipientException& 例外) のゲートウェイではありません System.Net.Mail.SmtpClient.Send(MailMessageメッセージ)

そしてコード:

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

もちろん、ドメインと IP は元のコードで有効です。「localhost」とIPの両方を使用してみましたが、同じエラーが発生しました。グーグルは3つの結果を返しましたが、そのうち役立つのは中国語であり、ファイアウォールが翻訳を妨げているようです。

前もって感謝します。

4

1 に答える 1

4

検索した結果: C# smtpclient error The server response was: not local host example.com, not a gateway27,000 件以上の結果が得られました。

localhost を使用している場合は、次のページを参照してください。

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
于 2009-09-11T09:59:48.827 に答える