Setting Content-Type for MimeMessage?

£可爱£侵袭症+ 提交于 2019-12-06 10:08:40

If I understand what you're trying to do, you want a message with this structure:

  multipart/mixed
    multipart/alternative
      text/plain - a plain text version of the main message body
      multipart/related
        text/html - the html version of the main message body
        image/jpeg - an image referenced by the main body
    application/octet-stream (or whatever) - the attachment

That means three nested multipart pieces. You'll need to specify the subtype for each multipart piece other than the default "mixed".

The multipart/mixed and multipart/alternative pieces are relatively straightforward. The multipart/related piece is more complicated and you might want to read RFC 2387 and/or find some other tutorials to help you with that.

You can simplify the structure by getting rid of the multipart/related and just having the html text reference an image somewhere on the internet.

You should also test that a message with this structure is going to be displayed properly by all the mail readers you care about. Some mail readers will do a better job than others with a complicated structure such as this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!