如何使用asp.net的exchange发送本地邮件?
我有一个项目需要通过本地电子邮件向员工发送通知。 我使用 SmtpClient 类发送电子邮件但不起作用! 这是代码:
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "Sending mail";
message.Body = "Check sending email by Exchange from asp.net code <> ";
SmtpClient client = new SmtpClient("ExchangeDNS", 25);
try
{
client.Send(message);
}
catch (Exception exc)
{
Label1.Text = exc.Message.ToString();
}
当我单击按钮时,它会给我一个 SmtpException
消息:发送邮件失败。
注意:我们使用 Exchange 服务器。
我该如何解决?
I have a project that need to sends notification for employees by local email. I use SmtpClient class to send email but didn't work! here is the code:
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = "Sending mail";
message.Body = "Check sending email by Exchange from asp.net code <> ";
SmtpClient client = new SmtpClient("ExchangeDNS", 25);
try
{
client.Send(message);
}
catch (Exception exc)
{
Label1.Text = exc.Message.ToString();
}
When I click buttons it give me an SmtpException
with message : Failure sending mail.
NB: we use Exchange server.
How can I solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用服务器的完全限定名称,例如,exchangeDNS.example.com。 如果这不起作用,请尝试 IP 地址。 您可能需要手动远程登录到 Exchange 服务器上的端口 25,只是为了看看是否可行。 另外,检查您的服务器是否需要经过身份验证或加密的连接。 如果是这样,您需要在请求中提供凭据或更改为使用 SSL 和安全端口。
Use the fully qualified name for your server, for example, exchangeDNS.example.com. If that doesn't work, try the IP address. You may want to manually telnet to port 25 on the Exchange server, just to see if it is possible. Also, check whether your server requires an authenticated or encrypted connection. If so, you'll need to supply credentials with the request or change to use SSL and the secure port.
假设您的服务器和任何所需的凭据均正确(仔细检查这些),我会尝试增加SMTP 客户端超时。
Assuming that you have the server and any required credentials correct (double check these) I would try increasing the timeout on the SMTP client.
你的代码没问题。 值得怀疑的是您的 Exchange 服务器的配置。 供 Exchange 管理员使用的一些选项:
如果您发布有关您的 Exchange 配置的更多详细信息,我可以提供帮助,但冒着将此问题降级为“与编程无关”的风险。
Your code is fine. It's the configuration of your Exchange server that is suspect. Some options for your Exchange administrator:
If you post more details about your Exchange configuration, I can help, at the risk of having this question downmodded for "not programming related".