문제

smtpclient를 사용하여 첨부 파일로 간단한 메일을 보내고 있지만이 오류가 발생합니다.

사서함을 사용할 수 없습니다. 서버 응답은 다음과 같습니다. 로컬 호스트 example.com, 게이트웨이가 아닙니다.

System.net.mail.smtpfailedRecipientException : 사서함을 사용할 수 없습니다.

서버 응답은 다음과 같습니다. System.net.net.mail.smtptransport.sendmail (MailAddress 발신자, MailAddressCollection Recepitients, String DeliveryNotify, SMTPFAILEDRECIPIENTEXCEPTION 및 EXCERTION)의 GATEWAY가 아닙니다. 메시지)

그리고 코드 :

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 The server response was: not local host example.com, not a gateway 그리고 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