.NET SMTP客户端 - 客户端不必送,因为这发件人权限 [英] .NET SMTP Client - Client does not have permissions to send as this sender

查看:327
本文介绍了.NET SMTP客户端 - 客户端不必送,因为这发件人权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到奇怪的次数在我们的服务器,当我试图通过ASP MVC3项目发送使用SmtpClient类邮件。这是code我使用。

I'm getting strange occurance on our servers when I am trying to send an email using SmtpClient class via an ASP MVC3 project. This is the code I am using.

try
{
    var client = new SmtpClient("MailServer");
    client.UseDefaultCredentials = true;

    MailMessage message = new MailMessage("me@mydomain.com", "friend@mydomain.com", "Test Message", "Test Body");
    client.Send(message);
}
catch (Exception ex)
{
    // Do Nothing
}

我已经部署在三个环境;在Windows 7中(使用VS 2010 IIS)发送电子邮件细,在Windows 2003 IIS6的计算机上发送​​电子邮件罚款,终于在Windows 2008 R2服务器II7我收到以下错误:

I have deployed on three environments; on Windows 7 (using VS 2010 IIS) it sends the email fine, on the Windows 2003 IIS6 machine it sends the email fine, finally on the Windows 2008 R2 II7 server I get the following error:

Mailbox unavailable. The server response was: 5.7.1 Client does not have permissions to send as this sender using username 

有人能告知什么可能会导致此。我注意到,当我查看 User.Identity.Name ,此函数返回一个空字符串。

Can anybody advise on what may be causing this. I have noticed that when I view User.Identity.Name, this is returning an empty string.

推荐答案

这是可能的邮件服务器不支持发送匿名邮件,并要求指定的凭据注册的邮件服务器上。

It is likely that the mail server does not support sending anonymous emails and will require credentials to be specified which are registered on the mail server.

您可以指定凭据,像这样:

You can specify the credentials like so:

client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("username", "password");

希望这有助于。

Hope this helps.

这篇关于.NET SMTP客户端 - 客户端不必送,因为这发件人权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