Am processing emails using exchange web services. Is new to me but this works fine, however I've come across a 'feature' I can't resolve.
I have to save the emails to disk, so I do in the eml format using:
File.WriteAllBytes(fileName, email.MimeContent.Content);
Sometimes the emails I process have an msg file attached to them, but when I load the saved eml file, I see the msg attached is now in eml format as well.
How can I keep an msg attachment as an msg attachment when saving to an eml file?
How are you setting the filename? Can you check the original attachment format/extension and then save the new one with the same extension?
Related
Is it possible to create an excel file and after send the file without to save it on the computer by email with attachment ?
Now I create the excel file and I save the file in my computer and after I send the mail with the file attached. It works but I want to send the file directly without saving in the disk.
I use this for the attachment
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("C:/Users/.......");
mail.Attachments.Add(attachment);
Thanks.
In my application, i send mails to managers from program automatically. Normally it works good, but when i use program on another computer, it sends mail automatically but file type is not PDF. File type is File and name of pdf is =utf-8BQU5HT1JBIEhBTEkgQS7Fni4gR8OcTkzD. I also checked source codes. But I couldn't understand what is wrong with that. Any idea what to do?
Try to fill the ContentDisposition, example is here:
Sending email with attachments from C#, attachments arrive as Part 1.2 in Thunderbird
Maybe, in the code you can change the MediaTypeNames.Application.Octet to MediaTypeNames.Application.Pdf
I hope, this helps!
I am trying to develop an outlook add-in in VS 2010. It's purpose is to scan email body and attachment content for some key words and if any such words are found, email sending should be blocked.
I am able to read email body and subject and to the validation but I am not understanding how to read an attachment content (txt file) while composing the mail.
attachment.GetTemporaryPath() is not giving the attachment path. I guess this works only for mails in inbox.
One way I found was saving the attachment to a temp folder and reading it (attachment.saveAs()).
Is this the only way to read attachment content while composing a mail ?
Possible Duplicate : C# Outlook 2007 - How do I access attachment contents directly from my addin?
But as suggested in there, I cant use Redemption. Is there any other way?
Yes, saving the attachment data to a temporary file and reading it s the only way. In theory, you can use Attachment.PropertyAccessor.GetProperty to read the PR_ATTACH_DATA_BIN property, but you will run into problems for the large (> 64kB) files.
You can also use Extended MAPI to open the attachment data as IStream (IAttach::OpenProperty(PR_ATTACH_DATA_BIN, IID_IStream)), but it is only accessible through C++ or Delphi. You can use Redemption (any language - I am its author) that wraps Extended MAPI and exposes AsArray and AsText properties on both RDOAttachment and the Attachment object exposed by the Safe*Item objects.
I am getting the attachments from an outlook mail. There are some traps aroudn this from c#, but most of them are solved by some ugly hacks. But there is one that I am not able to solve.
If I add an attachment as a file, the whole filename is saved including the file extenssion. So when I save the file to disc later it's saved correctly so I can only dblclick the file and it's opened in the correct application.
But if the attachement is added using the "Attach Item" -> "Add outlook Item", the mail/calender/contact is added without the file extenssion. So If I add a mail to my mail with this function then the .msg fileextension is not part of the filename and when trying to save it to disc it is recognized as an outlook mail.
But if I check in outlook I can see that the correct icon is added for this attachment, so outlook is able to know if it's a mail / contact / calenderitem so the information should be there somewhere.
Does anybody knows how to find out that it's a .msg that is in the attachment?
When you pass an Outlook item to Attachments.Add, you add create an embedded message attachment (Attachment.Type = olEmbeddeditem) as opposed to the regular olByValue attachment.
BTW, the filename(Attachment.FileName) will always include the .msg extension. What are the cases when it is not there?
Hell guys,
I'm coding in csharp to send an email which contains a .zip file (has htmls and css inside). When I check the mail recieved, In fact, instead of the .zip file, the attachment becomes a txt file and has:
FILE QUARANTINED
The original contents of this file have been replaced with
this message because of its characteristics.
File name: 'xxxxxxx_Result.zip'
Virus name: 'Large uncompressed size'
The exchange server has blocked the zip file..I'm using CDO to create and send the email.
I tried using the code to send a mail with a zip file generated by WINZIP, there was no problem, then I tried using outlook to send a mail with the zip file generated by my code(I use sharpziplib library), the problem occured...
How can I do to send the attachment correctly? Many thanks in advance!
Allen
I encounter similar problems sending email on our network. I've found that using an alternate compression format, such as 7-zip (.7z), is adequate to get my content through the filters. This could resolve the issue if the block is not due strictly to size.
Looks like your mail server or spam service have removed your attachement and replaced it with the txt file, it sounds like your code is fine and you need to speak to an admin regarding the mail filters and send size quotas!
For anyone facing this problem, here is a solution. You have to explicitly set the file size for the zipentry.
ZipEntry newEntry = new ZipEntry(fileName);
newEntry.DateTime = DateTime.Now;
newEntry.Size = fileData.Length; // setting data size