0

I want to send an email which contains only an attached file, no text or anything else.

Why should i represent this as one bodypart of a multipart email?
Why i can't just write

message.setFileName(filepath);

When in the other hand this works

message.setText("blablabla");
Ricardo Vila
  • 1,529
  • 1
  • 16
  • 33
John
  • 81
  • 1
  • 12
  • Because a mail must have a body part – Jens Aug 25 '16 at 07:52
  • It's not because of java email API. It's because SMTP protocol. Check this http://stackoverflow.com/questions/3902455/smtp-multipart-alternative-vs-multipart-mixed – Ricardo Vila Aug 25 '16 at 07:55
  • Jens, @RicardoVila You're not correct. SMTP e-mails support messages that have a non-text type as their direct body, without the use of multipart. Check the RFC: https://www.ietf.org/rfc/rfc2045.txt – Erwin Bolwidt Aug 25 '16 at 08:03

1 Answers1

1

Because this is the MIME standards, all email messages should follow the MIME RFC in order for email clients to properly display the email. An attached image is binary data, while a message body is always ASCII, a user cannot open an email with binary in the body displayd, that would be useless. The binary code of the image is translated to BASE64 so the binary can be transfered in sort of ASCII characters and this has to sit in an email MIME boundary. The email software knows how to find these boundaries and will either show the image to the user as an attachment, or displayed the right way in the body, depending on how you setup your MIME boundaries. Multipart means the email has multiple boundaries, where the ASCII email body is one of them, no matter if that one is blanc or not.

Saskia
  • 234
  • 3
  • 10
  • Read https://www.ietf.org/rfc/rfc2045.txt - message bodies containing an attachment rather than text are supported. Yes they must be encoded (in base64 or quoted-printable for example) but they don't need to be in a multipart. If you believe otherwise, please provide a reference. – Erwin Bolwidt Aug 25 '16 at 08:05