码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-10-02 09:29:52      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

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

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

2.  实现代码

bubuko.com,布布扣
 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

 

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

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/lonelyxmas/p/4003811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!