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

2

本文介绍了如何通过 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 发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14