Guest User

Untitled

a guest
Jan 17th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. private void AddMessageAsAttachment(Microsoft.Office.Interop.Outlook.MailItem
  2. mailContainer,Microsoft.Office.Interop.Outlook.MailItem mailToAttach)
  3. {
  4. Microsoft.Office.Interop.Outlook.Attachments attachments = null;
  5. Microsoft.Office.Interop.Outlook.Attachment attachment = null;
  6. try
  7. {
  8. attachments = mailContainer.Attachments;
  9. attachment = attachments.Add(mailToAttach,
  10. Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, 1, "The attached e-mail");
  11. mailContainer.Save();
  12. }
  13. catch (Exception ex)
  14. {
  15. Console.WriteLine(ex.Message);
  16. }
  17. finally
  18. {
  19. if (attachment != null) Marshal.ReleaseComObject(attachment);
  20. if (attachments != null) Marshal.ReleaseComObject(attachments);
  21. }
  22. }
Add Comment
Please, Sign In to add comment