方法一:
public static string SendMail2(string add_smtp, string acc_SendMail, string psw_SendMail, string add_SendMail, ArrayList arr_GetMail, ArrayList arr_CcMail, ArrayList arr_McMail, ArrayList arr_Att, string body, string subject, bool bodytype) { add_smtp = "实际地址"; psw_SendMail = "密码"; string result = ""; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(add_smtp, 25); smtp.Credentials = new System.Net.NetworkCredential(acc_SendMail, psw_SendMail); System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); for (int s = 0; s < arr_GetMail.Count; s++) { mail.To.Add(arr_GetMail[s].ToString() + ""); } //抄送 for (int c = 0; c < arr_CcMail.Count; c++) { mail.CC.Add(arr_CcMail[c].ToString() + ""); } //密送 for (int c = 0; c < arr_McMail.Count; c++) { mail.Bcc.Add(arr_McMail[c].ToString() + ""); } mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312"); mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); mail.From = new System.Net.Mail.MailAddress(add_SendMail); mail.Priority = System.Net.Mail.MailPriority.Normal; mail.Subject = subject; mail.Body = body; mail.IsBodyHtml = bodytype; for (int d = 0; d < arr_Att.Count; d++) { System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(arr_Att[d].ToString()); mail.Attachments.Add(attachment); } try { smtp.Send(mail); result = "sucess"; } catch (System.Net.Mail.SmtpException ex) { result = ex.Message + ex.Source; } finally { mail.Dispose(); } return result; }
方法二:
/// <summary> /// 邮件发送辅助类 /// </summary> public class MailHelper { /// <summary> /// 发送邮件 [如果发送失败,不添加重发] /// </summary> /// <param name="tomail">收件人</param> /// <param name="subject">主题</param> /// <param name="body">消息内容</param> public static void SendMail(string tomail, string subject, string body,string mailFrom) { // 设置发送方的邮件信息,例如使用网易的smtp string smtpServer = "实际地址"; //SMTP服务器 string user = "用户名"; string userPassword = "密码";//登陆密码 string mailTo = tomail; // 邮件服务设置 SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = smtpServer; //指定SMTP服务器 smtpClient.Port = 25; smtpClient.UseDefaultCredentials = false; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 smtpClient.Credentials = new System.Net.NetworkCredential(mailFrom, userPassword);//用户名和密码 // 发送邮件设置 MailMessage mailMessage = new MailMessage(mailFrom, mailTo); // 发送人和收件人 mailMessage.Subject = subject;//主题 mailMessage.Body = body;//内容 mailMessage.BodyEncoding = Encoding.UTF8;//正文编码 mailMessage.IsBodyHtml = true;//设置为HTML格式 try { smtpClient.Send(mailMessage); // 发送邮件 } catch (SmtpException ex) { throw ex; } } }
标签:arr,string,C#,System,发送,Mail,mail,Net,邮件 From: https://www.cnblogs.com/ydc2023/p/16995731.html