public static void Send(EmailItem item, EmailServer server) { MailMessage msg = new MailMessage(); msg.From = new MailAddress(item.FromAccount, item.FromShowName); if (string.IsNullOrEmpty(item.Title)) { throw new Helper.Excep.HelperException("邮件标题为空!"); } if (string.IsNullOrEmpty(item.Body)) { throw new Helper.Excep.HelperException("邮件内容为空!"); } foreach (string s in item.To) { msg.To.Add(new MailAddress(s)); } if (item.Cc != null) { foreach (string s in item.Cc) { msg.CC.Add(new MailAddress(s)); } } if (item.Bcc != null) { foreach (string s in item.Bcc) { msg.Bcc.Add(new MailAddress(s)); } } msg.IsBodyHtml = item.IsHtml; if (string.IsNullOrEmpty(item.EncodingName)) { msg.BodyEncoding = System.Text.Encoding.Default;// Encoding.GetEncoding(item.EncodingName); } else { msg.BodyEncoding = Encoding.GetEncoding(item.EncodingName); } msg.Subject = item.Title; if (string.IsNullOrEmpty(item.EncodingName)) { msg.SubjectEncoding = System.Text.Encoding.Default; } else { msg.SubjectEncoding = Encoding.GetEncoding(item.EncodingName); } msg.Body = item.Body; if (item.IsPretend) { msg.Headers.Add("X-Priority", "3"); msg.Headers.Add("X-MSMail-Priority", "Normal"); msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869"); } try { if (server.Port == 0) { server.Port = 25; } SmtpClient client = new SmtpClient(server.Server, server.Port); client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential(server.UserName, server.Password); client.DeliveryMethod = SmtpDeliveryMethod.Network; // client.EnableSsl = true; client.Send(msg); } catch (Exception) { throw; } }
public void Send(EmailItem item) { EmailManager.Send(item, this); }
public static void Send(EmailItem item, EmailServer server) { MailMessage msg = new MailMessage(); msg.From = new MailAddress(item.FromAccount, item.FromShowName); if (string.IsNullOrEmpty(item.Title)) { throw new Helper.Excep.HelperException("邮件标题为空!"); } if (string.IsNullOrEmpty(item.Body)) { throw new Helper.Excep.HelperException("邮件内容为空!"); } foreach (string s in item.To) { msg.To.Add(new MailAddress(s)); } if (item.Cc != null) { foreach (string s in item.Cc) { msg.CC.Add(new MailAddress(s)); } } if (item.Bcc != null) { foreach (string s in item.Bcc) { msg.Bcc.Add(new MailAddress(s)); } } msg.IsBodyHtml = item.IsHtml; if (string.IsNullOrEmpty(item.EncodingName)) msg.BodyEncoding = System.Text.Encoding.Default;// Encoding.GetEncoding(item.EncodingName); else msg.BodyEncoding = Encoding.GetEncoding(item.EncodingName); msg.Subject = item.Title; if (string.IsNullOrEmpty(item.EncodingName)) msg.SubjectEncoding = System.Text.Encoding.Default; else msg.SubjectEncoding = Encoding.GetEncoding(item.EncodingName); msg.Body = item.Body; if (item.IsPretend) { msg.Headers.Add("X-Priority", "3"); msg.Headers.Add("X-MSMail-Priority", "Normal"); msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869"); } try { if (server.Port == 0) server.Port = 25; SmtpClient client = new SmtpClient(server.Server, server.Port); client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential(server.UserName, server.Password); client.DeliveryMethod = SmtpDeliveryMethod.Network; // client.EnableSsl = true; client.Send(msg); } catch (Exception) { throw; } }