1

JavaMail で作成されたメッセージにインラインで表示される画像が、Apple Mail では 2 回表示されますが、Outlook では表示されませんか?

EmailMaster は、以下を含むテスト電子メール メッセージを送信します。1) メッセージが開かれたときにタイトルにインラインで表示される電子メールと共に送信された画像 2) メッセージが表示された後にリモート URL からダウンロードする必要がある画像へのリンク.

目標は、メッセージが開かれたときにメッセージが完全にレンダリングされることです (フクロウ)。完全なメッセージを表示する前にリーダーがダウンロードする必要はありません。

以下のコードは、メッセージが Outlook などのクライアントで開かれたときに完全に機能します。-- フクロウの画像を開いたときに行に表示されます。 -- 下線はダウンロードする必要があります。

AppleMail がメッセージを開くと、フクロウが 2 回表示されます。画面には次のように表示されます。 -- フクロウがスタンドアロンの画像として表示されます。 -- 次に、タイトルにフクロウが正しく表示されたメッセージが表示されます。

スクリーンショットを投稿することはできませんが、AppleMail 画面のスクリーンショットを http://america-3.org/images/shot.jpgに掲載します。

誰でも問題の原因を指摘できますか? それとも解決策?

1 つの MimeBodyPart として追加された HTML コード。

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="cid:fonts" rel="stylesheet" type="text/css" />
    <style type="text/css"> 
    <!--
      .text-blue-12 {font-family: Verdana, Arial, Helvetica, sans-serif;
                     text-decoration: none; font-weight: normal; 
                     font-size:12pt; color: #0F0F0F}
       body { margin: 0; padding: 0; background-color: #1A4576; width: 480px;} 
       tr {width:100%;  background-color: white;}
     --> 
     </style>     
  </head>
  <body>
      <table width='480px' cellspacing='0' cellpadding='6' class='text-blue-12' align="center">
        <tr><td style='text-align: center;'>
            Hello! <img src='cid:owl'>
        </td></tr>
        <tr><td style='text-align: center;'>
          <img align="center" alt="Shadow" class="kmImage"
               src="https://d3k81ch9hvuctc.cloudfront.net/assets/email/bottom_shadow_444.png"
               width="600" style="border: 0; height: auto; line-height: 100%;
               outline:none; text-decoration: none; max-width: 100%; padding-bottom: 0; 
               display: inline; vertical-align: bottom" />
        </td></tr>
        <tr><td>
          This is test # 1005.  The Table should be a 480px wide and centered.
          If not there is a problem.
        </td></tr>
      <tr><td>
        Yours truly,
        GLB
      </td></tr>
    </table>
  </body>
</html>

JavaMail コードのテストに使用する Java クラスの抜粋

public class EmailMaster {
  /* JavaMail attempts to use IPv6 to  connect. Windows IPv4.  
   * The error message will be "Network Unreachable: Connect.
   * To fix it, I ran this code from the command window 
   * setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true
   * I tried to set _JAVA_OPTIONS as an environment variable but that didn't
   * work.
   */

/* the constructor instantiates EmailMaster. 
 * It parses a ".properties" text file that provides the everything 
 * needed to define a message:
 * -- send from, reply to, subject etc. Strings
 * -- local paths to one or more files:
 *      .. a text file containing the to addresses.
 *      .. the HTML file that holds the message body,
 *      .. one of more images to be displayed inline
 *         in the HTML message body.  I used one.
 *      .. one or more files to be attached to the msg. I used one.
 */ 

/* then it calls sendEmail() to read through the list of addresses 
 * and sends an individual email to each address*/

sendEmail () {
  /*this section of code is done once. */
  Session session = Session.getInstance(this.sessionParameters);
  SMTPTransport tr = new SMTPTransport(session, new URLName (host));
  tr.connect(...); // this is successful

  /* the method loops through this section for every to address provided*/
  Message msg = new MimeMessage(session);
  msg.setReplyTo(this.replyToAddress);// read from properties file
  msg.setSentDate(new java.util.Date());// read from properties file
  msg.setSubject(this.subject);// read from properties file
  msg.setFrom(this.fromAddress);// read from properties file
  msg.setRecipient(RecipientType.TO, singleToAddress);// read from properties file

  MimeMultipart mmp = new MimeMultipart();

  /* add a MimeBodyPart for each image be displayed inline the HTML text */
  for (MimeBodyPart part : this.imagesBodyParts.values()) {
    mmp.addBodyPart(part);
    /* add a MimeBodyPart for each HTML page in the message. */
    for (MimeBodyPart part : this.attachmentBodyParts.values()) {
      mmp.addBodyPart(part);
    }
    mmp.addBodyPart(this.msgPart);
    msg.setContent(mmp);
    msg.saveChanges();
    tr.sendMessage(msg, msg.getAllRecipients());
  }
}
4

1 に答える 1

0

メール リーダーがメッセージを表示する方法を制御できる範囲には制限があります。最終的に、すべてのメール リーダーでやろうとしていることを達成できない可能性があります。とはいえ、投稿したコードにはいくつかの問題があります...

最初に画像の本文部分を追加し、次に一連の添付ファイル (html?) 本文部分を追加し、メッセージを送信し、両方を同じメッセージに追加してから、メッセージを再度送信するなど。確かにこれはあなたが意図したものではありません。

メッセージに単一の html パーツと、html パーツによって参照されるいくつかの画像パーツを含める場合は、マルチパート/関連メッセージを作成する必要があり、画像パーツには Content-ID ヘッダーが必要です。 この JavaMail FAQ エントリは、正しい方向を示しています。

最後に、SMTPTransport のコンストラクターを直接呼び出してはいけません。代わりに、Session.getTransport メソッドを使用する必要があります。

于 2013-09-03T18:16:45.093 に答える