2017-12-04 7 views
0

HTMLを使用してメールコンテンツを準備しています(私はメールを送信するために春のMIMEメッセージを使用しています)。 HTMLは次のとおりです。Java - 連結を行うときに文字列の値が壊れています

<html><body><div><div style='margin-top: 0; margin-bottom: 0;'><font face='Times New Roman' size='3'>&nbsp;</font></div><div style='margin-top: 0; margin-bottom: 0;'><table width='100%' style='border-collapse: collapse; width: 100%;'><tbody><tr height='8' style='height: 8px;'><td style='width: 100%; padding: 0; border: 0 none black;'><table width='100%'style='border-collapse: collapse; width: 100%;'><tbody><tr height='8' style='height: 8px;'><td style='width: 100%; padding: 0; border: 0 none black;'><table width='600' align='center' style='border-collapse: collapse; width: 600px;><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border: 0 none black;'><table width='600' align='center'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600'style='width: 600px; padding: 0; border: 0 none black;'><table width='600' align='left'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0;border: 0 none black;'><table width='600' align='left'style='border-collapse:collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600'style='width:600px; padding:0; border: 0 none black;'><div align='center' style='text-align:center;'><a href='http://www.e-XXXXbank.com/'target='_blank'> <img src='cid:logo' 'align='top' alt='logo' style='display:inline;'></a></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center'<tbody><tr height='8' style='height: 8px;'><td width='600'style='width: 600px; padding: 0; border: 0 none black;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='560'style='width: 560px; padding: 0; border: 0 none black;'><table width='100%'style='border-collapse: collapse; width: 100%;'><tbody><tr height='8' style='height: 8px;'><td style='width: 100%; padding: 0; border: 0 none black;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='558'style='width: 558px; background-color: #F0F0F0; padding: 0; border: 1px solid #ECECED;'><span style='background-color: #F0F0F0;'><div align='center' style='text-align: center;'><font face='Arial' size='4' color='#104160'><b>XXXX Portfolio Confirmation</b></font></div></span></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border: 0 none black;'><img src='cid:space' align='top'alt='space' style='display: inline;'></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600'style='width: 600px; padding: 0; border: 0 none black;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='560'style='width: 560px; padding: 0; border: 0 none black;'><table width='550' align='right'style='border-collapse: collapse; width: 550px;'><tbody><tr height='8' style='height: 8px;'><td width='550'style='width: 550px; padding: 0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td width='550'style='width: 550px; padding: 0; border: 0 none black;'><table width='550' align='left'style='border-collapse: collapse; width: 550px;'><tbody><tr height='8' style='height: 8px;'><td colspan='2' width='550'style='width: 550px; padding: 0; border: 0 none black;'><font face='Arial' size='4' color='#C21212'><b>Dear Customer</b></font></td></tr><tr height='8' style='height: 8px;'><td colspan='2' width='550'style='width: 550px; padding: 0; border: 0 none black;'><font face='Arial' size='4' color='#104160'><br>Following your instructions we have created your XXXX. The document attached enable you to view the details of your portfolio. You can save, print and store it for your records.</font><font face='Arial' size='4' color='#104160'><br></font><font face='Arial' size='4' color='#104160'><br>For security reasons, the document is protected with a password that has been sent to your mobile by SMS.</font><font face='Arial' size='4' color='#104160'><br></font><font face='Arial' size='4' color='#104160'><br>Many thanks for trusting us to help you manage your finances.</font></td></tr><tr height='8' style='height: 8px;'><td width='510' style='width: 510px; padding: 0; border: 0 none black;'></td><td width='39' style='width: 39px; padding: 0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td colspan='2' width='550'style='width: 550px; padding: 0; border: 0 noneblack;'><font face='Arial' size='4' color='#C21212'><b>XXXX YYYYY Customer Service</b></font></td></tr><tr height='8' style='height: 8px;'><td width='510' valign='top'style='width: 510px; padding: 0; border: 0 none black;'><table width='510' align='left'style='border-collapse: collapse; width:510px;'><tbody><tr height='8' style='height: 8px;'><td width='510'style='width: 510px; padding:0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td width='510'style='width: 510px; padding:0; border: 0 none black;'><font face='Times New Roman' size='2'>&nbsp;</font> <div style='margin-top: 0;margin-bottom: 0;'><font face='Times New Roman' size='2'>&nbsp;</font></div><div style='margin-top: 0;margin-bottom: 0;'><font face='Times New Roman' size='2'>&nbsp;</font></div><div style='margin-top: 0;margin-bottom: 0;'><font face='Times New Roman' size='2'>&nbsp;</font></div><div style='margin-top: 0;margin-bottom: 0;'><font face='Arial' size='2'color='#104160'>Please add </font><a href='mailto:[email protected]'target='_blank'><font face='Arial'size='2'>[email protected]</font></a><font face='Arial' size='2'color='#104160'> to your email address book to ensure your statements are not redirected to the junk folder.If there are any questions, please contact directly with your XXXX Bank manager.</font></div></td></tr><tr height='8' style='height: 8px;'><td width='510' style='width: 510px; padding: 0; border: 0 none black;'></td></tr></tbody></table></td><td width='39' style='width: 39px; padding: 0; border: 0 none black;'></td></tr></tbody></table> </td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table> </td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center' style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border-width: 0 0 1px 0; border-style: none none solid none; border-color: black;'></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><table width='600' align='center' style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border: 0 none black;'></td></tr></tbody></table> <br></td></tr><tr height='8' style='height: 8px;'><td style='background-color: #F0F0F0; padding: 0; border: 0 none black;'><span style='background-color: #F0F0F0;'><table width='600' align='center' style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border-width: 1px 0 0 0; border-style: solid none none none; border-color: #E6E6E6;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='560' style='width: 560px; padding: 0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td width='560' style='width: 560px; padding: 0; border: 0 none black;'><table width='500' align='center' style='border-collapse: collapse; width: 500px;'><tbody><tr height='8' style='height: 8px;'><td width='300' style='width: 300px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><font face='Arial' size='2' color='#C21212'>© 2016 XXXX Bank. All rights reserved. </font><font face='Arial' size='2' color='#004080'>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; </font></div></td><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='https://XXX/XXXX?_rdr' target='_blank'><img src='cid:facebook' alt='facebook' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='http://XXXX.com/XXXX' target='_blank'><img src='cid:twitter' align='top' alt='twitter' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='http://XXXXX.com/XXXX' target='_blank'><img src='cid:Instagram' align='top'alt='Instagram' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='https://www.youtube.com/XXX/YYYY' target='_blank'><img src='cid:youtube' align='top' alt='youtube' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='https://www.linkedin.com/company/XXXX?trk=hb_tab_compy_id_202412' target='_blank'><img src='cid:linkedIn' align='top' alt='linkedIn' style='display:inline;'></a></div></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td width='560'style='width: 560px; padding: 0; border: 0 none black;'></td></tr></tbody></table> </td></tr></tbody></table></span></td</tr></tbody></table></div><div style='margin-top: 0; margin-bottom: 0;'><font face='Times New Roman' size='3'>&nbsp;</font></div><div style='margin-top: 0; margin-bottom: 0;'><img src='cid:tree' alt='http://XXXX/tree-small.jpg' style='display:inline;'><font face='Arial' size='1' color='green'>Please consider theenvironment &amp; Print only if necessary</font></div><hr></div></body></html> 

