Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.