我使用SmtpClient發送一個簡單的郵件帶有附件,但我得到這個錯誤:C#SmtpClient錯誤:不是本地主機?
Mailbox unavailable. The server response was: not local host example.com, not a gateway
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable.
The server response was: not local host example.com, not a gateway at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message)
,代碼:
public static void CreateMessageWithAttachment(byte[] compressed)
{
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"[email protected]",
"[email protected]",
"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是在原代碼有效。我曾嘗試使用「本地主機」和IP但獲得相同的錯誤。谷歌搜索返回了3個結果,其中有用的一個似乎在中文和防火牆中阻止我翻譯它。
在此先感謝。
這是從你自己的服務器?我發現大多數ISP(在瑞典)無論如何都有自己的SMTP服務器上的每個域的SMTP,你必須連接到這種情況下,我會smtp.example.com – 2009-09-11 09:56:41
是的,自己的服務器。 – syaz 2009-09-11 10:06:54