fork download
  1. from email.message import EmailMessage
  2.  
  3. msg = EmailMessage()
  4. msg['From'] = 'Nik@example.com'
  5. msg['To'] = 'Nathaniel@example.com'
  6. msg['Subject'] = 'Example of a message in Spanish and English'
  7. msg['Content-Disposition'] = 'inline' # redundant?
  8.  
  9. msg.set_content = """\
  10. This is a message in multiple languages. It says the
  11. same thing in each language. If you can read it in one language,
  12. you can ignore the other translations. The other translations may be
  13. presented as attachments or grouped together.
  14.  
  15. Este es un mensaje en varios idiomas. Dice lo mismo en
  16. cada idioma. Si puede leerlo en un idioma, puede ignorar las otras
  17. traducciones. Las otras traducciones pueden presentarse como archivos
  18. adjuntos o agrupados.
  19. """
  20.  
  21. suben = EmailMessage()
  22. suben['Content-Language'] = 'en-GB'
  23. suben['Content-Translation-Type'] = 'original'
  24. #suben['Content-Disposition'] = 'inline' # redundant?
  25. suben['Subject'] = 'Example of a message in Spanish and English'
  26. suben.set_content("Hello, this message content is provided in your language.")
  27. suben.add_header('Content-Language', 'en-GB')
  28. suben.add_header('Content-Disposition', 'inline')
  29.  
  30. subes = EmailMessage()
  31. subes['Content-Language'] = 'es-ES'
  32. subes['Content-Translation-Type'] = 'human'
  33. subes['Content-Disposition'] = 'inline' # redundant?
  34. subes['Subject'] = 'Ejemplo práctico de mensaje en español e inglés'
  35. subes.set_content("Hola, el contenido de este mensaje esta disponible en su idioma.")
  36. subes.add_header('Content-Language', 'es-ES')
  37. subes.add_header('Content-Disposition', 'inline')
  38.  
  39. msg.add_attachment(suben)
  40. msg.add_attachment(subes)
  41. msg.replace_header('Content-type', 'multipart/multilingual')
  42.  
  43. print(msg.as_string())
  44.  
Success #stdin #stdout 0.06s 18516KB
stdin
Standard input is empty
stdout
From: Nik@example.com
To: Nathaniel@example.com
Subject: Example of a message in Spanish and English
Content-Type: multipart/multilingual;
 boundary="===============0427525616482018382=="

--===============0427525616482018382==
Content-Disposition: inline


--===============0427525616482018382==
Content-Type: message/rfc822
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
Content-Disposition: attachment

Subject: Example of a message in Spanish and English
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Content-Language: en-GB
Content-Disposition: inline

Hello, this message content is provided in your language.

--===============0427525616482018382==
Content-Type: message/rfc822
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
Content-Disposition: attachment

Subject: Ejemplo =?utf-8?q?pr=C3=A1ctico_de_mensaje_en_espa=C3=B1ol_e_i?=
 =?utf-8?q?ngl=C3=A9s?=
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Content-Language: es-ES
Content-Disposition: inline

Hola, el contenido de este mensaje esta disponible en su idioma.

--===============0427525616482018382==--