私は、文字列を使用してメールの内容を作成し、私はのhtmlText 1に連絡してhtmltext2は以下

<html><body><div><div style='margin-top: 0; margin-bottom: 0;'><font face='Times New Roman' size='3'>&nbsp;</font></div><div style='margin-top: 0; margin-bottom: 0;'><table width='100%' style='border-collapse: collapse; width: 100%;'><tbody><tr height='8' style='height: 8px;'><td style='width: 100%; padding: 0; border: 0 none black;'><table width='100%'style='border-collapse: collapse; width: 100%;'><tbody><tr height='8' style='height: 8px;'><td style='width: 100%; padding: 0; border: 0 none black;'><table width='600' align='center' style='border-collapse: collapse; width: 600px;><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border: 0 none black;'><table width='600' align='center'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600'style='width: 600px; padding: 0; border: 0 none black;'><table width='600' align='left'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0;border: 0 none black;'><table width='600' align='left'style='border-collapse:collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600'style='width:600px; padding:0; border: 0 none black;'><div align='center' style='text-align:center;'><a href='http://www.e-XXXXbank.com/'target='_blank'> <img src='cid:logo' 'align='top' alt='logo' style='display:inline;'></a></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center'<tbody><tr height='8' style='height: 8px;'><td width='600'style='width: 600px; padding: 0; border: 0 none black;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='560'style='width: 560px; padding: 0; border: 0 none black;'><table width='100%'style='border-collapse: collapse; width: 100%;'><tbody><tr height='8' style='height: 8px;'><td style='width: 100%; padding: 0; border: 0 none black;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='558'style='width: 558px; background-color: #F0F0F0; padding: 0; border: 1px solid #ECECED;'><span style='background-color: #F0F0F0;'><div align='center' style='text-align: center;'><font face='Arial' size='4' color='#104160'><b>XXXX Portfolio Confirmation</b></font></div></span></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border: 0 none black;'><img src='cid:space' align='top'alt='space' style='display: inline;'></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center'style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600'style='width: 600px; padding: 0; border: 0 none black;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='560'style='width: 560px; padding: 0; border: 0 none black;'><table width='550' align='right'style='border-collapse: collapse; width: 550px;'><tbody><tr height='8' style='height: 8px;'><td width='550'style='width: 550px; padding: 0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td width='550'style='width: 550px; padding: 0; border: 0 none black;'><table width='550' align='left'style='border-collapse: collapse; width: 550px;'><tbody><tr height='8' style='height: 8px;'><td colspan='2' width='550'style='width: 550px; padding: 0; border: 0 none black;'><font face='Arial' size='4' color='#C21212'><b>Dear Customer</b></font></td></tr><tr height='8' style='height: 8px;'><td colspan='2' width='550'style='width: 550px; padding: 0; border: 0 none black;'><font face='Arial' size='4' color='#104160'><br>Following your instructions we have created your XXXX. The document attached enable you to view the details of your portfolio. You can save, print and store it for your records.</font><font face='Arial' size='4' color='#104160'><br></font><font face='Arial' size='4' color='#104160'><br>For security reasons, the document is protected with a password that has been sent to your mobile by SMS.</font><font face='Arial' size='4' color='#104160'><br></font><font face='Arial' size='4' color='#104160'><br>Many thanks for trusting us to help you manage your finances.</font></td></tr><tr height='8' style='height: 8px;'><td width='510' style='width: 510px; padding: 0; border: 0 none black;'></td><td width='39' style='width: 39px; padding: 0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td colspan='2' width='550'style='width: 550px; padding: 0; border: 0 noneblack;'><font face='Arial' size='4' color='#C21212'><b>XXXX YYYYY Customer Service</b></font></td></tr><tr height='8' style='height: 8px;'><td width='510' valign='top'style='width: 510px; padding: 0; border: 0 none black;'><table width='510' align='left'style='border-collapse: collapse; width:510px;'><tbody><tr height='8' style='height: 8px;'><td width='510'style='width: 510px; padding:0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td width='510'style='width: 510px; padding:0; border: 0 none black;'><font face='Times New Roman' size='2'>&nbsp;</font> <div style='margin-top: 0;margin-bottom: 0;'><font face='Times New Roman' size='2'>&nbsp;</font></div><div style='margin-top: 0;margin-bottom: 0;'><font face='Times New Roman' size='2'>&nbsp;</font></div><div style='margin-top: 0;margin-bottom: 0;'><font face='Times New Roman' size='2'>&nbsp;</font></div><div style='margin-top: 0;margin-bottom: 0;'><font face='Arial' size='2'color='#104160'>Please add </font><a href='mailto:[email protected]'target='_blank'><font face='Arial'size='2'>[email protected]</font></a><font face='Arial' size='2'color='#104160'> to your email address book to ensure your statements are not redirected to the junk folder.If there are any questions, please contact directly with your XXXX Bank manager.</font></div></td></tr><tr height='8' style='height: 8px;'><td width='510' style='width: 510px; padding: 0; border: 0 none black;'></td></tr></tbody></table></td><td width='39' style='width: 39px; padding: 0; border: 0 none black;'></td></tr></tbody></table> </td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table> </td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><br><table width='600' align='center' style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border-width: 0 0 1px 0; border-style: none none solid none; border-color: black;'></td></tr></tbody></table></td></tr><tr height='8' style='height: 8px;'><td style='padding: 0; border: 0 none black;'><table width='600' align='center' style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border: 0 none black;'></td></tr></tbody></table> <br></td></tr><tr height='8' style='height: 8px;'><td style='background-color: #F0F0F0; padding: 0; border: 0 none black;'><span style='background-color: #F0F0F0;'><table width='600' align='center' style='border-collapse: collapse; width: 600px;'><tbody><tr height='8' style='height: 8px;'><td width='600' style='width: 600px; padding: 0; border-width: 1px 0 0 0; border-style: solid none none none; border-color: #E6E6E6;'><table width='560' align='center'style='border-collapse: collapse; width: 560px;'><tbody><tr height='8' style='height: 8px;'><td width='560' style='width: 560px; padding: 0; border: 0 none black;'></td></tr><tr height='8' style='height: 8px;'><td width='560' style='width: 560px; padding: 0; border: 0 none black;'><table width='500' align='center' style='border-collapse: collapse; width: 500px;'><tbody><tr height='8' style='height: 8px;'><td width='300' style='width: 300px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><font face='Arial' size='2' color='#C21212'>© 2016 XXXX Bank. All rights reserved. </font><font face='Arial' size='2' color='#004080'>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; </font></div></td><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='https://XXX/XXXX?_rdr' target='_blank'><img src='cid:facebook' alt='facebook' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='http://XXXX.com/XXXX' target='_blank'><img src='cid:twitter' align='top' alt='twitter' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='http://XXXXX.com/XXXX' target='_blank'><img src='cid:Instagram' align='top'alt='Instagram' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='https://www.youtube.com/XXX/YYYY' target='_blank'><img src='cid:youtube' align='top' alt='youtube' style='display:inline;'></a><td width='30' style='width: 30px; padding: 0; border: 0 none black;'><div align='center' style='text-align: center;'><a href='htt..... 
を結果に終わるのですときCID

