读取SharePoint的SMTP设置, 发送邮件

private static String GetSmtpHost()
{
SPOutboundMailServiceInstance instance = SPContext.Current.Site.WebApplication.OutboundMailServiceInstance;

if (instance != null)
{
return instance.Server.Address;
}

instance = SPAdministrationWebApplication.Local.OutboundMailServiceInstance;

if (instance != null)
{
return instance.Server.Address;
}

return String.Empty;
}

SmtpClient smtpClient = new SmtpClient(smtpServer);
MailMessage mail = new MailMessage(FromEmail, ToEMail)
{
Subject = MailSubject,
Body =

“<html><head><meta http-equiv=\”Content-Type\” content=\”text/html; charset=UTF-8\”><title>” + MailSubject + “</title></head>”
+ “<body style=\”font-family: Verdana; font-size: 12px\”>” + MailBody + “</body></html>”,
IsBodyHtml = true
};

smtpClient.Send(mail);

发表评论

电子邮件地址不会被公开。

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>