邮件发送

 public bool Send()

        {

            //mail message

            MailMessage myMail = new MailMessage();

            myMail.From = new MailAddress("[email protected]");      // 发送人

            myMail.To.Add(new MailAddress("[email protected]"));   // 接收人邮箱

            myMail.Subject = "测试邮件发送--主题";

            myMail.SubjectEncoding = Encoding.UTF8;

            myMail.Body = "测试邮件发送--正文测试邮件发送--正文测试邮件发送--正文测试邮件发送--正文测试邮件发送--正文";

            myMail.BodyEncoding = Encoding.UTF8;

            myMail.IsBodyHtml = false;

            myMail.Priority = MailPriority.Normal;                // 邮件级别

            //myMail.CC.Add(new MailAddress("[email protected]"));   // 抄送

            //myMail.Bcc.Add(new MailAddress("[email protected]"));  // 密送



            //Smtp Client

            SmtpClient sender = new SmtpClient();

            sender.Host = "smtp.163.com";// email.Host;

            //sender.Port = 80;

            // 设置发送人的邮箱和密码

            sender.Credentials = new NetworkCredential("[email protected]", "3232");

            sender.DeliveryMethod = SmtpDeliveryMethod.Network;

            sender.EnableSsl = false;  // 是否启用 SSL 加密



            try

            {

                sender.Send(myMail);

                return true;

            }

            catch (Exception e)

            {

                throw new Exception(e.Message);

            }

        }

 

你可能感兴趣的:(邮件发送)