首页 > 代码库 > C#在outlook里创建一封邮件到草稿箱
C#在outlook里创建一封邮件到草稿箱
原文:C#在outlook里创建一封邮件到草稿箱View Code
1.引用Microsoft.Office.Interop.Outlook.dll
2. 实现代码
1 public static int SendToDraft(List<string> to, List<string> cc, List<string> bcc, string subject, string content, List<string> attachments, ref string errorMessage) 2 { 3 int result = -1; 4 try 5 { 6 StringBuilder sbattachment = new StringBuilder(); 7 Application objOutlook = new Application(); 8 NameSpace oNameSpace = objOutlook.GetNamespace("MAPI"); 9 MAPIFolder folder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderDrafts);10 MailItem item = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));11 item.To = GetString(to);12 item.CC = GetString(cc);13 item.BCC = GetString(bcc);14 item.Subject = subject;15 item.HTMLBody = content;16 new Log("send email outlook ").Write("7");17 //添加附件18 if (attachments != null && attachments.Count > 0)19 {20 for (int i = 0; i < attachments.Count; i++)21 {22 item.Attachments.Add(@attachments[i]);23 }24 }25 item.SaveSentMessageFolder = folder;26 item.Save();27 result = 0;28 }29 catch (System.Exception ex)30 {31 result = -3;32 errorMessage = ex.Message.ToString();33 }34 return result;35 }
C#在outlook里创建一封邮件到草稿箱
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。