在应用程序中发送大量电子邮件的最佳实践(ASP.NET MVC 2,C#)?
在网络应用程序中实现群发电子邮件发送功能的最佳方法是什么?两种主要情况:
根据不同的注册用户的活动向其发送电子邮件消息(仅向前用户发送有关其创建的主题中的新帖子的简短提醒)
“向所有注册用户发送电子邮件”功能,如果系统管理员能够为所有注册用户发送一些消息,那就太好了。当然,将所有电子邮件添加到收件人并不是我们可以采用的方法,因为每个用户的电子邮件地址都是匿名的。
据我了解,案例 nr1 没有问题,只需通过 System.Net.Mail 通过创建新邮件消息并发送来创建一些电子邮件消息...但是案例 nr 2 呢???
我想这样:
foreach(var emailAddress in emailAddresses) {
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add(emailAddress);
mail.Subject = "test";
mail.Body = "test";
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Send(mail);
}
这不是好方法:)所以问题是实现这一目标的最佳方法是什么?
顺便说一句,我们无法部署一些用于电子邮件发送的服务,这应该集成到 Web 应用程序中。
Whats the best way to implement mass email sending feature within web app? Two major cases:
Email messages for separate registered users depending on their activities (just sending short reminders to user for ex about new posts in his created topic)
"Send email for all registered users" functionality, it will be nice to have feature for system administrator to send some messages for all registered users. Of course adding all emails to recipient isn't the way we can go, because email addresses for each user are anonimous.
As i understand for case nr1 there is no problem just create some email message via System.Net.Mail by creating new mail message and sending it... but what about case nr 2???
i guess smth like this:
foreach(var emailAddress in emailAddresses) {
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add(emailAddress);
mail.Subject = "test";
mail.Body = "test";
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Send(mail);
}
isn't the good way :) so the question is what is the best way to achieve this ?
btw we have no possiblity to deploy some serive for email sending, this should be integrated into web application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一件事:不要使用 gmail。首先,gmail 有限制 - 无论如何,根本不使用外部服务器。
我做类似的事情,我使用硬盘上的放置目录,然后使用 MTA(Windows 中的 SMTP 服务)进行实际传输。
这样我就可以快速完成(仅生成文件),而实际的电子邮件可能需要更长的时间。
ANother thing: do NOT use gmail. First, gmail has limits - anyhow, use no external server at all.
I do stuff like that, and I use a drop directory on the hard disc, then use an MTA (SMTP service in Windows acutally) to do the actual transfer.
This way I finish fast (just file generation) while the actual emails can take longer.
如果您想在情况 2 中隐藏收件人,为什么不能将收件人放入 MailMessage 的密件抄送中?
我建议的一件事是在 web.config 中定义电子邮件设置,如下所示:
If you want to hide who it's going to in case 2 why can't you put the recipients into the BCC of MailMessage?
One thing I would recommend is to define your email settings in your web.config like below:
如果您在“emailAddresses”实例中收到太多电子邮件,您将面临超时问题。
您可能会考虑使用一个小型 Windows 服务应用程序来处理发送功能。这对我有用。
If you got too many e-mail in "emailAddresses" instance, you would face the time-out problem.
You might considering a tiny Windows Service app to handle sending function. It works for me.