• 群发邮件(邮件不显示在垃圾箱中)


            // <summary>
            /// 发送邮件
            /// </summary>
            /// <param name="fromemail">发件人邮箱</param>
            /// <param name="pwd">发件人密码</param>
            /// <param name="toemail">收件人邮箱</param>
            /// <param name="subject">主题</param>
            /// <param name="body">内容</param>
            /// <returns></returns>
            public static bool SendEmail(string fromemail, string pwd, string toemail, string subject, string body)
            {
                SmtpClient client = new SmtpClient();
                client.Host = "smtp." + fromemail.Remove(0, fromemail.IndexOf("@") + 1);
                client.UseDefaultCredentials = false;
                if (client.Host == "smtp.gmail.com")
                    client.EnableSsl = true;
                client.Credentials = new System.Net.NetworkCredential(fromemail, pwd);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                MailMessage message = new MailMessage(fromemail, toemail);
                message.Subject = subject;
                message.Body = body;
                message.IsBodyHtml = true;
                message.BodyEncoding = Encoding.UTF8;
                message.Headers.Add("X-Priority", "3");
                message.Headers.Add("X-MSMail-Priority", "Normal");
                message.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
                message.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
                message.Headers.Add("ReturnReceipt", "1");
                try
                {
                    client.Send(message);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }

    发件人的邮箱QQ邮箱、163邮箱都是可以的,gmail邮箱调用这个方法不行,邮箱的内容是包括HTML格式,有关内容中的字体大小,颜色或者链接等,需转成HTML格式再发送

  • 相关阅读:
    chrome shortkeys
    五笔xu
    getline()报错解决办法
    PCA程序
    c++矩阵运算库Eigen
    yolo接口
    遇到的编译错误及解决办法
    visual studio command window的使用
    NDK+MSYS2+Android sdk编译opencv源码
    面向对象分析与设计笔记(三)
  • 原文地址:https://www.cnblogs.com/jdk123456/p/3520315.html
Copyright © 2020-2023  润新知