曹永思

导航

asp.net 发送邮件

Asp.Net发送邮件方法

 

     /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="body"></param>
        /// <param name="email"></param>
        /// <param name="Subject"></param>
        private static void SendEmail(string body, string email, string Subject)
        {
            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("xxxxxxxxx@aa.com", "从某处发");
            mailMsg.To.Add(email);  //收件人地址
            //mailMsg.To.Add("123546@163.com");  //收件人地址
            mailMsg.Subject = Subject;
            mailMsg.Body = body;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.IsBodyHtml = true;
            mailMsg.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient();
            // 提供身份验证的用户名和密码  8591211
           // smtp.Credentials = new NetworkCredential("xxxxxx@163.com", "******");
            smtp.Credentials = new NetworkCredential("xxxxxxxxx@aa.com", "*******");            
            smtp.Port = 25; // Gmail 使用 465 和 587 端口 
            smtp.Host = "smtp.aa.com";//"mail.aa.com"; // 如 smtp.163.com, smtp.gmail.com 
            smtp.EnableSsl = false; // 如果使用GMail,则需要设置为true 
            smtp.SendCompleted += new SendCompletedEventHandler(SendMailCompleted);

            try
            {
                smtp.SendAsync(mailMsg, mailMsg);
                //存储已发送邮件用户ID
            }
            catch (SmtpException ex)
            {
                //  Response.Write(ex.ToString());
            }
        }

 

posted on 2014-08-27 14:59  曹永思  阅读(135)  评论(0编辑  收藏  举报