簡體   English   中英

將生成的附件添加到Outlook電子郵件

[英]Add generated attachment to Outlook email

我有一些工作代碼可將附件添加到Outlook。 但是我們在添加附件時必須指定文件的物理位置。 在我的方案中,我將數據表導出到Word文檔,並且需要將該文檔附加到電子郵件,而無需將文檔保存在文件夾中。 代碼如下。

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
oMailItem.To = "test@gmail.com";
oMailItem.Subject = "Outlook Email test Subject";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(strwritter);
GridView gv = new GridView();
DataTable dtWord = GetDataItem();
gv.DataSource = dtWord;
gv.DataBind();
gv.RenderControl(htmlWrite);
MemoryStream ms = null;
StreamWriter sw = new StreamWriter(ms);
sw.WriteLine(sb.ToString());
sw.Flush();
ms.Seek(0, SeekOrigin.Begin);

string fileName = @"D:\test.doc";
oMailItem.Attachments.Add(fileName, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
oMailItem.Display(true);

因此,我需要將內存流添加為電子郵件附件。 請幫忙。 非常感謝!

你不能這樣做。 Outlook中的Attachments.Add使用帶有附件文件名的字符串或另一個Outlook項目(MailItem等)作為參數。

如果使用贖回是一個選項,則其RDOAttachments .Add方法還將IStream COM接口作為參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM