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

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

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         }
View Code

 

posted on 2014-10-02 07:14 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/4003811.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值