如何通过 IIS7 发送电子邮件?

How to send email through IIS7?(如何通过 IIS7 发送电子邮件?)
本文介绍了如何通过 IIS7 发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 Windows 7 机器上使用 IIS7 设置 SMTP 服务器.我已将其设置为将电子邮件发送到 localhost,端口 25,没有身份验证.但是当我尝试从我的 C# 程序以编程方式连接时,我收到一个错误:

I'm trying to set up a SMTP server on my Windows 7 machine in IIS7. I have set it to "Deliver email to localhost, port 25, no authentication. But when I try to connect programmatically from my C# program, I get an error:

发送邮件失败",内部异常无法建立连接,因为目标机器主动拒绝了它127.0.0.1:25

Failure sending mail", inner exception "No connection could be made because the target machine actively refused it 127.0.0.1:25

public static void SendEmail(MailMessage m) {
  var smtp = new SmtpClient {
    Host = "localhost",
    Port = 25,
    UseDefaultCredentials = true,
  };
  smtp.Send(m);
}

为什么?我还需要打开什么其他秘密开关?

Why? What other secret switch do I have to flip?

推荐答案

我发现最好的方法是使用 SMTP4Dev,它会侦听电子邮件,并向您显示已发送"的内容,但实际上并未发送任何内容.非常适合测试!

Best method I found was to use SMTP4Dev, which listens for emails, and shows you what was "sent", but doesn't actually send anything. Great for testing!

这篇关于如何通过 IIS7 发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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子句?)