Change what file an Outlook attachment points to - c#

For instance, I have a word document as an Outlook attachment. I want to have a C# program that will find that file's local location, process it into a PDF, and then change the email's attachment to that new PDF file. The next time that attachment is opened, it will open the PDF and not the word document.
Edit 1: The email attachment is in my inbox, as someone has sent this file to me. I am able to edit the actual word file just like any other document just fine. I figure this would be possible by adding
Is this function possible? and remoreceived chments to existing recieved emails as well.

Yes, that is possible. You can develop an Outlook COM add-in (for example, a VSTO based one). The Attachment class provides the SaveAsFile method which saves the attachment to the specified path. Then you can automate Word where you may open the file just saved and re-save it using the .pdf file format. Or you may consider using third-party components that don't require Word installed on the system. After converting the document and getting the required pdf file you may remove an old attachment and re-add a new one. The Attachments.Add creates a new attachment in the Attachments collection.
You may find the following articles helpful:
Attach a File to a Mail Item
Modify an Attachment of an Outlook Email Message
How To: Add an attachment to an Outlook e-mail message

Related

C# Outlook Plugin - Get full path (origin source file) of attachment in mail?

I want to get full path (origin source file) of attachment in mail Outlook, I use object Attachment in Outlook to get Pathname: Attachment.PathName, but it returns null.
So, how can I get the source file's link?
Example: this is a link to image attachment in a my email
Email attachments do not have a source path. Once they were sent, they are part of the message, not part of any file system, regardless of their source path. The best you can do is get the attachment file name.
As you can read here, Attachment.PathName only works with linked files, not attached files:
Remarks:
This property is only valid for linked files.

Copy body of outlook mail to a text file

Is there any way to copy email body of an outlook mail to a text file using c#. I am not getting a way to do this
when using Interop this will help to save the whole mail as Text file. Then you can parse the file to get the body part and save it.
mailItem.SaveAs(#"c:\path\to\save\mail.msg", Outlook.OlSaveAsType.olTXT);

Programmatically Attach PDF from MemoryStream to Outlook E-Mail Items

Would it be possible to attach PDF from MemoryStream or other functions to Outlook E-Mail Items MailItem.Attachment.add(), rather than from the file on the hard disk by passing the physical path of file in this method.
I would like to create the Outlook mailitem for the users with the PDF attached programmatically, and let the users to review and send out the email by themselves.
Thank you in advance.
Not using the Outlook Object Model - Attachments.Add will only let you pass a file name for the olByValue attachments. Extended MAPI (C++ or Delphi) only operates on IStream objects (IAttach::OpenProperty(PR_ATTACH_DATA_BIN, IID_IStream,...)), Redemption (I am its author) lets you pass file name, url, array, IStream or IStorage to RDOAttachments.Add.

How to save MailMesage to .msg file?

I need save a MailMessage to .msg file. In this article have a solution but when I save as .msg file, it does not work in MS Outlook. It only great work when I save as.eml file.
How to save MailMessage object to disk as *.eml or *.msg file
Note that I get when open the .msg file:
Cannot open file: path. The file may not exist, you may not have permission to open it, or it may open in another program. Right-click the folder that contains the file, and then click Properties check your permisstions for the folder.
Thank all.
In Interop Outlook, this is how to locally save a mail as .msg.
mailItem.SaveAs(#"c:\path\to\save\mail.msg", Outlook.OlSaveAsType.olMSG);
How exactly are you creating the MSG file? It is completely different from an EML file - see https://stackoverflow.com/questions/16229591/difference-between-a-msg-file-and-a-eml-file/16230261#16230261
MSG file format is a binary IStorage file, and its format is documented. You can parse your EML (MIME) file and copy one property at a time to a programmatically created MSG file.
If using Redemption is an option (I am its author), you can use Session.CreateMessageFromMsgFile to create a new MSG file and RDOMail.Import method to import your existing EML file.
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.CreateMessageFromMsgFile("c:\temp\test.msg")
Msg.Sent = true '//since Import does not copy this property
Msg.Import("c:\temp\test.eml", 1024) ' //1024 is olRfc822
Msg.Save

'The given path's format is not supported' when attaching with email

I am trying to attach some pdf document when sending email but I get above error when I try to attach.
code I am using is:
Attachment a = new Attachment("External_path", MediaTypeNames.Application.Octet);
External_Path points to pdf on external website and can confirm it exists. I have also tried chaing MediaTypeNames to 'MediaTypeNames.Application.Pdf' but that didn't work either.
Has someone experienced same problem while attaching attachments to an email?
The documentation of Attachment says, the constructor must be called with a file path. What you use is an URL.
You must download the document to a local (temporary) file and read it from there.

Categories

Resources