Speed up sending multiple emails through smtp server using System.Net.Mail(使用 System.Net.Mail 加速通过 smtp 服务器发送多封电子邮件)
问题描述
我是 C# 的新手,但我从 VB.Net 学到了很多关于在 .Net for windows 中编程的知识.
I am quite a newbie in C# but I have learnt a lot from VB.Net about programming in .Net for windows.
我刚刚制作了一个简单的 SMTP 客户端,它从程序中发送电子邮件.它是一个控制台应用程序,一次只能通过服务器发送一封电子邮件.这非常慢,我需要通过我的客户端同时发送多封电子邮件.
I have just made a simple SMTP client which sends emails from the program. It is a console application and can only send one email through the server at a time. This is very slow and I need to send multiple emails through my client at the same time.
这在 C# 中可行吗?
Is this possible in C#?
推荐答案
只需使用多线程(多进程)即可.
simply use multiple threads (multiple processes).
在 C# 中,您可以使用任务来完成此操作.
In C# you can do this with a Task.
new Task(delegate {
smtpClient.send(myMessage);
}).Start();
只需将您的 send 命令包装在此对象中,它将异步发送.
Just wrap your send command in this object and it will be send Asynchronously.
小心,如果它被包裹在一个循环中,它将为每封邮件启动一个新进程.
Be careful if this is wrapped in a loop it will start a new process for each mail.
如果您需要同时发送大量邮件,我建议您使用ThreadPool.它使您可以控制要同时拥有多少并发线程.
if you need to send large amounts of mails at the same time I suggest you use a ThreadPool. It lets you control how many concurent threads you'd like to have at the same time.
这篇关于使用 System.Net.Mail 加速通过 smtp 服务器发送多封电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 System.Net.Mail 加速通过 smtp 服务器发送多封电子邮件
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
