亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

郵件分段/替代vs分段/混合

郵件分段/替代vs分段/混合

小唯快跑啊 2019-11-05 11:24:48
當創建的電子郵件,你都應該設置內容類型來multipart/alternative發送HTML和文本時,或multipart/mixed發送文本和附件時。如果要發送HTML,文本和附件,該怎么辦?同時使用?
查看完整描述

3 回答

?
蝴蝶刀刀

TA貢獻1801條經驗 獲得超8個贊

使用multipart/mixed與第一部分為multipart/alternative及以后的零件的附件。反過來,在零件內使用text/plaintext/html零件multipart/alternative

有能力的電子郵件客戶端應然后識別該multipart/alternative部分,并在必要時顯示文本部分或html部分。它還應將所有隨后的零件顯示為附件。

這里要注意的重要一點是,在多部分MIME消息中,部分內包含部分是完全有效的。從理論上講,嵌套可以擴展到任何深度。然后,任何具有合理能力的電子郵件客戶端都應該能夠遞歸處理所有消息部分。


查看完整回答
反對 回復 2019-11-05
?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

消息有內容。內容可以是文本,html,DataHandler或Multipart,并且只能有一個內容。多個零件只有身體零件,但可以有多個零件。像消息一樣,BodyParts可以包含已經描述的內容。


帶有HTML,文本和附件的消息可以按如下所示分層查看:


message

  mainMultipart (content for message, subType="mixed")

    ->htmlAndTextBodyPart (bodyPart1 for mainMultipart)

      ->htmlAndTextMultipart (content for htmlAndTextBodyPart, subType="alternative")

        ->textBodyPart (bodyPart2 for the htmlAndTextMultipart)

          ->text (content for textBodyPart)

        ->htmlBodyPart (bodyPart1 for htmlAndTextMultipart)

          ->html (content for htmlBodyPart)

    ->fileBodyPart1 (bodyPart2 for the mainMultipart)

      ->FileDataHandler (content for fileBodyPart1 )

以及構建此類消息的代碼:


    // the parent or main part if you will

    Multipart mainMultipart = new MimeMultipart("mixed");


    // this will hold text and html and tells the client there are 2 versions of the message (html and text). presumably text

    // being the alternative to html

    Multipart htmlAndTextMultipart = new MimeMultipart("alternative");


    // set text

    MimeBodyPart textBodyPart = new MimeBodyPart();

    textBodyPart.setText(text);

    htmlAndTextMultipart.addBodyPart(textBodyPart);


    // set html (set this last per rfc1341 which states last = best)

    MimeBodyPart htmlBodyPart = new MimeBodyPart();

    htmlBodyPart.setContent(html, "text/html; charset=utf-8");

    htmlAndTextMultipart.addBodyPart(htmlBodyPart);


    // stuff the multipart into a bodypart and add the bodyPart to the mainMultipart

    MimeBodyPart htmlAndTextBodyPart = new MimeBodyPart();

    htmlAndTextBodyPart.setContent(htmlAndTextMultipart);

    mainMultipart.addBodyPart(htmlAndTextBodyPart);


    // attach file body parts directly to the mainMultipart

    MimeBodyPart filePart = new MimeBodyPart();

    FileDataSource fds = new FileDataSource("/path/to/some/file.txt");

    filePart.setDataHandler(new DataHandler(fds));

    filePart.setFileName(fds.getName());

    mainMultipart.addBodyPart(filePart);


    // set message content

    message.setContent(mainMultipart);


查看完整回答
反對 回復 2019-11-05
  • 3 回答
  • 0 關注
  • 445 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號