zoukankan      html  css  js  c++  java
  • OutLook发送邮件

       public BaseResult Office365Send(string toEmail, string fromEmail, string subject, string body, bool isBodyHtml)
            {
                try
                {
                    logger.Info("发送失败,用户:" + toEmail + " ,主题:" + subject);
                    MailMessage msg = new MailMessage();
                    msg.To.Add(new MailAddress(toEmail, toEmail));
                    msg.From = new MailAddress(fromEmail, fromEmail);
                    msg.Subject = subject;
                    msg.Body = body;
                    msg.Priority = MailPriority.High;
                    msg.IsBodyHtml = isBodyHtml;
                    msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); //防止成为垃圾邮件,披上outlook的马甲
                    msg.BodyEncoding = Encoding.GetEncoding("GB2312");
                    msg.Priority = MailPriority.High;
    
                    SmtpClient client = new SmtpClient();
                    client.UseDefaultCredentials = false;
                    client.Credentials = new System.Net.NetworkCredential(_serverUserName, _serverUserPassword);
                    client.Port = 587;
                    //client.Host = "smtp.office365.com";
                    //client.TargetName = "STARTTLS/smtp.office365.com";
                    client.Host = "outlook.office365.com";
                    client.TargetName = "STARTTLS/outlook.office365.com";
                    //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.EnableSsl = true;
                    client.Send(msg);
                }
                catch (Exception ex)
                {
                    logger.Error("发送失败,用户:" + toEmail + ",内部错误:" + ex.Message);
                    return new BaseResult { code = 1, msg = "发送失败,内部错误:" + ex.Message };
                }
                return new BaseResult { code = 0, msg = "发送成功" };
            }

    需要关闭微软的默认安全值

  • 相关阅读:
    I Hate It
    hdu 2112 HDU Today ( Dijkstra )
    hdu 1280 前m大的数
    hdu 4252 A Famous City
    hdu 2647 Reward
    hdu 2845 Beans
    hdu 3548 Enumerate the Triangles ( 优 化 )
    hdu 3552 I can do it! (贪心)
    HDU 3033 I love sneakers!(分组背包变形)
    hdu 1712 ACboy needs your help 分组背包
  • 原文地址:https://www.cnblogs.com/tangchun/p/14693728.html
Copyright © 2011-2022 走看看