String htmltext1=mailContentStart.concat(mailContentLogo).concat(mailContentHeading). 
       concat(mailContentSpace).concat(mailContentBody); 
     String htmltext12=(mailContentImages).concat(mailEnd); 

を使用して画像が埋め込まれています

誰も同じ問題を解決することを提案できますか?このため、私のHTMLはMAILで正しくレンダリングされません。

+0

あなたが直面している問題を記述してください。 – shmosel

+0

Btw、 'concat'をチェーン化するのは非常に効率が悪いです。代わりに、 '+'演算子または 'StringBuilder'を使用してください。 – shmosel

答えて

0

ここでは、concatの代わりにStringBuilderを使用することをお勧めします。 そうでなければ、concatの代わりに+オペレータをここで単純に使用してください。

concat()メソッドは文字列値のみを受け入れ、+演算子は暗黙的に引数をStringに変換します(オブジェクトのtoString()メソッドを使用)。したがって、concat()メソッドは受け入れられるものがより厳密です。あなたはこのスニペットを使用してコード内の上記2行を置き換えることができます

のStringBuilderを使用するには:

StringBuilder html = new StringBuilder(); 
html.append(mailContentStart) 
     .append(mailContentLogo) 
     .append(mailContentHeading) 
     .append(mailContentSpace) 
     .append(mailContentBody) 
     .append(mailContentImages) 
     .append(mailEnd); 

そして、あなたは、このことによって、このStringBuilderのの文字列値を返すことができます

return html.toString(); 
+0

私は説明通りに変更しました。それでも問題は終了します:( –

+0

ありがとう..私はそれを働いて.. StringBuilderで:) –

+0

完璧なおかげで! –

0

StringBuilderを使用して、電子メールの作成時にコンテンツを追加します.FullstionがStringを受け取る場合は、StringBuilderにtoString()を渡します。

0

あなたのhtmlに「行方不明があります:

<table width='600' align='center' style='border-collapse: collapse; width: 600px;> 
+0

タグが動作しているところはどこでも変更しました..まだ同じです.. :( –

関連する問題