You could use the SmtpClient class:
foreach (DataRow row in datatable.Rows)
{
var name = (string)row["Name"];
var email = (string)row["MailID"];
var body = (string)row["Body"];
var message = new MailMessage();
message.To.Add(email);
message.Subject = "This is the Subject";
message.From = new MailAddress("[email protected]");
message.Body = body;
var smtpClient = new SmtpClient("yoursmtphost");
smtpClient.Send(message);
}
Remark1: In .NET 4.0, SmtpClient implements IDisposable, so make sure to properly dispose it.
Remark2: There's a bug in SmtpClient class prior to .NET 4.0 which doesn't properly send the QUIT
command to the SMTP server.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…