zoukankan      html  css  js  c++  java
  • asp.net 邮件发送,使用外部stmp服务器,呵呵!简单例子

        public void MailSend(string[] mails)
        { 
    
          try
                {
                    MailMessage message = new MailMessage();
                    foreach (string mail in mails)
                    {
                        message.To.Add(mail);//收件人地址 
                    }
    
                    if (txtCC.Text != "")
                    {
                        string[] cc = txtCC.Text.Split(';');
                        foreach (string str in cc)
                        {
                            message.CC.Add(str);//抄送的地址
                        }
                    }
                    message.From = new MailAddress("ceshi@yeah.net", "管理员", System.Text.Encoding.UTF8);
                    message.Subject =txtTitle.Text.Trim();  //邮件主题
                    message.IsBodyHtml = true;//是否为html格式的邮件
                    message.Body = FreeTextBox1.Text;//邮件的内容
    
                    string smtp = "smtp.yeah.net";//因为我用的是163的邮箱,所以这里用到的是用163的
                    SmtpClient sc = new SmtpClient(smtp);//发送邮件用到的smtp主机(用不同的邮箱,stmp定义则不同)
                    string email = "email";//ConfigurationManager.AppSettings["email"];
                    string pwd = "pwds";//ConfigurationManager.AppSettings["email_pwd"];
                    sc.Credentials = new System.Net.NetworkCredential(email,pwd);//邮箱账号与密码 
                    sc.Send(message);   //发送邮件
                }
                catch (SmtpException se)
                {
                    Response.Write("<script>alert('"+se.ToString()+"');</script>");
                }
    
        }
    
    
  • 相关阅读:
    sql语句添加查询字段
    SqlServer Case when then用法总结
    单例与多线程
    HttpSession详解
    范式
    SQL语句中的Having子句与where子句
    HTTP无状态
    字节流与字符流的区别
    选择排序
    ReentrantLock VS synchronized
  • 原文地址:https://www.cnblogs.com/sh_yao/p/1897598.html
Copyright © 2011-2022 走看看