[转]发送邮件

// https://www.microsoft.com/en-us/download/details.aspx?id=28952
// > msiexec /a "D:\EwsManagedApi32.msi" /qb TARGETDIR="D:\1"  -- 解压 msi 
/// <summary>
/// 发送邮件
/// </summary>
public void SendEmail()
{
    string credentialUserName = "";
    string credentialUserPwd = "";
    string domain = "";

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    service.Credentials = new NetworkCredential(credentialUserName, credentialUserPwd, domain);
    service.Url = new Uri("https://XX/ews/Exchange.asmx");
    
    EmailMessage message = new EmailMessage(service);
    message.Subject = ""; // 主题
    message.Body = ""; // 内容
    message.ToRecipients.Add(""); // 收件人
    message.CcRecipients.Add(""); // 抄送
    message.BccRecipients.Add(""); // 密送
    message.Attachments.AddFileAttachment(""); // 添加附件
    message.Send(); // 发送
}

本文来自:http://www.cnblogs.com/gcczhongduan/p/4025106.html

今天使用腾迅企业邮发邮件时,发现 System.Net.Mail 不支持ssl,参考资料:https://blog.csdn.net/molu474305148/article/details/99713389

https 如果访问有问题,记得加上这段代码:

    // set remote certificate Validation auto pass
    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(remoteCertificateValidate);
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
private static bool remoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
    return true;
}
posted on 2017-12-14 17:43  z5337  阅读(194)  评论(0编辑  收藏  举报