views:

71

answers:

3

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("[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.

+1  A: 

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>
Abe Miessler
+1  A: 

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.

TomTom
A: 

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.

supernont