Errore C # SmtpClient: non host locale?
-
05-07-2019 - |
Domanda
Sto inviando una semplice e-mail con allegato utilizzando SmtpClient ma ricevo questo errore:
Cassetta postale non disponibile. La risposta del server è stata: non host locale esempio.com, non un gateway
System.Net.Mail.SmtpFailedRecipientException: Cassetta postale non disponibile.
La risposta del server è stata: non l'host locale example.com, non un gateway su System.Net.Mail.SmtpTransport.SendMail (mittente MailAddress, destinatari MailAddressCollection, String deliveryNotify, SmtpFailedRecipientException & amp; exception) at System.Net.Mail.SmtpClient.Send (messaggio MailMessage)
E il codice:
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();
}
Naturalmente il dominio e l'IP sono validi nel codice originale. Ho provato a utilizzare entrambi " localhost " e IP ma ottenendo lo stesso errore. Google ha restituito 3 risultati, di cui l'utile sembra essere in cinese e firewall che mi impedisce di tradurlo.
Grazie in anticipo.
Soluzione
Ho cercato: Errore C # smtpclient La risposta del server è stata: no host locale example.com, non un gateway
e ottenuto 27K + risultati.
Se stai usando localhost dai un'occhiata a questa pagina dice :
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