Copy body of outlook mail to a text file - c#

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);

Related

Create MailMessage object from .msg File Path?

Is there a way to create a MailMessage object from a directory path of a .msg file?
Such as MailMessage x = new MailMessage("path")
There is no direct conversion between these two entities out of the box - the Outlook message file and the MailMessage class from the .net framework. You can automate Outlook to get the instance of the MSG file instantiated using the NameSpace.OpenSharedItem method which is used to open iCalendar appointment (.ics) files, vCard (.vcf) files, and Outlook message (.msg) files.
You can also use Redemption for that, look for RDOSession.GetMessageFromMsgFile.
Thanks for the replies but I found the answer on this existing post: C# Outlook interop and OpenSharedItem for opening MSG files
Like Eugene said, I used the Microsoft.Office.Interop.Outlook.Application to open the .msg file via Outlook.

Change what file an Outlook attachment points to

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

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.

'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.

how to read mail from Google mail and mark as save and save mail in local folder with C# .NET

I am trying to build a winform app to
read mails from google app
save mail and attachment to local folder
mark mail as read
Save the email body and attachments to a SQL-Server database
The latter is ok but I'm really having trouble with the first 3.
I've look everywhere and people are telling me how to send mail on a winform app but not how to read, mark and save content and attachment.
CodeProject is probably the next best resource online after SO (IMHO.) Here are some well-reviewed sample projects that will get you a long way:
http://www.codeproject.com/Articles/14304/POP3-Email-Client-NET-2-0
http://www.codeproject.com/Articles/6062/A-POP3-Client-in-C-NET
http://www.codeproject.com/Articles/188349/Read-Gmail-Inbox-Message-in-ASP-NET
http://www.codeproject.com/Articles/34495/Building-your-own-Mail-Client-using-C
http://www.codeproject.com/Articles/15611/POP3-Email-Client-with-full-MIME-Support-NET-2-0

Categories

Resources