📄 emailsender.cs
字号:
using System;
using System.Configuration;
using System.Net;
using System.Net.Mail;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace ScrewTurn.Wiki {
/// <summary>
/// Sends Emails.
/// </summary>
public static class EmailSender {
/// <summary>
/// Sends an Email.
/// </summary>
/// <param name="recipient">The Recipient.</param>
/// <param name="sender">The Sender.</param>
/// <param name="subject">The Subject.</param>
/// <param name="body">The Message body.</param>
/// <param name="html">True if the body is HTML.</param>
public static void Send(string recipient, string sender, string subject, string body, bool html) {
MailMessage message = new MailMessage(sender, recipient, subject, body);
message.IsBodyHtml = html;
GenerateSmtpClient().Send(message);
}
/// <summary>
/// Sends a Mass Email, using BCC.
/// </summary>
/// <param name="recipients">The Recipents.</param>
/// <param name="sender">The Sender.</param>
/// <param name="subject">The Subject.</param>
/// <param name="body">The Body.</param>
/// <param name="html">True if the body is HTML.</param>
public static void SendMassEmail(string[] recipients, string sender, string subject, string body, bool html) {
MailMessage message = new MailMessage(new MailAddress(sender), new MailAddress(sender));
message.Subject = subject;
message.Body = body;
for(int i = 0; i < recipients.Length; i++) {
message.Bcc.Add(new MailAddress(recipients[i]));
}
message.IsBodyHtml = html;
GenerateSmtpClient().Send(message);
}
private static SmtpClient GenerateSmtpClient() {
SmtpClient client = new SmtpClient(Settings.SmtpServer);
if(Settings.SmtpUsername.Length > 0) {
client.Credentials = new NetworkCredential(Settings.SmtpUsername, Settings.SmtpPassword);
}
client.EnableSsl = Settings.SmtpSsl;
if(Settings.SmtpPort != -1) client.Port = Settings.SmtpPort;
else if(Settings.SmtpSsl) client.Port = 465;
return client;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -