C#在outlook里创建一封邮件到草稿箱

原文:C#在outlook里创建一封邮件到草稿箱

1.引用Microsoft.Office.Interop.Outlook.dll

2.  实现代码

C#在outlook里创建一封邮件到草稿箱C#在outlook里创建一封邮件到草稿箱
 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         }
View Code

 

上一篇:Outlook 2010 配置关联QQ邮箱


下一篇:Linux mail命令查看邮箱邮件