我正在使用 SmtpClient 发送带有附件的简单邮件,但出现此错误:
信箱不可用。服务器响应是:不是本地主机 example.com,不是网关
System.Net.Mail.SmtpFailedRecipientException:邮箱不可用。
服务器响应是:不是本地主机 example.com,不是 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 个结果,其中有用的结果似乎是中文的,而防火墙阻止我翻译它。
提前致谢。