• asp.net发送email


     

        /// <summary>
        /// 单发Email

        /// </summary>
        /// <param name="from">发信人地址</param>
        /// <param name="to">收信人地址</param>
        /// <param name="title">标题</param>
        /// <param name="body">内容</param>
        /// <returns></returns>
        public static  string sendEmail(string to, string title, string body)
        {
            try
            {
                MailMessage m_message = new MailMessage();

                m_message.From = new MailAddress("*@163.com");

                m_message.To.Add(new MailAddress(to));

                m_message.Subject = title;

                m_message.Body = body;

                SmtpClient m_smtpClient = createClient();

                m_smtpClient.Send(m_message);
                return "发送成功";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }

        /// <summary>
        /// 群发Email

        /// </summary>
        /// <param name="from">发信人地址</param>
        /// <param name="to">收信人地址列表</param>
        /// <param name="title">标题</param>
        /// <param name="body">内容</param>
        /// <returns></returns>
        public static  string sendEmail(string[] to, string title, string body)
        {
            try
            {
                MailMessage m_message = new MailMessage();

                m_message.From = new MailAddress("*@163.com");

               foreach (string s in to)
                {
                    m_message.To.Add(new MailAddress(s));
                }

                m_message.Subject = title;

                m_message.Body = body;

                SmtpClient m_smtpClient =createClient();

                m_smtpClient.Send(m_message);
                return "发送成功";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }


        public static  SmtpClient createClient()
        {
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.163.com";
            smtp.Port = 25;

            smtp.UseDefaultCredentials = true;//不能和帐号顺序颠倒,否则出错。
            smtp.Credentials = new System.Net.NetworkCredential("*@163.com", "******");
            return smtp;
        }

  • 相关阅读:
    Spring Boot实战二:集成Mybatis
    Spring Boot实战一:搭建Spring Boot开发环境
    Oracle 11g安装和PL/SQL连接完全解读(连接本地数据库)
    Spring事务详解
    RabbitMQ学习笔记六:RabbitMQ之消息确认
    RabbitMQ学习笔记五:RabbitMQ之优先级消息队列
    RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决)
    RabbitMQ学习笔记三:Java实现RabbitMQ之与Spring集成
    RabbitMQ学习笔记二:Java实现RabbitMQ
    Spark 读 Hive(不在一个 yarn 集群)
  • 原文地址:https://www.cnblogs.com/loveAnimal/p/myemail.html
Copyright © 2020-2023  润新知