1. 分享一段调用Lotus Notes邮箱发送邮件的代码,理论上只要是使用了SMTP协议的邮箱均可使用下面的代码发送邮件,只是在一些小地方需要修改而已。
public void SendEmail()
{
//图片的位置
string filePath = @"F:\robot.jpg";
//收件人
string emailTo = "填入邮箱地址";
//副本抄送
string copyTo = "填入邮箱地址";
//设定smtp主机
string smtpAddress = "你的IP";//IP
//设定Port
int portNumber = 25;
bool enableSSL = false;
//填入寄送方email
string emailFrom = "hello@Administrator";
//寄送方密码(可为空)
string password = "";
//主旨
string subject = "demo";
//內容
string body = "<h1 style=\"color: red;\">Hello World!</h1><img src=\"F:\robot.jpg\"/>";//文字和图片
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom, "SMT System");
mail.To.Add(emailTo);
if (!string.IsNullOrEmpty(copyTo))
{
mail.CC.Add(copyTo);
}
mail.Subject = subject;
mail.Body = body;
// 若你的內容是HTML格式,则为true
mail.IsBodyHtml = true;
//夹带附档
mail.Attachments.Add(new Attachment(filePath));
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
}
}
2. 实际效果