我正在使用MailMessage类发送电子邮件
MailMessage msg = new MailMessage(fromAddr, toAddr);当我创建新的MailMessage对象时,它会自动使用fromAddr.for获取主机。例如,如果我的fromaddress是chamara@pindoc.com.au,它会假定主机是pindoc.com.au,但是我为host.so使用了一个不同的名称,主机名是错误的。我想正因为如此,我得到了以下错误。
{“邮箱不可用。服务器响应为: 5.7.1 Unable to relay"} System.Exception {System.Net.Mail.SmtpFailedRecipientException}
我该如何解决这个问题呢?
发布于 2011-11-02 10:21:42
你检查过你的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-02 10:22:40
您可以在创建SmtpClient对象的实例时指定邮件服务器(以及端口号和身份验证等其他详细信息)
SmtpClient client = new SmtpClient("different.hostname"); // specify your hostname
client.Send(msg);你也可以指定你的smtp details in the web.config or app.config,SmtpClient会自动拾取它们...
SmtpClient client = new SmtpClient();
client.Send(msg);发布于 2011-11-02 10:25:18
通常,我将使用SmtpClient发送消息。它的构造函数接受主机和端口:
SmtpClient mailClient = new SmtpClient("mail.domain.com", 25);
mailClient.Send(msg);https://stackoverflow.com/questions/7975119
复制相似问题