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 服务器发送多封电子邮件


基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01