I maintain the website for a small organization with roughly 100 to 120 members.
Every month, we send out an email notifying our members of the topics we will cover in the upcoming meetings.
I am trying to use our website to give us a way to send these emails out, but our ASP Hosting Site has a defined limit of 50 emails per hour.
Theoretically, I suppose I could put the thread to sleep for 1-minute after each SmtpClient.Send(MailMessage) call by using a Thread.Sleep(60000), like this:
public const int ONE_MINUTE = 60000;
public String SiteEmailAddress { get; set; }
public String SiteMailServer { get; set; }
public String SiteMailUserId { get; set; }
public String SiteMailPwd { get; set; }
public void BulkEmail(String emailMessage) {
using (var msg = new MailMessage()) {
msg.From = new MailAddress(SiteMailAddress);
msg.Body = emailMessage;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
using (var server = new SmtpClient(SiteMailServer, 25)) {
server.Credentials = new NetworkCredential(SiteMailUserId, SiteMailPwd);
foreach (var person in Personnel.GetActiveMembers()) {
var msgTo = person.PersonalEmail;
if (!String.IsNullOrEmpty(msgTo)) {
msg.To.Clear();
msg.To.Add(new MailAddress(msgTo, person.FullName));
server.Send(msg);
System.Threading.Thread.Sleep(ONE_MINUTE);
}
}
}
}
}
That would either make our website appear dead for over an hour while this ran or it would likely fail.