zoukankan      html  css  js  c++  java
  • c# QQ发送邮件功能

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Mail;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace SendEmail
    {
        public static class Email
        {
            /// <summary>
            ///
            /// </summary>
            /// <param name="getmail">收件人邮箱地址</param>
            /// <param name="title">主题</param>
            /// <param name="message">内容</param>
            /// <param name="mailFrom">用户名</param>
            /// <param name="userPassword">密码</param>
            /// <returns></returns>
            public static bool Sendmail(string getmail, string title, string message, string mailFrom, string userPassword)
            {
                // 邮件服务设置
                string smtpServer = "smtp.qq.com"; //SMTP服务器
                SmtpClient smtpClient = new SmtpClient();
                smtpClient.EnableSsl = true;//由于使用了授权码必须设置该属性为true
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
                smtpClient.Host = smtpServer; //指定SMTP服务器
                smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userPassword);//用户名和密码
    
                // 发送邮件设置
                MailMessage mailMessage = new MailMessage(mailFrom, getmail); // 发送人和收件人
                mailMessage.Subject = title;//主题
                mailMessage.Body = message;//内容
                mailMessage.BodyEncoding = Encoding.UTF8;//正文编码
                mailMessage.IsBodyHtml = true;//设置为HTML格式
                mailMessage.Priority = MailPriority.Low;//优先级
    
                bool b = false;
                try
                {
                    smtpClient.Send(mailMessage); // 发送邮件
                    b = true;
                }
                catch (Exception ex)
                {
                    var mes = ex;
                    b = false;
                }
                return b;
            }
        }
    }

    下面是调用

  • 相关阅读:
    yum 在线安装LAMP
    python-scrapy-增量式
    python-scrapy-分布式爬取
    python-scrapy-全站数据爬取-CrawlSpider
    python-scrapy-中间件的学习
    python-scrapy深度爬取
    python-scrapy环境配置
    django DOM
    window10设置环境变量(以设置虚拟环境和SQL为例)
    加入园子啦
  • 原文地址:https://www.cnblogs.com/victor-huang/p/15108133.html
Copyright © 2011-2022 走看看