We are using asp.net 3.5 with c#.We have to make an powerful mailer module.This module can mail more than 15000 recipient or in short all records in DBMS.I would like to ask few things.
1)We have a code which sends a mail to single recipient.How will we send a mail to multiple recipient.I tried with our code to add more than one email id by ',' but it sends only first email id.Here is the code sample
public bool Mail(string to, string subject, string body)
{
try
{
MailMessage objEmail = new MailMessage();
objEmail.To =to;
objEmail.From = "[email protected]";
//objEmail.Priority =priority
objEmail.Subject = subject;
objEmail.Body = body;
//enable the Html tag...
objEmail.BodyFormat = MailFormat.Html;
objEmail.Priority = MailPriority.High;
SmtpMail.SmtpServer = "localhost";
try
{
SmtpMail.Send(objEmail);
return true;
}
catch(Exception ex)
{
string error = ex.StackTrace;
return false;
}
}
catch
{
return false;
}
}
2)What is the max limit to send mail at a time.Means how much value we can assign in string to that contains emailids?
3)One main thing our code is in button click so if we have more than 15000 records so will it able to send to mail all because What we are thinking is that page will have 60sec to render so it may send mails only those ids cover in 60 sec.
Lets suggest what is the best way to do that.
Thanks in advance.
Do not use System.Web.Mail. Use System.Net.Mail. See this blog.
System.Web.Mail is deprecated and not recommended.
You need to pass the work onto an actual mail server/service. A third party one is your best option. Do not send email directly from the web application code as request timeouts, authentication timeouts, etc will eventually halt your send loop. Also, this process will lock up the current page/session until it is done/halted and I have also experienced entire applications locking up for ALL visitors when pages are executing heavy tasks like this.
If all you want is a cheap email server that you can add emails to a queue and the server will just chug through them and send them, then Amazon SES is worth a look. If you want more user management and campaign management tools, then MailChimp or JangoMail might be your best options.
Amazon SES is definitely the cheapest as you only pay for what you use. I spend 4 bucks a month on average.
All of these provide APIs you can use in your code.
Aside: Do ensure that your recipients have somehow requested or are otherwise expecting these emails. Sending spam is illegal and the punishment is harsh.
Please also check out these questions: