質問

SmtpClientを使用して添付ファイル付きのシンプルなメールを送信していますが、このエラーが表示されます:

  

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

     

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

     

サーバーの応答:ローカルホストexample.comではなく、ゲートウェイ   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender、MailAddressCollection recipients、String deliveryNotify、SmtpFailedRecipientException& exception)で   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(
           "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つの結果を返しましたが、そのうち有用なものは中国語であり、ファイアウォールで翻訳できないようです。

事前に感謝します。

役に立ちましたか?

解決

検索しました: C#smtpclient errorサーバーの応答:notローカルホストexample.com、ゲートウェイではなく 、27K以上の結果が得られました。

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top