导航

 

    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>");
            }

    }