在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
添加引用:Microsoft.Office.Interop.Outlook 1 public class EmailHelper 2 { 3 /// <summary> 4 /// 收件人,多个收件人用分号";"隔开 5 /// </summary> 6 public string MailTo { get; set; } 7 8 /// <summary> 9 /// 抄送,多个收件人用分号";"隔开 10 /// </summary> 11 public string MailCC { get; set; } 12 13 /// <summary> 14 /// 密送,多个收件人用分号";"隔开 15 /// </summary> 16 public string MailBCC { get; set; } 17 18 /// <summary> 19 /// 主题 20 /// </summary> 21 public string MailSubject { get; set; } 22 23 /// <summary> 24 /// 内容 25 /// </summary> 26 public string MailHTMLBody { get; set; } 27 28 /// <summary> 29 /// 多个附加用分号";"隔开 30 /// </summary> 31 public string MailAttachments { get; set; } 32 33 public bool Send() 34 { 35 try 36 { 37 Outlook.Application olApp = new Outlook.Application(); 38 Outlook.MailItem mailItem = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem); 39 mailItem.To = MailTo; 40 mailItem.CC = MailCC; 41 mailItem.BCC = MailBCC; 42 mailItem.Subject = MailSubject; 43 mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;//内容格式 44 mailItem.HTMLBody = MailHTMLBody; 45 foreach (var item in MailAttachments.Split(';')) 46 { 47 mailItem.Attachments.Add(item); 48 } 49 mailItem.Send(); 50 mailItem = null; 51 olApp = null; 52 return true; 53 } 54 catch (System.Exception ex) 55 { 56 return false; 57 } 58 } 59 } 在使用前需要先在本地的Outlook上配置发送人的用户信息。 Microsoft.Office.Interop.Outlook 官网文档:https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook?view=outlook-pia |
请发表评论