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 = "发送成功" };
            }

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

  • 相关阅读:
    vim设置字体
    mplayer error opening/initializing the selected video_out (vo) device
    ubuntn MySQL安装指南
    man linux
    ubuntu中无法启用桌面效果(3D效果)几种解决方案
    man c 函数 安装 使用
    Ubuntu使用桌面小工具
    Josephus 排列问题
    Adding the PPA to Ubuntu
    Ubuntu的root密码是什么
  • 原文地址:https://www.cnblogs.com/tangchun/p/14693728.html
Copyright © 2011-2022 走看看