1

我正在使用 MailMessage 类发送电子邮件

 MailMessage msg = new MailMessage(fromAddr, toAddr);

当我创建新的 MailMessage 对象时,它会使用 fromAddr 自动获取主机。例如,如果我的 fromaddress 是 chamara@pindoc.com.au 它假定主机为 pindoc.com.au 但我有不同的主机名称.所以主机名是错误的。我认为因为我收到以下错误。

{“邮箱不可用。服务器响应为:5.7.1 无法中继”} System.Exception {System.Net.Mail.SmtpFailedRecipientException}

我该如何解决这个问题?

4

3 回答 3

3

你检查过你的mailSettings吗?下面的示例 web.config:

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="no-reply@yourdomain.com">
      <network defaultCredentials="true" host="mail.yourdomain.com" port="25"/>
   </smtp>
 </mailSettings>
</system.net>
于 2011-11-02T02:21:42.030 回答
1

您可以在创建 SmtpClient 对象的实例时指定邮件服务器(以及端口号和身份验证等其他详细信息)

SmtpClient client = new SmtpClient("different.hostname"); // specify your hostname
client.Send(msg);

您还可以在 web.config 或 app.config 中指定您的smtp 详细信息, SmtpClient 将自动获取这些信息...

SmtpClient client = new SmtpClient();
client.Send(msg);
于 2011-11-02T02:22:40.017 回答
0

通常,我将使用SmtpClient发送消息。它的构造函数需要一个主机和端口:

SmtpClient mailClient = new SmtpClient("mail.domain.com", 25);
mailClient.Send(msg);
于 2011-11-02T02:25:17.920 回答