[Imap][Mail][.net] Attachment constructor: "Invalid Character error " with parameter 'name'

0 votes
asked Dec 13, 2017 by makertoo (160 points)
edited Dec 13, 2017 by makertoo

Hello,
I have an issue when instantiating new Attachment

   using (Stream str = new MemoryStream(imap.MessageB))
      {
        attachment = new Attachment();
        attachment.SetContent(str, filename);
      }

with filename="Invoice17/12/9813".
I have many received Gmail mails with attachment that have the '/' inside the filename with no issue. But using Rebex I have "Invalid character at position.." (parameter name).
I tried to change MimeOption to allow everything but still got the error. Any solution?
Thank you

Applies to: Rebex Secure Mail

1 Answer

+1 vote
answered Dec 14, 2017 by stepantalalayev (3,940 points)
selected Dec 14, 2017 by makertoo
 
Best answer

Hello,

the problem is that in many operation systems the '/' is recognized as directory separator, so the better practice is to omit such character. But if you really want to use it, there is a workaround:

using (Stream str = new MemoryStream(imap.MessageB))
{
    attachment.SetContent(str, "dummy");
    attachment.ContentType.Parameters["name"] = "invoice/17/12/9813";
    attachment.ContentDisposition.Parameters["filename"] = "invoice/17/12/9813";
}
...