.NET SMTP 客户端 - 客户端无权作为此发件人发送

.NET SMTP Client - Client does not have permissions to send as this sender(.NET SMTP 客户端 - 客户端无权作为此发件人发送)
本文介绍了.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 客户端 - 客户端无权作为此发件人发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)