• C# 发送邮件代码


        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="title">邮件标题</param>
        /// <param name="content">邮件内容</param>
        /// <param name="receiveEmail">收件人</param>
        public void SendEmail(string title, string content, string receiveEmail)
        {
            string eMailUserName = "aaaaaa";    //要显示的发件人名称
            string eMailPassWord = "bbbbbb";   //发件用户的邮箱密码
            string eMailHost = "smtp.gmail.com";     //发件邮箱所在的邮件发件服务器
            int eMailPort = 587;                     //邮件发送端口
            bool eMailEnableSSL = true;              //是否启用发件安全协议
            string eMailFromAddress = ""; //发件人邮箱账号
    
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            smtp.Credentials = new System.Net.NetworkCredential(eMailUserName, eMailPassWord);
            smtp.Host = eMailHost;
            smtp.Port = eMailPort;
            smtp.EnableSsl = eMailEnableSSL;
    
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.Subject = title;                                             //主题
            mail.Body = content;                                              //正文
            mail.From = new System.Net.Mail.MailAddress(eMailFromAddress);    //发件人
            mail.SubjectEncoding = System.Text.UTF8Encoding.UTF8;             //发送邮件主题内容编码
            mail.BodyEncoding = System.Text.UTF8Encoding.UTF8;                //发送邮件内容编码
            mail.Priority = System.Net.Mail.MailPriority.High;                //优先级别
            mail.IsBodyHtml = true;                                           //邮件内容是否以HTML格式嵌套在邮件中
            mail.To.Add(receiveEmail);                                        //添加邮件收件人
            smtp.Send(mail);                                                  //发送
        }
  • 相关阅读:
    Python3 使用requests请求,解码时出错:'utf8' codec can't decode byte 0x83 in position 1: invalid start byte
    快速上手阿里云oss SDK
    peewee 通俗易懂版
    gunicorn开启、关闭和重启
    Vector和ArrayList区别
    Hibernate与MyBatis
    redis缓存
    Innodb学习
    基本数据结构-图
    基本数据结构-树
  • 原文地址:https://www.cnblogs.com/wangbogo/p/2564052.html
Copyright © 2020-2023  润新知