Skip to content

Instantly share code, notes, and snippets.

@VibhuKuchhal
Last active April 19, 2016 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VibhuKuchhal/a327a2dafd821c3b7f94 to your computer and use it in GitHub Desktop.
Save VibhuKuchhal/a327a2dafd821c3b7f94 to your computer and use it in GitHub Desktop.
public void SendMail()
{
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SMTPAddress"].ToString());
client.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["User"].ToString(),
ConfigurationManager.AppSettings["Password"].ToString(),
ConfigurationManager.AppSettings["Domain"].ToString());
Recipients.Insert(0, (ConfigurationManager.AppSettings["IntimationEmailId"].ToString()));
int pageSize = int.Parse(ConfigurationManager.AppSettings["BatchSize"].ToString());
int counter = 0;
var recipients = Recipients.Skip(counter * pageSize).Take(pageSize);
do
{
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(ConfigurationManager.AppSettings["SenderEmailId"].ToString());
foreach (string address in recipients)
{
try
{
message.Bcc.Add(address);
}
catch ()
{
}
}
Body += Environment.NewLine;
message.Body = Body;
message.IsBodyHtml = true;
message.Subject = Subject;
message.SubjectEncoding = System.Text.Encoding.UTF8;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
counter += 1;
recipients = Recipients.Skip(counter * pageSize).Take(pageSize);
}
while (recipients.Count() > 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment