I'm working with the EWS Managed API 2.0.
At this moment I can save EmailMessages to my harddrive as *.eml files.
However I can't open them correctly to show the content.
How can an EmailMessage (.eml) be saved as an .html, .doc or .txt file directly?
Use following code if you want to save it as .eml
message.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mimcon = message.MimeContent;
FileStream fStream = new FileStream("c:\test.eml", FileMode.Create);
fStream.Write(mimcon.Content, 0, mimcon.Content.Length);
fStream.Close();
For msg file look at following link:
http://msdn.microsoft.com/en-us/library/cc463912%28EXCHG.80%29.aspx
After saving it as .eml file you can look at following post for parsing it:
Recommendations on parsing .eml files in C#
Hope its helpful.
Related
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
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
I'm trying to Zip and send .csv files using C#.
I create the files, zip them and send them using an SMTP Gmail host.
It can sometimes take this email several hours to reach it's destination.
For testing I am using very small files so size isn't an issue.
If I try to "manually" send these zips using gmail I get the following error:
"myFile.csv.zip contains an executable file. For security reasons, Gmail does not allow you to send this type of file."
I think there might be a problem with my compression method but it's very straight forward:
string compressedFile = fileName + ".zip";
FileInfo fi = new FileInfo(fileName);
using (FileStream inFile = fi.OpenRead())
{
using (FileStream outFile = File.Create(compressedFile))
{
using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress))
{
inFile.CopyTo(Compress);
Compress.Close();
}
outFile.Dispose();
}
}
return compressedFile;
Just a note:
If I take the same file and manually Zip or rar it I have no problem. This happens with text files too.
Quote from the MSDN:
Compressed GZipStream objects written to a file with an extension of .gz can be decompressed using many common compression tools
GZip files are not really "zip" files. They usually use "gz" as file extension. You might try that, maybe Gmail is very strict about "matching" extensions and compression formats.
If you are using .NET 4.5 you can alternatively use the ZipArchive class. That one actually handles "zip" files.
I have list of pdf file url in excel template Now i want to upload all files from my local pc to server just by browsing the excel file and click to upload.
I have achieved this task by using iTextSharp Library pdfreader and pdfstamper class, but what problem is, i need to read all files by using pdfreader.
Case may come, when some of pdf files are encrypted, So i can not able to read that file using pdfreader of itextsharp and not be able to upload the same.
Is it possible that without reading the pdf file i can just dumped it to server just like what Fileupload.Saveas method does????
I'm trying to Zip and send .csv files using C#.
I create the files, zip them and send them using an SMTP Gmail host.
It can sometimes take this email several hours to reach it's destination.
For testing I am using very small files so size isn't an issue.
If I try to "manually" send these zips using gmail I get the following error:
"myFile.csv.zip contains an executable file. For security reasons, Gmail does not allow you to send this type of file."
I think there might be a problem with my compression method but it's very straight forward:
string compressedFile = fileName + ".zip";
FileInfo fi = new FileInfo(fileName);
using (FileStream inFile = fi.OpenRead())
{
using (FileStream outFile = File.Create(compressedFile))
{
using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress))
{
inFile.CopyTo(Compress);
Compress.Close();
}
outFile.Dispose();
}
}
return compressedFile;
Just a note:
If I take the same file and manually Zip or rar it I have no problem. This happens with text files too.
Quote from the MSDN:
Compressed GZipStream objects written to a file with an extension of .gz can be decompressed using many common compression tools
GZip files are not really "zip" files. They usually use "gz" as file extension. You might try that, maybe Gmail is very strict about "matching" extensions and compression formats.
If you are using .NET 4.5 you can alternatively use the ZipArchive class. That one actually handles "zip" files.