{"id":11240,"date":"2023-05-29T12:21:26","date_gmt":"2023-05-29T04:21:26","guid":{"rendered":"http:\/\/123.57.164.21\/?p=11240"},"modified":"2023-05-29T12:22:25","modified_gmt":"2023-05-29T04:22:25","slug":"javamail%e7%9a%84%e4%bd%bf%e7%94%a8%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11240","title":{"rendered":"JavaMail\u7684\u4f7f\u7528\u8be6\u89e3"},"content":{"rendered":"\n<p><strong>maven\u5f15\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;dependency>\n            &lt;groupId>com.sun.mail&lt;\/groupId>\n            &lt;artifactId>javax.mail&lt;\/artifactId>\n            &lt;version>1.6.2&lt;\/version>\n&lt;\/dependency>\n<\/pre>\n\n\n\n<p><strong>JavaMail\u90ae\u4ef6\u683c\u5f0f\u4ecb\u7ecd<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5982\u679c\u60f3\u4e86\u89e3\u90ae\u4ef6\u5982\u4f55\u53d1\u9001\uff0c\u6211\u4eec\u5fc5\u987b\u4e86\u89e3\u90ae\u4ef6\u6d88\u606f\u7684\u6b63\u6587\u7ed3\u6784<br>\u6211\u4eec\u5148\u4e86\u89e3\u4e00\u4e0b\u53d1\u90ae\u4ef6\u65f6\u7684\u6d41\u7a0b:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\u521b\u5efa\u6d88\u606f\u5bf9\u8c61\nMimeMessage message = new MimeMessage(session);\n\/\/\u521b\u5efa\u6d88\u606f\u6b63\u6587\nMimeMultipart mimmultiPart = new MimeMultipart();\n\/\/\u521b\u5efa\u6d88\u606f\u4f53\nMimeBodyPart mimeBodyPart = new MimeBodyPart();\n\/\/\u5c06\u6d88\u606f\u4f53\u5305\u88f9\u5728\u6b63\u6587\u4e2d\nmimmultiPart.addBodyPart(mimeBodyPart);\n\/\/\u5c06\u6b63\u6587\u5305\u88f9\u5728\u6d88\u606f\u5bf9\u8c61\u4e2d\nmessage.setContent(mimmultiPart )\n\/\/\u53d1\u90ae\u4ef6\u534f\u8bae\u662fsmtp  \u6536\u90ae\u4ef6\u534f\u8bae\u662fimap\nTransport transport = session.getTransport(\"smtp\");\n\/\/\u53d1\u9001\u90ae\u4ef6\ntransport.sendMessage(mimeMessage,\"\u67d0\u6536\u4ef6\u4eba\");<\/pre>\n\n\n\n<p>MimeMessage \u5305\u542b\u4e86 MimeMultipart\uff0c<br>MimeMultipart \u5305\u542b\u4e86 MimeBodyPart<br>\u8fd9\u91cc\u9762\u6bd4\u8f83\u7edd\u5999\u7684\u5c31\u662f<br>MimeBodyPart \u5176\u5b9e\u53cd\u8fc7\u6765\u4e5f\u53ef\u4ee5\u5305\u542bMimeMultipart \u540e\u9762\u6211\u4eec\u5c06\u770b\u5230<\/p>\n\n\n\n<p><br><strong>MIMEMultipart\u7c7b\u578b<\/strong><\/p>\n\n\n\n<p>MIME\u90ae\u4ef6\u4e2d\u5404\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u5185\u5bb9\u662f\u5206\u6bb5\u5b58\u50a8\u7684\uff0c\u5404\u4e2a\u6bb5\u7684\u6392\u5217\u65b9\u5f0f\u3001\u4f4d\u7f6e\u4fe1\u606f\u90fd\u901a\u8fc7Content-Type\u57df\u7684multipart\u7c7b\u578b\u6765\u5b9a\u4e49\u3002multipart\u7c7b\u578b\u4e3b\u8981\u6709\u4e09\u79cd\u5b50\u7c7b\u578b\uff1amixed\u3001alternative\u3001related\u3002<br>MIMEMultipart\u7c7b\u578b\u57fa\u672c\u683c\u5f0f<br>\u25cf MIMEMultipart\uff08\u2018mixed\u2019\uff09\u7c7b\u578b<br>\u5982\u679c\u4e00\u5c01\u90ae\u4ef6\u4e2d\u542b\u6709\u9644\u4ef6\uff0c\u90a3\u90ae\u4ef6\u7684\u4e2d\u5fc5\u987b\u5b9a\u4e49multipart\/mixed\u7c7b\u578b\uff0c\u90ae\u4ef6\u901a\u8fc7multipart\/mixed\u7c7b\u578b\u4e2d\u5b9a\u4e49\u7684boundary\u6807\u8bc6\u5c06\u9644\u4ef6\u5185\u5bb9\u540c\u90ae\u4ef6\u5176\u5b83\u5185\u5bb9\u5206\u6210\u4e0d\u540c\u7684\u6bb5\u3002\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<br>msg=MIMEMultipart(\u2018mixed\u2019)<\/p>\n\n\n\n<p>\u25cf MIMEMultipart(\u2018alternative\u2019)\u7c7b\u578b<br>MIME\u90ae\u4ef6\u53ef\u4ee5\u4f20\u9001\u8d85\u6587\u672c\u5185\u5bb9\uff0c\u4f46\u51fa\u4e8e\u517c\u5bb9\u6027\u7684\u8003\u8651\uff0c\u4e00\u822c\u5728\u53d1\u9001\u8d85\u6587\u672c\u683c\u5f0f\u5185\u5bb9\u7684\u540c\u65f6\u4f1a\u540c\u65f6\u53d1\u9001\u4e00\u4e2a\u7eaf\u6587\u672c\u5185\u5bb9\u7684\u526f\u672c\uff0c\u5982\u679c\u90ae\u4ef6\u4e2d\u540c\u65f6\u5b58\u5728\u7eaf\u6587\u672c\u548c\u8d85\u6587\u672c\u5185\u5bb9\uff0c\u5219\u90ae\u4ef6\u9700\u8981\u5728Content-Type\u57df\u4e2d\u5b9a\u4e49multipart\/alternative\u7c7b\u578b\uff0c\u90ae\u4ef6\u901a\u8fc7\u5176boundary\u4e2d\u7684\u5206\u6bb5\u6807\u8bc6\u5c06\u7eaf\u6587\u672c\u3001\u8d85\u6587\u672c\u548c\u90ae\u4ef6\u7684\u5176\u5b83\u5185\u5bb9\u5206\u6210\u4e0d\u540c\u7684\u6bb5\u3002\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<br>msg=MIMEMultipart(\u2018alternative\u2019)<\/p>\n\n\n\n<p>\u25cf MIMEMultipart(\u2018related\u2019)\u7c7b\u578b<br>MIME\u90ae\u4ef6\u4e2d\u9664\u4e86\u53ef\u4ee5\u643a\u5e26\u5404\u79cd\u9644\u4ef6\u5916\uff0c\u8fd8\u53ef\u4ee5\u5c06\u5176\u5b83\u5185\u5bb9\u4ee5\u5185\u5d4c\u8d44\u6e90\u7684\u65b9\u5f0f\u5b58\u50a8\u5728\u90ae\u4ef6\u4e2d\u3002\u6bd4\u5982\u6211\u4eec\u5728\u53d1\u9001html\u683c\u5f0f\u7684\u90ae\u4ef6\u5185\u5bb9\u65f6\uff0c\u53ef\u80fd\u4f7f\u7528\u56fe\u50cf\u4f5c\u4e3a html\u7684\u80cc\u666f\uff0chtml\u6587\u672c\u4f1a\u88ab\u5b58\u50a8\u5728alternative\u6bb5\u4e2d\uff0c\u800c\u4f5c\u4e3a\u80cc\u666f\u7684\u56fe\u50cf\u5219\u4f1a\u5b58\u50a8\u5728multipart\/related\u7c7b\u578b\u5b9a\u4e49\u7684\u6bb5\u4e2d\u3002\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<br>msg=MIMEMultipart(\u2018related\u2019)<\/p>\n\n\n\n<p>\u4ee5\u4e0b4\u79cd\u683c\u5f0f\u5747\u4e3a\u7b14\u8005\u901a\u8fc7FoxMail\u53d1\u9001\u90ae\u4ef6\uff0c\u5e76\u901a\u8fc7JavaMail\u53bb\u627e\u90ae\u4ef6\u800c\u6765\u7684\u7ed3\u679c<\/p>\n\n\n\n<p><strong>\u2460\u7eaf\u6587\u672c<\/strong><\/p>\n\n\n\n<p>\u90ae\u4ef6\u6b63\u6587\u4ec5\u5e26\u6709\u6587\u672c\u6587\u5b57<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"ALTERNATIVE\")\n          MimeBodyPart0(\"TEXT\/PLAIN\")\n          MimeBodyPart1(\"TEXT\/HTML\")\n<\/pre>\n\n\n\n<p>\u53d1\u90ae\u4ef6\u65f6\uff0c\u5c3d\u7ba1\u662f\u6700\u7b80\u5355\u7684\u6587\u672c\uff0c\u4e5f\u662f\u4e00\u4e2aMimeMutiPart\u5305\u542b\u4e86\u4e24\u4e2aMimeBodyPart\uff0c\u4e00\u4e2a\u5bf9\u5e94\u7eaf\u6587\u672c\uff0c\u53e6\u4e00\u4e2a\u5bf9\u5e94html<\/p>\n\n\n\n<p><strong>\u2461\u7eaf\u6587\u672c\u5e26\u9644\u4ef6<\/strong><\/p>\n\n\n\n<p>\u90ae\u4ef6\u6b63\u6587\u5305\u542b\u6587\u672c\u6587\u5b57+\u9644\u4ef6<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"MIXED\")\n|------MimeBodyPart0 ---- MimeMutiPart(\"ALTERNATIVE\")\n|            MimeBodyPart0(\"TEXT\/PLAIN\")\n|            MimeBodyPart1(\"TEXT\/HTML\")\n|------MimeBodyPart1 (\"\"APPLICATION\/OCTET-STREAM\")\n<\/pre>\n\n\n\n<p>\u6587\u672c\u7684\u5185\u5bb9\u4ecd\u7136\u662f\u4e00\u4e2aMutiPart\u5305\u542b\u4e86\u4e24\u4e2aBodyPart \u53ea\u4e0d\u8fc7\u6b64\u90e8\u5206\u88ab\u5305\u542b\u8fdb\u4e86MimeBodyPart0<br>\u9644\u4ef6\u7684\u90e8\u5206\u662f\u4e00\u4e2a\u72ec\u7acb\u7684MimeBodyPart1<\/p>\n\n\n\n<p><strong>\u2462\u5bcc\u6587\u672c<\/strong><\/p>\n\n\n\n<p>\u90ae\u4ef6\u6b63\u6587\u5305\u542b\u5bcc\u6587\u672c\u6587\u5b57<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"RELATED\")\n|------MimeBodyPart0 ---- MimeMutiPart(\"ALTERNATIVE\")\n|            MimeBodyPart0(\"TEXT\/PLAIN\")\n|            MimeBodyPart1(\"TEXT\/HTML\")\n|------MimeBodyPart1(\"IMAGE\/GIF\")\n|------MimeBodyPart2(\"IMAGE\/GIF\")\n|------MimeBodyPart3(\"IMAGE\/GIF\")\n<\/pre>\n\n\n\n<p>\u6587\u672c\u7684\u5185\u5bb9\u8fd8\u662f\u76f8\u540c\u7684,\u4e00\u4e2aMutiPart\u5305\u542b\u4e86\u4e24\u4e2aBodyPart \u6b64MutiPart\u88ab\u5305\u542b\u8fdb\u4e86\uff0cMimeBodyPart0<br>MimeBodyPart1\u3001MimeBodyPart2\u3001MimeBodyPart3\u5c5e\u4e8e&#8221;INLINE&#8221;\u7684\u9644\u4ef6\uff0c\u800c\u975eattach\u7684\u9644\u4ef6\u5c5e\u4e8e\u5bcc\u6587\u672c\u4e2d\u7684\u56fe\u7247\u548c\u8868\u60c5\u7b49\u8d44\u6e90<\/p>\n\n\n\n<p><strong>\u2463\u5bcc\u6587\u672c\u5e26\u9644\u4ef6<\/strong><\/p>\n\n\n\n<p>\u90ae\u4ef6\u6b63\u6587\u5305\u542b\u5bcc\u6587\u672c\u6587\u5b57+\u9644\u4ef6<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"MIXED\")\n|------MimeBodyPart0 ---- MimeMutiPart(\"RELATED\")\n|            MimeBodyPart0 ---- MimeMutiPart(\"ALTERNATIVE\")\n|                 MimeBodyPart0(\"TEXT\/PLAIN\")\n|                 MimeBodyPart1(\"TEXT\/HTML\")\n|            MimeBodyPart1(\"IMAGE\/GIF\")\n|            MimeBodyPart2(\"IMAGE\/GIF\")\n|            MimeBodyPart3(\"IMAGE\/GIF\")\n|------MimeBodyPart1 (\"APPLICATION\/OCTET-STREAM\")\n|------MimeBodyPart2 (\"APPLICATION\/OCTET-STREAM\")\n|------MimeBodyPart3 (\"APPLICATION\/OCTET-STREAM\")<\/pre>\n\n\n\n<p>\u8fd9\u662f\u6700\u590d\u6742\u7684\u4e00\u79cd\uff0c\u4e5f\u662f\u53ef\u4ee5\u57fa\u672c\u6ee1\u8db3\u6211\u4eec\u65e5\u5e38\u9700\u6c42\u7684\u4e00\u79cd\uff0c\u6700\u91cc\u9762\u7684\u4e00\u5c42\u8fd8\u662fALTERNATIVE\u7684MutiPart\u5305\u542b\u4e86\u4e24\u4e2a\u6587\u672c\u7c7b\u578b\uff0c\u540c\u5c42\u7ea7\u5305\u542b\u7740&#8221;INLINE&#8221;\u7684\u9644\u4ef6<br>\u6700\u5916\u5c42\u662f\u4e00\u4e9b\u771f\u6b63\u7684\u9644\u4ef6<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u56db\u79cd\u7c7b\u578b\u57fa\u672c\u4e0a\u6db5\u76d6\u4e86\u6211\u4eec\u65e5\u5e38\u4f7f\u7528\u7684\u683c\u5f0f\uff0c\u4e0d\u96be\u53d1\u73b0MimeMutiPart\u4e00\u5171\u6709\u4e09\u79cd\u7c7b\u578b:<\/p>\n\n\n\n<ul><li>1.MIXED:\u5305\u542b\u9644\u4ef6\u7684\u6587\u6863<\/li><li>2.ALTERNATIVE: \u5305\u542btext\u6587\u6863\u548chtml\u6587\u6863\uff0c\u4e3a\u4ec0\u4e48\u662f\u4e24\u79cd \u4e00\u822c\u90ae\u7bb1\u5ba2\u6237\u7aef\u6bd4\u5982FoxMail \u53ef\u4ee5\u5207\u6362\u9605\u8bfb\u6a21\u5f0f, \u4e00\u4e2a\u662f\u8d85\u6587\u672c\u9605\u8bfb\u683c\u5f0f \u5bf9\u5e94html, \u4e00\u4e2a\u662f\u7eaf\u6587\u672c(\u53bb\u6389\u6587\u4e2d\u56fe\u7247\u548c\u8868\u60c5)\u683c\u5f0f \u5bf9\u5e94text<\/li><li>3.RELATED:\u56fe\u6587(\u5bcc\u6587\u672c)<\/li><\/ul>\n\n\n\n<p>\u6211\u4eec\u5728\u4f7f\u5f97\u7684\u65f6\u5019\u5982\u679c\u4e0d\u77e5\u9053\u4f7f\u7528\u54ea\u4e00\u4e2a\uff0c\u76f4\u63a5\u4f7f\u7528mixed\u5373\u53ef\uff0c\u4f7f\u7528\u8fd9\u4e2a\u5c5e\u6027\u503c\u4e00\u5b9a\u4e0d\u4f1a\u62a5\u9519<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-25-1024x492.png\" alt=\"\" class=\"wp-image-11242\" width=\"555\" height=\"266\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-1024x492.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-300x144.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-768x369.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-830x399.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-230x111.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-350x168.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25-480x231.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-25.png 1452w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u53d1\u9001\u90ae\u4ef6\u4ee3\u7801\u6837\u4f8b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u9996\u5148\uff0c\u90ae\u7bb1\u670d\u52a1\u90fd\u662f\u57fa\u4e8eSession\u4f1a\u8bdd\u5f00\u59cb\uff0c\u9996\u5148\u6211\u4eec\u6784\u5efa\u4e00\u4e2aSession<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public final static String SSL_FACTORY = \"javax.net.ssl.SSLSocketFactory\";\npublic final static String DEFAULT_FACTORY = \"javax.net.DefaultSocketFactory\";\npublic static Session generSession(Dto_MainForward dto_mainForward,MailServers mailinfo) throws NoSuchProviderException, GeneralSecurityException {\n        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());\n        MailSSLSocketFactory socketFactory= new MailSSLSocketFactory();\n        socketFactory.setTrustAllHosts(true);\n        Properties props = System.getProperties();\n        props.put(\"mail.imaps.ssl.socketFactory\", socketFactory);\n        \/\/\u6b64\u5904\u89c4\u5b9a\u8fde\u63a5\u90ae\u7bb1\u7684\u65b9\u5f0f\u662fhttps\u8fd8\u662fhttp \u9ed8\u8ba4\u4e00\u79cd\u5373\u53ef\n        props.setProperty(\"mail.imap.socketFactory.class\", mailinfo.getSslable() ? SSL_FACTORY : DEFAULT_FACTORY);\n        \/\/\u5bf9\u5e94\u90ae\u7bb1\u670d\u52a1\u5668\u7684\u7aef\u53e3 ssl\u5bf9\u5e94465 \u666e\u901a\u5bf9\u5e9425 \u89c6\u5b9e\u9645\u60c5\u51b5\u800c\u5b9a\n        props.setProperty(\"mail.imap.socketFactory.port\", mailinfo.getMailboxPort().toString());\n        props.setProperty(\"mail.store.protocol\", \"imap\");\n        \/\/\u6536\u4fe1\u65f6\u90ae\u7bb1\u670d\u52a1\u5668\u5730\u5740 \u6bd4\u5982qq\u90ae\u7bb1\u5bf9\u5e94imap.exmail.qq.com\n        props.setProperty(\"mail.imap.host\", mailinfo.getMailbox());\n        \/\/\u6536\u4fe1\u4f7f\u7528\u7684\u7aef\u53e3  ssl\u5bf9\u5e94993 \u666e\u901a\u5bf9\u5e94143 \u89c6\u5b9e\u9645\u60c5\u51b5\u800c\u5b9a\n        props.setProperty(\"mail.imap.port\", mailinfo.getMailboxPort().toString());\n        props.setProperty(\"mail.imap.auth.login.disable\", \"true\");\n        props.setProperty(\"mail.imap.partialfetch\", \"false\");\n        props.setProperty(\"mail.imaps.partialfetch\", \"false\");\n        Session session = Session.getInstance(props, null);\n        \/\/\u662f\u5426\u5f00\u542fdebug\u6a21\u5f0f \u5982\u679c\u8bbe\u7f6e\u6210true \u4f60\u5c06\u5f97\u5230\u5927\u91cf\u90ae\u4ef6log\u4fe1\u606f\u5e2e\u52a9\u8c03\u8bd5\n        session.setDebug(false);\n        return session;\n    }<\/pre>\n\n\n\n<p><strong>\u6784\u5efa\u7eaf\u6587\u672c\u65e0\u9644\u4ef6\u7684\u90ae\u4ef6:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void SendJustText(Session session) throws MessagingException {\n        MimeMessage message = new MimeMessage(session);\n        \/\/\u90ae\u4ef6\u6807\u9898\n        message.setSubject(\"\u7eaf\u6587\u672c\");\n        \/\/\u90ae\u4ef6\u53d1\u9001\u4eba\n        message.setFrom(new InternetAddress(MailService.senderMail));\n        \/\/\u90ae\u4ef6\u63a5\u6536\u4eba     message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(MailService.senderMail));\n        \/\/\u6784\u5efa\u6700\u5916\u5c42\u7684MimeMutipart\n        MimeMultipart mimeMultipart = new MimeMultipart(\"alternative\");\n        \/\/\u6784\u5efa\u90ae\u4ef6\u6b63\u6587Body\n        MimeBodyPart mimeBodyPart = new MimeBodyPart();\n        mimeBodyPart.setContent(\"\u6211\u662f\u7eaf\u6587\u672c\u6b63\u6587\",\"TEXT\/PLAIN; charset=GB2312\");\n        \/\/\u5c06body\u8ffd\u52a0\u5230Mutipart\n        mimeMultipart.addBodyPart(mimeBodyPart);\n        message.setContent(mimeMultipart);\n        \/\/\u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        Transport transport = session.getTransport(\"smtp\");\n        \/\/\u53ef\u4ee5\u770b\u6210\u81ea\u5df1\u7684\u90ae\u7bb1\u767b\u5f55 \u7528\u65f6\u81ea\u884c\u66ff\u6362\u53c2\u6570\n        transport.connect(MailService.mailHost, MailService.senderMail, MailService.password);\n        \/\/\u53d1\u9001\u6d88\u606f\n        transport.sendMessage(message, message.getAllRecipients());\n    }<\/pre>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u7eaf\u6587\u672c\u7684\u90ae\u4ef6<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-26.png\" alt=\"\" class=\"wp-image-11243\" width=\"474\" height=\"237\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26.png 922w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26-300x150.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26-768x385.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26-830x416.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26-230x115.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26-350x175.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-26-480x241.png 480w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u6784\u5efa\u7eaf\u6587\u672c\u5e26\u9644\u4ef6\u7684\u90ae\u4ef6<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"MIXED\")\n|------MimeBodyPart0 ---- MimeMutiPart(\"ALTERNATIVE\")\n|            MimeBodyPart0(\"TEXT\/PLAIN\")\n|            MimeBodyPart1(\"TEXT\/HTML\")\n|------MimeBodyPart1 (\"\"APPLICATION\/OCTET-STREAM\")\n|------MimeBodyPart2 (\"\"APPLICATION\/OCTET-STREAM\")\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void SendAttachText(Session session) throws MessagingException, IOException {\n        MimeMessage message = new MimeMessage(session);\n        \/\/\u90ae\u4ef6\u6807\u9898\n        message.setSubject(\"\u7eaf\u6587\u672c\u5e26\u9644\u4ef6\");\n        \/\/\u90ae\u4ef6\u53d1\u9001\u4eba\n        message.setFrom(new InternetAddress(MailService.senderMail));\n        \/\/\u90ae\u4ef6\u63a5\u6536\u4eba\n        message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(MailService.senderMail));\n\n        \/\/\u6784\u5efa\u6700\u5916\u5c42\u7684MimeMutipart\n        MimeMultipart mimeMultipart = new MimeMultipart(\"mixed\");\n        \/\/\u6784\u5efa\u90ae\u4ef6\u6b63\u6587Body\n        MimeBodyPart mimeBodyPart = new MimeBodyPart();\n        mimeBodyPart.setContent(\"\u6211\u662f\u7eaf\u6587\u672c\u5e26\u9644\u4ef6\u6b63\u6587\",\"TEXT\/PLAIN; charset=GB2312\");\n        \/\/\u5c06body\u8ffd\u52a0\u5230Mutipart\n        mimeMultipart.addBodyPart(mimeBodyPart);\n        \/\/\u6dfb\u52a0\u7b2c\u4e00\u4e2a\u9644\u4ef6\n        mimeMultipart.addBodyPart(getAttchment1());\n        \/\/\u6dfb\u52a0\u7b2c\u4e8c\u4e2a\u9644\u4ef6\n        mimeMultipart.addBodyPart(getAttchment2());\n        message.setContent(mimeMultipart);\n        \/\/\u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        Transport transport = session.getTransport(\"smtp\");\n        \/\/\u53ef\u4ee5\u770b\u6210\u81ea\u5df1\u7684\u90ae\u7bb1\u767b\u5f55\n        transport.connect(MailService.mailHost, MailService.senderMail, MailService.password);\n        \/\/\u53d1\u9001\u6d88\u606f\n        transport.sendMessage(message, message.getAllRecipients());\n    }\n\n\n    \/**\n     * \u6784\u5efa\u9644\u4ef61\n     * @return\n     * @throws IOException\n     * @throws MessagingException\n     *\/\n    private MimeBodyPart getAttchment1() throws IOException, MessagingException {\n        MimeBodyPart attachPart = new MimeBodyPart();\n        File file = new File(\"C:\\\\Users\\\\xxx\\\\Desktop\\\\spring\u521d\u59cb\u5316.txt\");\n        attachPart.attachFile(file);\n        \/\/\u89e3\u51b3\u4e2d\u6587\u4e71\u7801\u95ee\u9898\n        attachPart.setFileName(MimeUtility.encodeText(file.getName()));\n        return attachPart;\n    }\n    \/**\n     * \u6784\u5efa\u9644\u4ef62\n     * @return\n     * @throws IOException\n     * @throws MessagingException\n     *\/\n    private MimeBodyPart getAttchment2() throws IOException, MessagingException {\n        MimeBodyPart attachPart = new MimeBodyPart();\n        File file = new File(\"C:\\\\Users\\\\xxx\\\\Desktop\\\\\u957f\u6625\u519c\u5546\u884c\u95ee\u9898\u4fee\u590d\\\\\u64cd\u4f5c\u8bf4\u660e.txt\");\n        attachPart.attachFile(file);\n        \/\/\u89e3\u51b3\u4e2d\u6587\u4e71\u7801\u95ee\u9898\n        attachPart.setFileName(MimeUtility.encodeText(file.getName()));\n        return attachPart;\n    }<\/pre>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u7eaf\u6587\u672c\u5e26\u9644\u4ef6\u7684\u90ae\u4ef6<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-27-1024x582.png\" alt=\"\" class=\"wp-image-11244\" width=\"409\" height=\"232\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-1024x582.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-300x170.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-768x436.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-830x471.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-230x131.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-350x199.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27-480x273.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-27.png 1310w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/figure><\/div>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u4f1a\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898:<\/p>\n\n\n\n<p>\u4e00\u822c\u6765\u8bb2\u90ae\u4ef6\u9644\u4ef6\u4e0d\u662f\u4ece\u672c\u5730\u83b7\u53d6 \u800c\u662f\u670d\u52a1\u5668\u63a5\u6536\u5ba2\u6237\u7aef\u53d1\u8fc7\u6765\u7684\u6587\u4ef6\uff0c\u8fd9\u6837\u5982\u4f55\u5199\u5462?\u4e8e\u662f\u6211\u4eec\u7684getAttchment1\u65b9\u6cd5\u5c31\u53d8\u6210\u4e86\u8fd9\u6837:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    \/**\n     * \u6784\u5efa\u9644\u4ef61\n     * @return\n     * @throws IOException\n     * @throws MessagingException\n     *\/\n   private MimeBodyPart getAttchment1(MultipartFile attachFile) throws IOException, MessagingException {\n        if (attachFile != null) {\n            MimeBodyPart attachPart = new MimeBodyPart();\n            ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(multipartFile.getInputStream(),multipartFile.getContentType());\n                \/\/\u4e3a\u6587\u4ef6\u6d41\u8bbe\u7f6e\u6587\u4ef6\u540d\u79f0\n                byteArrayDataSource.setName(multipartFile.getOriginalFilename());\n                DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(multipartFile.getInputStream(),multipartFile.getContentType()));\n            attachPart.setDataHandler(new DataHandler(dataSource));\n            \/\/\u8fd9\u91cc\u6587\u4ef6\u6e90\u540d\u79f0\u7531\u5ba2\u6237\u7aef\u4e0a\u4f20 \u4e00\u822c\u90fd\u662f\u7ecf\u8fc7url\u7f16\u7801\u7684 \u6211\u4eec\u5148\u89e3\u7801 \u518d\u8f6c\u6210\u90ae\u7bb1\u7684\u7f16\u7801    \n            attachPart.setFileName(MimeUtility.encodeText(URLDecoder.decode(attachFile.getOriginalFilename(), \"utf-8\")));\n        }\n    }\n<\/pre>\n\n\n\n<p><strong>\u6784\u5efa\u56fe\u6587\u6df7\u5408\u65e0\u9644\u4ef6\u7684\u90ae\u4ef6:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"RELATED\")\n|------MimeBodyPart0 ---- MimeMutiPart(\"ALTERNATIVE\")\n|            MimeBodyPart0(\"TEXT\/PLAIN\")\n|            MimeBodyPart1(\"TEXT\/HTML\")\n|------MimeBodyPart1(\"IMAGE\/GIF\")\n|------MimeBodyPart2(\"IMAGE\/GIF\")\n|------MimeBodyPart3(\"IMAGE\/GIF\")<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void SendJianShuPicText(Session session) throws MessagingException {\n        MimeMessage message = new MimeMessage(session);\n        \/\/\u90ae\u4ef6\u6807\u9898\n        message.setSubject(\"\u5bcc\u6587\u672c\u65e0\u9644\u4ef6\");\n        \/\/\u90ae\u4ef6\u53d1\u9001\u4eba\n        message.setFrom(new InternetAddress(MailService.senderMail));\n        \/\/\u90ae\u4ef6\u63a5\u6536\u4eba\n        message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(MailService.senderMail));\n        \/\/\u6784\u5efa\u6700\u5916\u5c42\u7684MimeMutipart\n        MimeMultipart mimeMultipart = new MimeMultipart(\"related\");\n        \/\/\u5c06\u6587\u672c\u7684bodyPart\u8ffd\u52a0\u5230Mutipart\n        mimeMultipart.addBodyPart(getAlterBodyPart());\n        message.setContent(mimeMultipart);\n        \/\/\u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        Transport transport = session.getTransport(\"smtp\");\n        \/\/\u53ef\u4ee5\u770b\u6210\u81ea\u5df1\u7684\u90ae\u7bb1\u767b\u5f55\n        transport.connect(MailService.mailHost, MailService.senderMail, MailService.password);\n        \/\/\u53d1\u9001\u6d88\u606f\n        transport.sendMessage(message, message.getAllRecipients());\n    }\n\n    public MimeBodyPart getAlterBodyPart() throws MessagingException {\n        \/\/\u8981\u8fd4\u56de\u7684alterBodyPart\n        MimeBodyPart alterBodyPart = new MimeBodyPart();\n        \/\/\u5b9a\u4e49alterBodyPart\u4e0b\u7684mutiPart\n        MimeMultipart alterMutiPart = new MimeMultipart(\"ALTERNATIVE\");\n        \/\/\u5b9a\u4e49\u6587\u672cbodyPart\n        MimeBodyPart textBodyPart = new MimeBodyPart();\n        textBodyPart.setContent(\"\u6211\u662f\u5bcc\u6587\u672c\u65e0\u9644\u4ef6\u6b63\u6587\",\"TEXT\/PLAIN; charset=GB2312\");\n        \/\/\u5b9a\u4e49html\u7684bodyPart\n        MimeBodyPart htmlBodyPart =new MimeBodyPart();\n        htmlBodyPart.setContent(\"&lt;html>&lt;div>&lt;h3>\u6211\u662f\u5bcc\u6587\u672c\u65e0\u9644\u4ef6\u6b63\u6587&lt;\/h3>&lt;\/div>&lt;\/br>&lt;img src='cid:lenglengliang1'\/>&lt;\/br>&lt;strong>\u6211\u7684\u51b7\u51b7\u51c92&lt;\/strong>&lt;\/br>&lt;img src='cid:lenglengliang2'\/>&lt;\/br>\u4e0d\u4e0b\u5730\u7684\u51b7\u51b7\u51c9&lt;\/html>\",\"TEXT\/HTML; charset=GB2312\");\n        \/\/\u6dfb\u52a0\u6587\u672c\u7684bodyPart\n        alterMutiPart.addBodyPart(textBodyPart);\n        \/\/\u6dfb\u52a0html\u7684bodyPart\n        alterMutiPart.addBodyPart(htmlBodyPart);\n        \/\/\u5b9a\u4e49inline\u9644\u4ef6\u7684bodyPart\n        MimeBodyPart inlineBodyPart = new MimeBodyPart();\n        DataSource dataSource = new FileDataSource(new File(\"D:\\\\\u4e00\u4e9b\u56fe\u7247\\\\\u65e0\u804a\u7684\u56fe\u7247\\\\\u672a\u6765\u6218\u58eb\\\\timg.jpg\"));\n        inlineBodyPart.setDataHandler(new DataHandler(dataSource));\n        inlineBodyPart.setDisposition(MimeBodyPart.INLINE);\n        inlineBodyPart.setContentID(\"&lt;lenglengliang1>\");\n        \/\/\u6dfb\u52a0inline\u7684bodyPart\n        alterMutiPart.addBodyPart(inlineBodyPart);\n\n        MimeBodyPart inlineBodyPart2 = new MimeBodyPart();\n        DataSource dataSource2 = new FileDataSource(new File(\"D:\\\\\u4e00\u4e9b\u56fe\u7247\\\\\u65e0\u804a\u7684\u56fe\u7247\\\\\u672a\u6765\u6218\u58eb\\\\timg (2).jpg\"));\n        inlineBodyPart2.setDataHandler(new DataHandler(dataSource2));\n        inlineBodyPart2.setDisposition(MimeBodyPart.INLINE);\n        inlineBodyPart2.setContentID(\"&lt;lenglengliang2>\");\n        \/\/\u6dfb\u52a0inline\u7684bodyPart\n        alterMutiPart.addBodyPart(inlineBodyPart2);\n        \/\/\u88c5\u8f7dmutiPart\n        alterBodyPart.setContent(alterMutiPart);\n        return alterBodyPart;\n    }<\/pre>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u5bcc\u6587\u672c\u65e0\u9644\u4ef6\u7684\u90ae\u4ef6<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-28-562x1024.png\" alt=\"\" class=\"wp-image-11245\" width=\"284\" height=\"517\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-28-562x1024.png 562w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-28-165x300.png 165w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-28-230x419.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-28-350x638.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-28-480x875.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-28.png 764w\" sizes=\"(max-width: 284px) 100vw, 284px\" \/><\/figure><\/div>\n\n\n\n<p>\u5c06\u56fe(\u4e0d\u7ba1\u662f\u56fe\u7247\u8fd8\u662f\u4e00\u4e9b\u8868\u60c5)\u6dfb\u52a0\u5230\u6b63\u6587\u7684\u903b\u8f91\u662f:<br>1.\u9996\u5148\u4fdd\u8bc1html\u6587\u672c\u4e2d\u5305\u542bimg\u6807\u7b7e \u5bcc\u6587\u672c\u5728\u90ae\u7bb1\u4e2d\u663e\u793a\u7684\u5176\u5b9e\u5c31\u662f\u4e00\u4e2ahtml\u9875\u9762<br>2.\u56fe\u7247\u548c&lt;img src=&#8221;&#8221; \/&gt;\u7684\u5173\u8054\u5173\u7cfb\u5c31\u662f\u4ee5\u4e0b\u4ee3\u7801\u521b\u5efa\u7684<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> htmlBodyPart.setContent(\"&lt;html>&lt;img src='cid:lenglengliang1'\/>&lt;\/html>\",\"TEXT\/HTML; charset=GB2312\");\n inlineBodyPart.setContentID(\"&lt;lenglengliang1>\");\n<\/pre>\n\n\n\n<p>html\u4e2d\u7684src \u5fc5\u987b\u5305\u542bcid: \u8fd9\u662frfc\u6807\u51c6\u683c\u5f0f<\/p>\n\n\n\n<p>bodyPart.setContentID \u5e76\u4e0d\u5305\u542b&#8221;cid:&#8221;,\u4f46\u5374\u6709 &#8220;&lt;&gt;&#8221; \u6807\u7b7e \u8fd9\u662f\u90ae\u4ef6\u7684\u6807\u51c6\u683c\u5f0f\uff0c\u5982\u679c\u4e0d\u5e26\uff0c\u53d1\u9001\u65f6\u53ef\u80fd\u6ca1\u95ee\u9898\uff0c\u4f46\u662f\u8fd9\u4e2a\u90ae\u4ef6\u88ab\u5b89\u5353\u6216\u8005ios\u7aef\u8f6c\u53d1\u89e3\u6790\u65f6\u53ef\u80fd\u51fa\u73b0\u95ee\u9898\uff0c\u4ed6\u4eec\u7684\u6807\u51c6\u5e93\u5224\u65ad\u4e86&#8221;&lt;&gt;&#8221;<\/p>\n\n\n\n<p>PS:\u9879\u76ee\u4e2d\u7b14\u8005\u66fe\u7ecf\u4e3a\u56fe\u6587\u4e2d\u7684\u56fe\u53d1\u9001\u540e\u53d8\u6210\u4e86\u9644\u4ef6\u800c\u82e6\u607c\u4e86\u5f88\u4e45,\u539f\u56e0\u5c31\u662f\u8fd9\u4e2acid src\u4e2d\u9700\u8981\u5e26\u4f46setContentID\u65f6\u5374\u4e0d\u9700\u8981\u5e26<\/p>\n\n\n\n<p><strong>\u6784\u5efa\u56fe\u6587\u6df7\u5408\u5e26\u9644\u4ef6\u7684\u90ae\u4ef6:<\/strong><\/p>\n\n\n\n<p>\u8fd9\u662f\u6700\u590d\u6742\u7684\u4e5f\u662f\u6700\u5e38\u7528\u7684<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">--- MimeMutiPart(\"MIXED\")\n|------MimeBodyPart0 ---- MimeMutiPart(\"RELATED\")\n|            MimeBodyPart0 ---- MimeMutiPart(\"ALTERNATIVE\")\n|                 MimeBodyPart0(\"TEXT\/PLAIN\")\n|                 MimeBodyPart1(\"TEXT\/HTML\")\n|            MimeBodyPart1(\"IMAGE\/GIF\")\n|            MimeBodyPart2(\"IMAGE\/GIF\")\n|            MimeBodyPart3(\"IMAGE\/GIF\")\n|------MimeBodyPart1 (\"APPLICATION\/OCTET-STREAM\")\n|------MimeBodyPart2 (\"APPLICATION\/OCTET-STREAM\")\n|------MimeBodyPart3 (\"APPLICATION\/OCTET-STREAM\")\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public void SendJianShuAttachPicText(Session session) throws MessagingException, IOException {\n        MimeMessage message = new MimeMessage(session);\n        \/\/\u90ae\u4ef6\u6807\u9898\n        message.setSubject(\"\u5bcc\u6587\u672c\u5e26\u9644\u4ef6\");\n        \/\/\u90ae\u4ef6\u53d1\u9001\u4eba\n        message.setFrom(new InternetAddress(MailService.senderMail));\n        \/\/\u90ae\u4ef6\u63a5\u6536\u4eba\n        message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(MailService.senderMail));\n        \/\/\u6784\u5efa\u6700\u5916\u5c42\u7684MimeMutipart\n        MimeMultipart mimeMultipart = new MimeMultipart(\"related\");\n        \/\/\u5c06\u6587\u672c\u7684bodyPart\u8ffd\u52a0\u5230Mutipart\n        mimeMultipart.addBodyPart(getAlterBodyPart());\n        message.setContent(mimeMultipart);\n        \/\/\u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        Transport transport = session.getTransport(\"smtp\");\n        \/\/\u53ef\u4ee5\u770b\u6210\u81ea\u5df1\u7684\u90ae\u7bb1\u767b\u5f55\n        transport.connect(MailService.mailHost, MailService.senderMail, MailService.password);\n        \/\/\u53d1\u9001\u6d88\u606f\n        transport.sendMessage(message, message.getAllRecipients());\n    }\n\n    public MimeBodyPart getAlterBodyPart() throws MessagingException, IOException {\n        \/\/\u8981\u8fd4\u56de\u7684alterBodyPart\n        MimeBodyPart alterBodyPart = new MimeBodyPart();\n        \/\/\u5b9a\u4e49alterBodyPart\u4e0b\u7684mutiPart\n        MimeMultipart alterMutiPart = new MimeMultipart(\"ALTERNATIVE\");\n        \/\/\u5b9a\u4e49\u6587\u672cbodyPart\n        MimeBodyPart textBodyPart = new MimeBodyPart();\n        textBodyPart.setContent(\"\u6211\u662f\u5bcc\u6587\u672c\u5e26\u9644\u4ef6\u6b63\u6587\",\"TEXT\/PLAIN; charset=GB2312\");\n        \/\/\u5b9a\u4e49html\u7684bodyPart\n        MimeBodyPart htmlBodyPart =new MimeBodyPart();\n        htmlBodyPart.setContent(\"&lt;html>&lt;div>&lt;h3>\u6211\u662f\u5bcc\u6587\u672c\u5e26\u9644\u4ef6\u6b63\u6587&lt;\/h3>&lt;\/div>&lt;\/br>&lt;img src='cid:lenglengliang1'\/>&lt;\/br>&lt;strong>\u6211\u7684\u51b7\u51b7\u51c92&lt;\/strong>&lt;\/br>&lt;img src='cid:lenglengliang2'\/>&lt;\/br>\u4e0d\u4e0b\u5730\u7684\u51b7\u51b7\u51c9&lt;\/html>\",\"TEXT\/HTML; charset=GB2312\");\n        \/\/\u6dfb\u52a0\u6587\u672c\u7684bodyPart\n        alterMutiPart.addBodyPart(textBodyPart);\n        \/\/\u6dfb\u52a0html\u7684bodyPart\n        alterMutiPart.addBodyPart(htmlBodyPart);\n        \/\/\u5b9a\u4e49inline\u9644\u4ef6\u7684bodyPart\n        MimeBodyPart inlineBodyPart = new MimeBodyPart();\n        DataSource dataSource = new FileDataSource(new File(\"D:\\\\\u4e00\u4e9b\u56fe\u7247\\\\\u65e0\u804a\u7684\u56fe\u7247\\\\\u672a\u6765\u6218\u58eb\\\\timg.jpg\"));\n        inlineBodyPart.setDataHandler(new DataHandler(dataSource));\n        inlineBodyPart.setDisposition(MimeBodyPart.INLINE);\n        inlineBodyPart.setContentID(\"&lt;lenglengliang1>\");\n        \/\/\u6dfb\u52a0inline\u7684bodyPart\n        alterMutiPart.addBodyPart(inlineBodyPart);\n\n        MimeBodyPart inlineBodyPart2 = new MimeBodyPart();\n        DataSource dataSource2 = new FileDataSource(new File(\"D:\\\\\u4e00\u4e9b\u56fe\u7247\\\\\u65e0\u804a\u7684\u56fe\u7247\\\\\u672a\u6765\u6218\u58eb\\\\timg (2).jpg\"));\n        inlineBodyPart2.setDataHandler(new DataHandler(dataSource2));\n        inlineBodyPart2.setDisposition(MimeBodyPart.INLINE);\n        inlineBodyPart2.setContentID(\"&lt;lenglengliang2>\");\n        \/\/\u6dfb\u52a0inline\u7684bodyPart\n        alterMutiPart.addBodyPart(inlineBodyPart2);\n        \/\/\u6dfb\u52a0\u7b2c\u4e00\u4e2a\u9644\u4ef6\n        alterMutiPart.addBodyPart(getAttchment1());\n        \/\/\u6dfb\u52a0\u7b2c\u4e8c\u4e2a\u9644\u4ef6\n        alterMutiPart.addBodyPart(getAttchment2());\n        \/\/\u6dfb\u52a0\u7b2c\u4e09\u4e2a\u9644\u4ef6\n        alterMutiPart.addBodyPart(getAttchment3());\n        \/\/\u88c5\u8f7dmutiPart\n        alterBodyPart.setContent(alterMutiPart);\n        return alterBodyPart;\n    }\n\n    \/**\n     * \u6784\u5efa\u9644\u4ef61\n     * @return\n     * @throws IOException\n     * @throws MessagingException\n     *\/\n    private MimeBodyPart getAttchment1() throws IOException, MessagingException {\n        MimeBodyPart attachPart = new MimeBodyPart();\n        File file = new File(\"C:\\\\Users\\\\yangzhi\\\\Desktop\\\\spring\u521d\u59cb\u5316.txt\");\n        attachPart.attachFile(file);\n        attachPart.setFileName(MimeUtility.encodeText(file.getName()));\n        attachPart.setDisposition(MimeBodyPart.ATTACHMENT);\n        return attachPart;\n    }\n\n    \/**\n     * \u6784\u5efa\u9644\u4ef62\n     * @return\n     * @throws IOException\n     * @throws MessagingException\n     *\/\n    private MimeBodyPart getAttchment2() throws IOException, MessagingException {\n        MimeBodyPart attachPart = new MimeBodyPart();\n        File file = new File(\"C:\\\\Users\\\\yangzhi\\\\Desktop\\\\\u8f6c\u53d1\u5bcc\u6587\u672c(ceomg).eml\");\n        attachPart.attachFile(file);\n        attachPart.setFileName(MimeUtility.encodeText(file.getName()));\n        attachPart.setDisposition(MimeBodyPart.ATTACHMENT);\n        return attachPart;\n    }\n    \/**\n     * \u6784\u5efa\u9644\u4ef63\n     * @return\n     * @throws IOException\n     * @throws MessagingException\n     *\/\n    private MimeBodyPart getAttchment3() throws IOException, MessagingException {\n        MimeBodyPart attachPart = new MimeBodyPart();\n        File file = new File(\"C:\\\\Users\\\\yangzhi\\\\Desktop\\\\\u90ae\u7bb1\u5f00\u53d1\u51c6\u5907\\\\\u90ae\u7bb1id\u6bd4\u5bf9.txt\");\n        attachPart.attachFile(file);\n        attachPart.setFileName(MimeUtility.encodeText(file.getName()));\n        attachPart.setDisposition(MimeBodyPart.ATTACHMENT);\n        return attachPart;\n    }\n<\/pre>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u5bcc\u6587\u672c\u5e26\u9644\u4ef6\u7684\u90ae\u4ef6<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-29-519x1024.png\" alt=\"\" class=\"wp-image-11246\" width=\"274\" height=\"541\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-29-519x1024.png 519w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-29-152x300.png 152w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-29-230x454.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-29-350x690.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-29-480x947.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-29.png 718w\" sizes=\"(max-width: 274px) 100vw, 274px\" \/><\/figure><\/div>\n\n\n\n<p>\u9644\u4e00\u4e9b\u6982\u5ff5\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-30-1024x383.png\" alt=\"\" class=\"wp-image-11248\" width=\"483\" height=\"181\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-1024x383.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-300x112.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-768x287.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-1536x574.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-830x310.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-230x86.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-350x131.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30-480x180.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-30.png 1722w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-31-1024x470.png\" alt=\"\" class=\"wp-image-11249\" width=\"533\" height=\"244\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-1024x470.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-300x138.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-768x353.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-830x381.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-230x106.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-350x161.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31-480x221.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-31.png 1184w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-32-1024x478.png\" alt=\"\" class=\"wp-image-11250\" width=\"500\" height=\"233\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-1024x478.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-300x140.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-768x359.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-830x388.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-230x107.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-350x163.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32-480x224.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-32.png 1306w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-33-1024x550.png\" alt=\"\" class=\"wp-image-11251\" width=\"494\" height=\"265\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-1024x550.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-300x161.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-768x412.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-830x446.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-230x123.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-350x188.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33-480x258.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-33.png 1326w\" sizes=\"(max-width: 494px) 100vw, 494px\" \/><\/figure><\/div>\n\n\n\n<p>MimeMultipart\u5bf9\u8c61\u7684\u4f7f\u7528\u7684\u65f6\u5019\u9700\u8981\u8bbe\u7f6esetSubType()\u7684\u5c5e\u6027\u503c\uff0c\u4e00\u5171\u5c31\u4e0b\u97623\u79cd\u53d6\u503c<\/p>\n\n\n\n<ul><li>alternative\uff1a\u8868\u660e\u8fd9\u4e2aMimeMultipart\u5bf9\u8c61\u4e2d\u7684MimeMessage\u5bf9\u8c61\u7684\u6570\u636e\u662f\u7eaf\u6587\u672c\u6587\u4ef6<\/li><li>related\uff1a\u8868\u660e\u8fd9\u4e2aMimeMultipart\u5bf9\u8c61\u4e2d\u7684MimeMessage\u5bf9\u8c61\u7684\u6570\u636e\u5305\u542b\u975e\u7eaf\u6587\u672c\u6587\u4ef6<\/li><li>mixed\uff1a\u8868\u660e\u8fd9\u4e2aMimeMultipart\u5bf9\u8c61\u4e2d\u7684MimeMessage\u5bf9\u8c61\u7684\u6570\u636e\u5305\u542b\u9644\u4ef6<\/li><\/ul>\n\n\n\n<p>\u6211\u4eec\u5728\u4f7f\u5f97\u7684\u65f6\u5019\u5982\u679c\u4e0d\u77e5\u9053\u4f7f\u7528\u54ea\u4e00\u4e2a\uff0c\u76f4\u63a5\u4f7f\u7528mixed\u5373\u53ef\uff0c\u4f7f\u7528\u8fd9\u4e2a\u5c5e\u6027\u503c\u4e00\u5b9a\u4e0d\u4f1a\u62a5\u9519<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/05\/image-34-1024x474.png\" alt=\"\" class=\"wp-image-11252\" width=\"515\" height=\"237\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34-1024x474.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34-300x139.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34-830x384.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34-230x106.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34-350x162.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34-480x222.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/05\/image-34.png 1214w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/figure><\/div>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>maven\u5f15\u7528 JavaMail\u90ae\u4ef6\u683c\u5f0f\u4ecb\u7ecd \u5982\u679c\u60f3\u4e86\u89e3\u90ae\u4ef6\u5982\u4f55\u53d1\u9001\uff0c\u6211\u4eec\u5fc5\u987b\u4e86\u89e3\u90ae\u4ef6\u6d88\u606f\u7684\u6b63\u6587\u7ed3\u6784\u6211\u4eec\u5148\u4e86\u89e3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11240"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11240"}],"version-history":[{"count":6,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11240\/revisions"}],"predecessor-version":[{"id":11256,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11240\/revisions\/11256"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}