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

发布日期:2018-02-26    浏览次数:710

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

2.  实现代码

public static int SendToDraft(List to, List cc, List bcc, string subject, string content, List attachments, ref string errorMessage)
        {
            int result = -1;
            try
            {
                StringBuilder sbattachment = new StringBuilder();
                Application objOutlook = new Application();
                NameSpace oNameSpace = objOutlook.GetNamespace("MAPI");
                MAPIFolder folder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderDrafts);
                MailItem item = (MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));
                item.To = GetString(to);
                item.CC = GetString(cc);
                item.BCC = GetString(bcc);
                item.Subject = subject;
                item.HTMLBody = content;
                new Log("send email outlook ").Write("7");
                //添加附件
                if (attachments != null && attachments.Count > 0)
                {
                    for (int i = 0; i < attachments.Count; i++)
                    {
                        item.Attachments.Add(@attachments[i]);
                    }
                }
                item.SaveSentMessageFolder = folder;
                item.Save();
                result = 0;
            }
            catch (System.Exception ex)
            {
                result = -3;
                errorMessage = ex.Message.ToString();
            }
            return result;
        }

本文网址:https://www.wyxxw.cn/blog-detail-2-6-787.html

返回列表

非特殊说明,本文版权归原作者所有,转载请注明出处

提示:本站所有资源仅供学习与参考,请勿用于商业用途。图片来自互联网~如侵犯您的权益,请联系QQ:1067507709.

提示:转载请注明来自:http://www.cnblogs.com/eims119/p/3529535.html 。 转载人:momo