{"id":2199,"date":"2024-05-31T11:06:05","date_gmt":"2024-05-31T03:06:05","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2199"},"modified":"2024-05-31T11:06:05","modified_gmt":"2024-05-31T03:06:05","slug":"spring-boot%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e7%9a%84%e9%82%ae%e7%ae%b1%e9%aa%8c%e8%af%81%e7%a0%81%e6%b3%a8%e5%86%8c%e9%85%8d%e7%bd%ae%e5%ae%9e%e7%8e%b0%e4%b8%8e%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2024\/05\/31\/spring-boot%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e7%9a%84%e9%82%ae%e7%ae%b1%e9%aa%8c%e8%af%81%e7%a0%81%e6%b3%a8%e5%86%8c%e9%85%8d%e7%bd%ae%e5%ae%9e%e7%8e%b0%e4%b8%8e%e6%b5%8b%e8%af%95\/","title":{"rendered":"Spring boot\u5b9e\u73b0\u7b80\u5355\u7684\u90ae\u7bb1\u9a8c\u8bc1\u7801\u6ce8\u518c\u914d\u7f6e\u5b9e\u73b0\u4e0e\u6d4b\u8bd5"},"content":{"rendered":"\n<p>\u6dfb\u52a0mail\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n&lt;dependency>\n    &lt;groupId>org.springframework.boot&lt;\/groupId>\n    &lt;artifactId>spring-boot-starter-mail&lt;\/artifactId>\n&lt;\/dependency><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2024\/05\/0cc7f450-a326-4841-b766-db2132eec32d-2-1024x898.png\" alt=\"\" class=\"wp-image-2210\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.laoxu.springboot;\n \nimport org.junit.Test;\nimport org.junit.runner.RunWith;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.context.SpringBootTest;\nimport org.springframework.mail.SimpleMailMessage;\nimport org.springframework.mail.javamail.JavaMailSenderImpl;\nimport org.springframework.mail.javamail.MimeMessageHelper;\nimport org.springframework.test.context.junit4.SpringRunner;\n \nimport javax.mail.internet.MimeMessage;\nimport java.io.File;\n \n@RunWith(SpringRunner.class)\n@SpringBootTest\npublic class TaskApplicationTests {\n    @Autowired\n    JavaMailSenderImpl mailSender;\n \n    @Test\n    public void contextLoads() {\n        SimpleMailMessage message = new SimpleMailMessage();\n        message.setSubject(\"\u4eca\u665a\u5f00\u4f1a\");\n        message.setText(\"\u5927\u5bb6\uff0c\u597d\uff01\\n\u4eca\u665a7:30\u5728\u6559\u5b66\u697c201\u5f00\u73ed\u59d4\u4f1a\uff0c\u8bf7\u5404\u4f4d\u73ed\u59d4\u51c6\u65f6\u53c2\u52a0\uff01 \\n\u8c22\u8c22\uff01\");\n        message.setTo(\"indexman@126.com\");\n        message.setFrom(\"836491384@qq.com\");\n \n        mailSender.send(message);\n    }\n \n    @Test\n    public void test2() throws Exception{\n        MimeMessage mimeMessage = mailSender.createMimeMessage();\n        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);\n        helper.setSubject(\"\u4eca\u665a\u5f00\u4f1a\");\n        helper.setText(\"\u5927\u5bb6\uff0c\u597d\uff01&lt;br> &amp;nbsp;&amp;nbsp;&lt;b style='color:red'>\u4eca\u665a7:30\u5728\u6559\u5b66\u697c201\u5f00\u73ed\u59d4\u4f1a\uff0c\u8bf7\u5404\u4f4d\u73ed\u59d4\u51c6\u65f6\u53c2\u52a0\uff01&lt;\/b> &lt;br>\u8c22\u8c22\uff01\",true);\n        helper.setTo(\"indexman@126.com\");\n        helper.setFrom(\"836491384@qq.com\");\n \n        \/\/\u6dfb\u52a0\u9644\u4ef6\n        helper.addAttachment(\"\u4f1a\u8bae\u8bf4\u660e.txt\",new File(\"C:\\\\Users\\\\Dylan\\\\Pictures\\\\\u4f1a\u8bae\u8bf4\u660e.txt\"));\n        helper.addAttachment(\"\u4f1a\u8bae\u56fe\u7247.jpg\",new File(\"C:\\\\Users\\\\Dylan\\\\Pictures\\\\\u4f1a\u8bae\u56fe\u7247.jpg\"));\n \n        mailSender.send(mimeMessage);\n    }\n \n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6dfb\u52a0mail\u4f9d\u8d56\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2199","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=2199"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2199\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}