views:

68

answers:

3

I have developed a web application in ASP.NET. I want to integrate email solution in my application.

Here are my core requirements: 1. Sending email as soon as user registers in website. 2. Sending notification emails to all registered users.

For the second requirement, we can consider it as bulk email as we are sending mails to all users.

Please give me best solution. Do we need to set up SMTP server?

+1  A: 

Typically no. Make sure that the web server has the SMTP service installed on the system and you can use system.net.mail class. This should handle all of your basic e-mail sending needs.

If you start to run into issues with a large volume of registered users or issues with having too many BCC addresses in your bulk mail, then you will want to look into a basic mail manager (something that could send your bulk messages in bursts) or a full fledged e-mail server.

Dillie-O
+3  A: 

Yes, you need to have an SMTP server, though it doesn't have to be setup on the same machine as the webserver (it can even be provided by a third party service).

Personally I would suggest that you create an email queue system - rather then the ASP.NET script directly using the System.Net namespace to create and send an email using a specific SMTP server, you have a database table (i.e. Subject, Body, TO address).

A seperate job then reads from that table and sends the email. The reasons for the seperate table/job are:

  • It avoids having the SMTP operation occur inside of an HTTP transaction - if the SMTP server is overloaded or worse, unavailable, your webpage will appear to hang.

  • If the SMTP server is temporary unavailable or overloaded, you have the ability to add a retry column to your table.

  • If you SMTP server limits of the number of emails that can be sent in a time period (spam prevention) you can configure your job to only attempt to send the top x emails on each interation.

  • If you want to send delayed emails, it's simply a matter of adding a "SendAfter" column

David
A: 

I've found it easiest to wrapper the System.Net.Mail library in a helper class, and then that has allowed me to simply include my EmailHelper class in any project that needs the ability to send out emails.

Here's my regurgitated Send() method in my EmailHelper. You can see that it is quite easy to use.

public bool Send() {
    bool emailSent = false;

    if (_to.Count > 0) {
        MailMessage msg = new MailMessage();
        SmtpClient mail = new SmtpClient("your.email.host");

        msg.From = new MailAddress(_fromAddress, _fromName);

        foreach (String to in _to) {
            msg.To.Add(new MailAddress(to));
        }

        foreach (String cc in _cc) {
            msg.CC.Add(new MailAddress(cc));
        }

        msg.Subject = _subject;
        msg.Body = _body;
        msg.IsBodyHtml = true;
        mail.Send(msg);
        emailSent = true;
    }
    return emailSent;
}

Note that the _fromAddress, _fromName, etc. are just private attributes of the EmailHelper class. The private attributes _to and _cc are both just lists of type string.

Jagd