【发布时间】:2010-11-27 10:57:08
【问题描述】:
我正在使用 SmtpClient 发送带有附件的简单邮件,但我收到此错误:
邮箱不可用。服务器响应是:不是本地主机 example.com,不是网关
System.Net.Mail.SmtpFailedRecipientException: 邮箱不可用。
服务器响应是:不是本地主机 example.com,不是网关 System.Net.Mail.SmtpTransport.SendMail(MailAddress 发件人,MailAddressCollection 收件人,String 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 个结果,其中有用的结果似乎是中文,而防火墙阻止我翻译它。
提前致谢。
【问题讨论】:
-
这是来自您自己的服务器吗?我发现大多数 ISP,不管怎样,在瑞典,他们服务器上的每个域都有自己的 SMTP,在这种情况下,我将是 smtp.example.com
标签: c# smtpclient