.NET SMTP Client - Client does not have permissions to send as this sender(.NET SMTP 客户端 - 客户端无权作为此发件人发送)
问题描述
当我尝试通过 ASP MVC3 项目使用 SmtpClient 类发送电子邮件时,我的服务器上出现了奇怪的情况.这是我正在使用的代码.
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");
希望这会有所帮助.
这篇关于.NET SMTP 客户端 - 客户端无权作为此发件人发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET SMTP 客户端 - 客户端无权作为此发件人发送


- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01