Best practise to send mass email within application (ASP.NET MVC 2, C#)?

落花浮王杯 提交于 2020-01-02 00:00:19

问题


Whats the best way to implement mass email sending feature within web app? Two major cases:

  1. 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)

  2. "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("jondoe@bla.net");

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.


回答1:


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:


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:

<configuration>
  <!-- Add the email settings to the <system.net> element -->
  <system.net>
    <mailSettings>
      <smtp>
        <network 
             host="relayServerHostname" 
             port="portNumber"
             userName="username"
             password="password" />
      </smtp>
    </mailSettings>
  </system.net>

  <system.web>
    ...
  </system.web>
</configuration>



回答3:


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.



来源:https://stackoverflow.com/questions/2866432/best-practise-to-send-mass-email-within-application-asp-net-mvc-2-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!