none
Unable to specify MIME header 'Content-Description' using System.Net.Mail.Attachment class RRS feed

  • Question

  • Hello ,

    I have a piece of code which sends emails with attachments. I have a requirement that the attachment should have a 'Content-Description' header. This is how the header should look like:

    Content-Type: text/xml; name="278012389_14_0000411_01.xml"
    Content-Transfer-Encoding: 8bit
    Content-Dis; filename="278012389_14_0000411_01.xml"
    Content-Description: DALE-UV-Nutzdaten

    My code looks like this:

    foreach (EMailAttachment attachment in emailMessage.Attachments)
                       {
                           ContentType contentType = new ContentType();
                           contentType.Name = attachment.Filename;
                           contentType.MediaType = attachment.MediaType;
                           contentType.CharSet = attachment.Charset;                       
                           Attachment mailAttachment = new Attachment(new MemoryStream(attachment.Content),contentType);
                           
                           mailAttachment.TransferEncoding = TransferEncoding.SevenBit;                       
                           mailAttachment.ContentDisposition.DispositionType = DispositionTypeNames.Attachment;
                           mailAttachment.ContentDisposition.FileName = attachment.Filename;                       
                           
                           mailMessage.Attachments.Add(mailAttachment);
                       }

    There seems to be no property for specifying the Content-Description. It is a valid header according to the RFC https://www.ietf.org/rfc/rfc2045.txt (look topic no. 8 in the Table of Contents).

    Help is appreciated.


    Kazi

    Tuesday, June 30, 2015 6:38 AM

All replies

  • hi Kazi,
       As far as I know, "Content-Description" property is available in the header when it is in Multipart/Related like below :

    Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;
    
    for more information, Click here to refer about MultiPart in this article.
    Wednesday, July 1, 2015 2:43 AM
  • Hello

    Thanks for the answer. But I guess that's not the case. The Content-Description is a common header irrespective of the MIME type. The RFC link I have given defines it

    https://www.ietf.org/rfc/rfc2045.txt.

    This is the very first RFC document for MIME specification, out of the six RFC memoranda.


    Kazi

    Wednesday, July 1, 2015 4:38 AM
  • hi junaidkazi,
        As far as I know, your MIME header should be like below based on RFC2045 :

    MIME-Version: 1.0 Content-Type: text/xml; name="278012389_14_0000411_01.xml; Content-Transfer-Encoding: 7bit Content-Description: very simple MIME message Content-ID: <xxx@yyy.zzz> Content-Location: http://xxx.yyy/zzz.txt Content-Disposition : inline

    This is the body of the message.

    for more information, Click here to refer about the MIME Headers.

    Thursday, July 9, 2015 5:47 AM