Friday, March 16, 2012

Mass Emailing

I have an application that sends off Newsletters via SMTP located on a web server. It works perfectly for <100 emails, but yesterday, I tried to send one off to over 3,800+ users, but unfortunately, it seemed not to go through.

I have a DataReader that displays each email that it sends it off to (for confirmation purposes) and it looks like it did went off, but no one has received it. I believe I have good exception handling implemented as shown below:

public void Send_Mail(Object sender, System.Web.UI.ImageClickEventArgs e)
{

SqlConnection conn = new SqlConnection("my connection string");
SqlCommand comm = new SqlCommand("my SQL statement, conn);
SqlDataReader dr;

MailMessage mailer = new MailMessage();
mailer.From = txtFrom.Text.Trim();
mailer.Subject = txtSubject.Text.Trim();
mailer.Body = txtBody.Text.Trim();
mailer.BodyFormat = MailFormat.Html;

try
{
conn.Open();
dr = comm.ExecuteReader(CommandBehavior.CloseConnection);
while(dr.Read())
{
mailer.To = dr[0].ToString();
lblConfirmation.Text = dr[0].ToString();
SmtpMail.SmtpServer = "xx.xx.xx.xxx";
SmtpMail.Send(mailer);
}
dr.Close();

lblConfirmation.Text = "Your message was successfully sent to the following recipients:" ;

conn.Open();
dgrid.DataSource = comm.ExecuteReader(CommandBehavior.CloseConnection);
dgrid.DataBind();
dr.Close();
}
catch(SqlException ex)
{
Response.Write("A database-related exception occurred!<br>" + ex.ToString());
}
catch(Exception ex)
{
Response.Write("A general exception occurred!<br>" + ex.ToString());
}
finally
{
if(conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}


Everything seems the same as with 100 emails as with 3,800 emails, but can't seem to know where my emails went. I did go to (C:\inetput\mailroot) but couldn't find anything near my situation.

Could someone please help me out here? Is there a queue somewhere I don't know about? ASP.NET can handle this type of mass mailings correct?

Any advice will be greatly appreciated.why don't you do a loop to get all the email addresses and put them in a string where each email is seperated by ";" or "," and then assign this string to the "TO" and then send only one email to all the email at once ? try it !!!!

0 comments:

Post a Comment