zoukankan      html  css  js  c++  java
  • 发送邮件

    public static void SendMailUseGmail(string gmailAddress, string gmailPwd, string name, string toAddress, string info, string title)
            {
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add(toAddress);

            
                msg.From = new MailAddress(toAddress, name, System.Text.Encoding.UTF8);
              
              
                msg.Subject = title;//邮件标题
                msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
                msg.Body = info;//邮件内容
                msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
                msg.IsBodyHtml = false;
                msg.Priority = MailPriority.High;
                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential(gmailAddress, gmailPwd);
              
                client.Port = 587;
                client.Host = "smtp.gmail.com";
                client.EnableSsl = true;
                object userState = msg;
                try
                {
                    client.Send(msg);     
                }
                catch (System.Net.Mail.SmtpException ex)
                {
                    Console.WriteLine(ex.Message);

                }
            }

            public static void SendMailUseGmail()
            {
                string userEmail = "123@sina.com";
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add(userEmail);

                msg.From = new MailAddress(userEmail, "wanhu", System.Text.Encoding.UTF8);        
                msg.Subject = "这是测试邮件";//邮件标题
                msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
                msg.Body = DateTime.Now.ToString();//邮件内容
                msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
                msg.IsBodyHtml = false;//是否是HTML邮件
                msg.Priority = MailPriority.High;//邮件优先级

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("szwanhu@gmail.com", "9016890168");
                //上述写你的GMail邮箱和密码
                client.Port = 587;//Gmail使用的端口
                client.Host = "smtp.gmail.com";
                client.EnableSsl = true;//经过ssl加密
                object userState = msg;
                try
                {
                    client.Send(msg);

                    //简单一点儿可以client.Send(msg);

                }
                catch (System.Net.Mail.SmtpException ex)
                {

                }
            }
  • 相关阅读:
    原生JS实现几个常用DOM操作API
    js字符串操作总结
    复选框 全选 反选 不选
    纯js实现分页
    JS 数据类型转换
    原生JS 购物车及购物页面的cookie使用
    js实现两种实用的排序算法——冒泡、快速排序
    linux下rename命令使用(可以实现文件批量重名)
    screen命令常用参数使用
    iptables端口转发规则(内网端口转外网端口)
  • 原文地址:https://www.cnblogs.com/mxw09/p/1874201.html
Copyright © 2011-2022 走看看