Error C # SmtpClient: ¿no es un host local?
-
05-07-2019 - |
Pregunta
Estoy enviando un correo simple con un archivo adjunto usando SmtpClient pero recibo este error:
Buzón no disponible. La respuesta del servidor fue: no host local example.com, no una puerta de enlace
System.Net.Mail.SmtpFailedRecipientException: Buzón no disponible.
La respuesta del servidor fue: no host.com local, no una puerta de enlace en System.Net.Mail.SmtpTransport.SendMail (remitente de MailAddress, destinatarios de MailAddressCollection, String deliveryNotify, SmtpFailedRecipientException & amp; exception) en System.Net.Mail.SmtpClient.Send (mensaje de MailMessage)
Y el código:
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();
}
Por supuesto, el dominio y la IP son válidos en el código original. He intentado usar ambos " localhost " e IP pero obteniendo el mismo error. Google devolvió 3 resultados, de los cuales el útil parece estar en chino y el firewall impidiéndome traducirlo.
Gracias de antemano.
Solución
He buscado: C # smtpclient error La respuesta del servidor fue: no host local example.com, no una puerta de enlace
y obtuvo 27K + resultados.
Si está utilizando localhost, eche un vistazo a esta página que 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