/////
// add Namespace
// .cs page
// add Namespace
//using System.Threading.Tasks;
// Call send email
public
static bool SendEmail_Bulk()
{
datatable
dt=new datatble();
dt=Fill
datatable;
Parallel.ForEach(dt.AsEnumerable(), row
=>
{
SendEmail(row["Email"].ToString(),
subject, string.Format(body, row["Name"]));
});
}
public
static bool SendEmail_Bulk(string SenderName,string AddressTo, string subject,
string body,string CC,string BCC)
{
//using System.Threading.Tasks;
//Parallel.ForEach(dt.AsEnumerable(),
row =>
//
{
//
SendEmail(row["Email"].ToString(), subject,
string.Format(body, row["Name"]));
//
});
bool isSuccess = false;
try
{
string[] Credentials = {
"gmail@gmail.com", "AppPassword", "Password"
};
MailMessage mail = new
MailMessage();
mail.IsBodyHtml = true;
SmtpClient SmtpServer = new
SmtpClient("smtp.gmail.com");
mail.From = new
MailAddress(Credentials[0], SenderName);
mail.To.Add(AddressTo);
mail.Subject = subject;
mail.Body = body;
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = true;
if (CC != "")
{
mail.CC.Add(CC);
}
if (BCC != "")
{
mail.Bcc.Add(BCC);
}
SmtpServer.Port = 587;
SmtpServer.Credentials = new
System.Net.NetworkCredential(Credentials[0], Credentials[1]);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
isSuccess = true;
}
catch (Exception ex)
{
// log the exception
}
return isSuccess;
}
No comments:
Post a Comment