本文整理汇总了C#中SmtpClient.BulkSend方法的典型用法代码示例。如果您正苦于以下问题:C# SmtpClient.BulkSend方法的具体用法?C# SmtpClient.BulkSend怎么用?C# SmtpClient.BulkSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmtpClient
的用法示例。
在下文中一共展示了SmtpClient.BulkSend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendEmail
private void SendEmail()
{
try
{
// Build message
MailMessage msg = new MailMessage();
msg.From = txtFrom.Text;
msg.Subject = txtSubject.Text;
msg.HtmlBody = txtHtmlBody.Text;
msg.To.Add(new MailAddress("#Recipient#", true));
// create a message template engine with the above message
TemplateEngine msgTemplateEngine = new TemplateEngine(msg);
// create data table for the template
DataTable dt = new DataTable();
// Add 3 columns
dt.Columns.Add("Recipient", typeof(string));
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("LastName", typeof(string));
// add rows to the table
DataRow row;
foreach (ListItem item in lstRecipients.Items)
{
string recipientEmail = item.Text;
string firstName = item.Value.Split(delimeter, StringSplitOptions.None)[0];
string lastName = item.Value.Split(delimeter, StringSplitOptions.None)[1];
// add rows to the data table
row = dt.NewRow();
row["Recipient"] = recipientEmail;
row["FirstName"] = firstName;
row["LastName"] = lastName;
dt.Rows.Add(row);
}
MailMessageCollection msgCollection;
msgCollection = msgTemplateEngine.Instantiate(dt);
// add recipients
// Send message
SmtpClient smtp = new SmtpClient(
txtHost.Text,
int.Parse(txtPort.Text),
txtUsername.Text,
txtPassword.Text);
// SSL settings
if (chSSL.Checked == true)
{
smtp.EnableSsl = true;
smtp.SecurityMode = SmtpSslSecurityMode.Explicit;
}
// send bulk emails
smtp.BulkSend(msgCollection);
// show message on screen that email has been sent
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Text = "Email sent successfully<br><hr>";
}
catch (Exception ex)
{
// display error message
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Error: " + ex.Message + "<br><hr>";
}
}