How to send email through 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 发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过 IIS7 发送电子邮件?
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
