Here I used gmail smtp for sending bulk mail you may use your smtp if you wish. If you face any problem then please write comment I will update it.
protected void btn1_Click(object sender, EventArgs e)
{
ArrayList list_emails = new ArrayList();
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
// setup Smtp authentication
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("your_mail_account@gmail.com", "password");
client.UseDefaultCredentials = false;
client.Credentials = credentials;
string[] listmails =
foreach (string email_to in listmails)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("your_gmail_account@gmail.com");
msg.To.Add(new MailAddress(email_to));
msg.ReplyTo= (new MailAddress("bhadreshpanchal@cyberdesign.co.in"));
msg.Subject = "This is a test Email subject";
msg.IsBodyHtml = true;
msg.Body = string.Format("Test HTML Email123*****");
try
{
client.Send(msg);
Response.Write("Your message has been successfully sent.");
}
catch (Exception ex)
{
Response.Write("Your message has been successfully sent.");
Response.Write("Error occured while sending your message." + ex.Message);
}
}
}
No comments:
Post a Comment