private string SendEmail(string mailTo, string body, ref int sendresult) { string errorEmailAddress = ""; SmtpClient smtp = new SmtpClient(_SmtpServer); try { MailMessage message = new MailMessage(); message.Priority = MailPriority.High; message.From = new MailAddress(_From); //message.To.Add(mailTo); message.Subject = _Subject; message.Body = body; message.IsBodyHtml = true; message.Bcc.Add(new MailAddress(_Bcc, "", Encoding.Default)); SetToMailAddress(mailTo, message, ref errorEmailAddress); if (message.To.Count > 0) { smtp.Send(message); sendresult = 1; } smtp.Dispose(); return string.IsNullOrEmpty(errorEmailAddress) ? string.Empty : ("Error email address:"+errorEmailAddress); } catch (Exception e) { smtp.Dispose(); return e.InnerException.Message + (string.IsNullOrEmpty(errorEmailAddress) ? "" : (" Error email address: " + errorEmailAddress)); } } private static void SetToMailAddress(string toMailAddress, MailMessage message, ref string errorEmailAddress) { string[] addes = toMailAddress.Split(';').ToArray(); foreach (string s in addes) { if (Regex.IsMatch(s, @"w+([-+.']w+)*@w+([-.]w+)*.w+([-.]w+)*")) { message.To.Add(new MailAddress(s.Trim(), "", Encoding.Default)); } else { errorEmailAddress += s + ";"; } } }