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("[email protected]", "从某处发");
            mailMsg.To.Add(email);  //收件人地址
            //mailMsg.To.Add("[email protected]");  //收件人地址
            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("[email protected]", "******");
            smtp.Credentials = new NetworkCredential("[email protected]", "*******");            
            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());
            }
        }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。