XML : Confused about Content-Transfer-Encoding when emailing an XML file as an attachment

I have a UTF-8 encoded XML file which is emailed as an attachment. When the email recipient opens the email and saves the attachment, the XML file is no longer UTF-8 (it's instead reporting ANSI encoding).

Before emailing the XML file, after creating it on the server, I can see using the Linux file command that it's a UTF-8 file. Separate to this, the XML also has a version header <?xml version="1.0" encoding="UTF-8"?> (which isn't really relevant to my problem, but I'm including it for completeness). I'm pretty sure that my code which emails the file is the problem here, but I'm uncertain as to the "right" way to do this.

The headers I'm sending are:

  "Mime-Version" "1.0"  "Content-Type" "multipart/mixed; boundary="__==NAHDHDH2.28ABSDJxjhkjhsdkjhd___"\n\n"    

The body of the email is:

  --__==NAHDHDH2.28ABSDJxjhkjhsdkjhd___\n  Content-Type: text/plain; charset="utf-8"; format=flowed\n  Content-Transfer-Encoding: 7bit\n\n  Please find attached the data file generated   --__==NAHDHDH2.28ABSDJxjhkjhsdkjhd___\n  Content-Type: text/plain; charset="utf-8"\n  Content-Disposition: attachment; filename="My_File_Name"\n\n  XML FILE CONTENTS GO HERE  --__==NAHDHDH2.28ABSDJxjhkjhsdkjhd___--\n    

Questions:

  • should I be using quoted-printable, 8bit or other type of Content-Transfer-Encoding here? I have tried all of them, but it hasn't changed the result.
  • Is Content-Type: text/plain correct for an XML attachment?
  • Any other suggestions?

No comments:

Post a Comment