zoukankan      html  css  js  c++  java
  • 使用Gmail发送邮件心得

     /// <summary>
            /// 发送邮件
            /// </summary>
            /// <returns></returns>
            public static bool SendEmail(string subject, string body, string to)
            {
                MailMessage myEmail = new MailMessage();
                Encoding eEncod = Encoding.GetEncoding("utf-8");
                myEmail.From = new System.Net.Mail.MailAddress(SmtpUserName, SmtpUserName, eEncod);
                myEmail.To.Add(to);
                myEmail.Subject = subject;
                myEmail.Body = body;
                myEmail.BodyEncoding = Encoding.UTF8;
                myEmail.Priority = System.Net.Mail.MailPriority.Normal;
                myEmail.IsBodyHtml = true;
    
    SmtpClient smtp = new SmtpClient(SmtpServer, 587); smtp.EnableSsl = true; string UserName = SmtpUserName; string Password = SmtpPassword; smtp.Credentials = new System.Net.NetworkCredential(UserName, Password); try { smtp.Send(myEmail); return true; } catch (Exception ex) { return false; } return true; }

    注意:

    使用gmail发送邮件写端口,但是当把端口设为465时,会报超时,所以只能设为587

  • 相关阅读:
    mybatis的知识点总结
    orm框架与缓存的关系
    mybatis知识点
    mybatis
    MyBatis的动态SQL详解
    工资谈判技巧
    MySQL 创建函数(Function)
    开始AFNetworking
    hdu 4778 Rabbit Kingdom(减少国家)
    设计模式:代理模式
  • 原文地址:https://www.cnblogs.com/loveAnimal/p/3259462.html
Copyright © 2011-2022 走看看