java - How to add a MimeMultipart to another one? -
this possibly stupid question, i'm trying compose email message suggested here
- multipart/mixed
- multipart/alternative
- text/html
- text/plain
- attachment 1
- attachment 2
- multipart/alternative
so i'm having
mimemultipart altpart = new mimemultipart("alternative"); bodypart textpart = new mimebodypart(); textpart.setcontent("sometext", "text/plain"); altpart.addbodypart(textpart); bodypart htmlpart = new mimebodypart(); htmlpart.setcontent("somehtml", "text/html"); altpart.addbodypart(htmlpart); mimemultipart mixedpart = new mimemultipart("multipart/mixed");
and need add altpart
mixedpart
, can't adding method accepts bodypart
only. wtf?
note unlike here, i'm not mixing packages.
you need wrap mimemultipart
in mimebodypart
, using mimebodypart.setcontent(multipart mp)
method. can add mimebodypart
mixedpart
object:
mimemultipart alternativemultipart = new mimemultipart("alternative"); bodypart textpart = new mimebodypart(); textpart.setcontent("sometext", "text/plain"); alternativemultipart.addbodypart(textpart); bodypart htmlpart = new mimebodypart(); htmlpart.setcontent("somehtml", "text/html"); alternativemultipart.addbodypart(htmlpart); mimebodypart alternativebodypart = new mimebodypart(); alternativebodypart.setcontent(alternativemultipart); mimemultipart mixedmultipart = new mimemultipart("mixed"); mixedmultipart.addbodypart(alternativebodypart); mimebodypart textpart1 = new mimebodypart(); textpart1.setcontent("someothertext", "text/plain"); mixedmultipart.addbodypart(textpart1);