.NET Send Email

 public static void sendEmail(string sendto, string ccto, string subject, string resultContent)
        {
            string mailaccount = ConfigurationManager.AppSettings["EmailAccount"].ToString();
            string mailpwd = ConfigurationManager.AppSettings["EmailPassword"].ToString();
            MailMessage myMail = new MailMessage();
            myMail.From = new MailAddress(mailaccount);//(ConfigurationManager.AppSettings["MonitorEmailFrom"].ToString());
            //send to
            string[] addressArray = sendto.Split(';');
            foreach (string add in addressArray)
            {
                if (add.Contains(@"@"))
                    myMail.To.Add(new MailAddress(add));
            }

            //cc to
            string[] ccAddressArray = ccto.Split(';');
            foreach (string add in ccAddressArray)
            {
                if (add.Contains(@"@"))
                    myMail.CC.Add(new MailAddress(add));
            }


            myMail.Subject = subject;
            myMail.SubjectEncoding = Encoding.UTF8;
            myMail.Body = resultContent;
            myMail.BodyEncoding = Encoding.UTF8;
            //myMail.IsBodyHtml = false;
            myMail.Priority = MailPriority.High;
            myMail.IsBodyHtml = true;


            //myMail.Bcc.Add(new MailAddress("[email protected]"));
            SmtpClient sender = new SmtpClient();
            sender.Host = ConfigurationManager.AppSettings["EmailHost"].ToString();
            sender.Port = 25;
            sender.DeliveryMethod = SmtpDeliveryMethod.Network;
            sender.UseDefaultCredentials = false;
            sender.Credentials = new NetworkCredential(mailaccount, mailpwd);
            try
            {
                sender.Send(myMail);
                Console.WriteLine("Send mail Succeed!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed.Exception:{0}", e.Message);
            }
        }


你可能感兴趣的:(.NET Send Email)