We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Processing digitally signed emails to retrieve MIME attachments

EDIT: Formatting changes and since I seem to be addressing the community, rather than solely company representatives...


I have a particular issue in a PowerShell script where the MS Exchange Web Services API (.Net) does not abstract out individual attachments when the email has been digitally signed (which is a requirement in our environment) and instead only provides the MIME-encoded byte array representing what I believe to be all MIME sections, including message(s), nested attachments, and finally signature. I have a temporary solution to roughly parse MIME encoding, but I am seeking a fully MIME-compliant solution to harden against future changes. I'd appreciate if anyone can confirm the following about Aspose, so that I can determine whether to recommend this software as part of our solution:



1) the EMAIL library can accept a MIME-encoded byte array and use it to either :



a. provide file byte streams with appropriate meta data (filenames, etc), OR

b. write all file attachments to disk at a given location


2) OR, the EMAIL library can handle:

a. connecting to an Exchange account, with password from a secure-string or else a PowerShell Credentials object, AND

b. finding email metadata to locate and process emails correctly, AND

c. save attachments for an email to disk, AND

d. move emails amongst folders in the same user account, again all in Exchange – I am under the understanding that IMAP and POP3 access is disabled in this environment, though I haven't actually tried to determine it, as I don't have direct access.


I have looked through the site's examples and I have not found examples of nested MIME blocks being decoded when the MIME content is signed – it seems like any library claiming to be a general MIME library should handle that, but at least the version of EWS I have does not seem to do that properly, so I would prefer to confirm this capability.



Also, what's with me having to use HTML markup to post something other than a blob of text here?

Hi,

Thank you for contacting Aspose support team.

  1. Aspose.Email library can handle digitally signed emails for retrieving the mime attachments. Following example reads a MIME encoded byte array from a file and then use this byte array to construct a message and save attachments on disc.

    using (var stream = new MemoryStream(File.ReadAllBytes(@“Signed.eml”)))

    {

    using (var restream = new MemoryStream())

    {

    EmlSaveOptions options = new EmlSaveOptions(MailMessageSaveType.EmlFormat)

    {

    PreserveOriginalBoundaries = true,

    PreserveSignedContent = true

    };

    MailMessage mimeMessage = MailMessage.Load(stream);

    foreach(Attachment att in mimeMessage.Attachments)

    {

    att.Save(path + att.Name);

    }

    }

    }

    1. Currently Aspose.Email does not support excepting secure string passwords. You may provide plain string passwords to connect to the server as follows.

    IEWSClient client =EWSClient.GetEWSClient(“https://outlook.office365.com/ews/exchange.asmx","User@xyz2016.onmicrosoft.com ”, “password”, “onmicrosoft.com”);

    We can extract mails meta data from the server and then fetch mails as required.

    ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
    builder.HasNoFlags(ExchangeMessageFlag.IsRead);
    MailQuery query = builder.GetQuery();
    ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, query);
    //Parse all the messages info collection
    foreach (ExchangeMessageInfo info in messageInfoCol)
    {
    if (info.Subject == subject)
    {
    MailMessage msg = client.FetchMessage(info.UniqueUri);
    foreach(Attachment att in mimeMessage.Attachments)
    {
    att.Save(path + att.Name);
    }

    }
    }

For moving mails from one folder to another, please have a look at the this article .