{"id":51520,"date":"2025-08-10T23:44:29","date_gmt":"2025-08-10T15:44:29","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/51520.html"},"modified":"2025-08-10T23:44:29","modified_gmt":"2025-08-10T15:44:29","slug":"%e8%b0%b7%e6%ad%8c%e9%82%ae%e7%ae%b1smtp%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%bf%9e%e6%8e%a5%e5%bc%82%e5%b8%b8%ef%bc%9amailconnectexception-couldnt-connect-to-host-port-smtp-gmail-com-587","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/51520.html","title":{"rendered":"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587"},"content":{"rendered":"<h2>1\u3001SpringBoot\u53d1\u9001\u90ae\u4ef6<\/h2>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 Spring Boot \u53d1\u9001\u90ae\u4ef6\u7684\u6700\u5c0f\u5b8c\u6574\u793a\u4f8b\u3002\u8fd9\u4e2a\u793a\u4f8b\u4f7f\u7528 Gmail \u7684 SMTP \u670d\u52a1&#xff0c;\u53d1\u9001\u4e00\u5c01\u7b80\u5355\u7684\u7eaf\u6587\u672c\u90ae\u4ef6\u3002<\/p>\n<p>\u524d\u63d0\u8981\u6c42&#xff1a;\u4f7f\u7528idea\u7684\u5f15\u5bfc\u642d\u5efa\u4e00\u4e2aSpringBoot\u7684web\u9879\u76ee\u57fa\u7840\u6846\u67b6\u3002<\/p>\n<h4>1. \u9879\u76ee\u4f9d\u8d56<\/h4>\n<p>\u9996\u5148&#xff0c;\u5728\u4f60\u7684 pom.xml \u6587\u4ef6\u4e2d\u6dfb\u52a0 Spring Boot Mail Starter \u4f9d\u8d56\u3002<\/p>\n<p><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependencies<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>org.springframework.boot<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-boot-starter-mail<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependencies<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<h4>2. \u5e94\u7528\u914d\u7f6e<\/h4>\n<p>\u5728 src\/main\/resources\/application.properties \u6587\u4ef6\u4e2d&#xff0c;\u914d\u7f6e\u90ae\u4ef6\u670d\u52a1\u5668\u7684\u8fde\u63a5\u4fe1\u606f\u3002\u8fd9\u91cc\u4ee5 Gmail \u4e3a\u4f8b&#xff0c;\u4f60\u9700\u8981\u5c06 your&#064;gmail.com \u548c your-app-password \u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u90ae\u7bb1\u5730\u5740\u548c\u5e94\u7528\u5bc6\u7801\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u4e3a\u4e86\u5b89\u5168&#xff0c;Gmail \u7b49\u670d\u52a1\u63d0\u4f9b\u5546\u901a\u5e38\u9700\u8981\u4f60\u751f\u6210\u4e00\u4e2a\u5e94\u7528\u4e13\u7528\u5bc6\u7801 (App Password)&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528\u4f60\u7684\u8d26\u6237\u767b\u5f55\u5bc6\u7801\u3002<\/p>\n<p># \u90ae\u4ef6\u670d\u52a1\u5668\u914d\u7f6e<br \/>\nspring.mail.host&#061;smtp.gmail.com<br \/>\nspring.mail.port&#061;587<br \/>\nspring.mail.username&#061;your&#064;gmail.com<br \/>\nspring.mail.password&#061;your-app-password  #\u6ce8\u610f&#xff1a;\u8fd9\u91cc\u7684\u5bc6\u7801\u662f\u5e94\u7528\u4e13\u7528\u5bc6\u7801&#xff0c;\u800c\u4e0d\u662f\u8c37\u6b4c\u90ae\u7bb1\u7684\u8d26\u53f7\u5bc6\u7801<\/p>\n<p># \u542f\u7528 SMTP \u8ba4\u8bc1\u548c TLS \u52a0\u5bc6<br \/>\nspring.mail.properties.mail.smtp.auth&#061;true<br \/>\nspring.mail.properties.mail.smtp.starttls.enable&#061;true<\/p>\n<h4>3. \u521b\u5efa\u90ae\u4ef6\u670d\u52a1\u7c7b<\/h4>\n<p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 Service \u7c7b\u6765\u5c01\u88c5\u90ae\u4ef6\u53d1\u9001\u903b\u8f91\u3002Spring Boot \u4f1a\u81ea\u52a8\u914d\u7f6e JavaMailSender bean&#xff0c;\u4f60\u53ef\u4ee5\u76f4\u63a5\u6ce8\u5165\u4f7f\u7528\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>beans<span class=\"token punctuation\">.<\/span>factory<span class=\"token punctuation\">.<\/span>annotation<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">Value<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>mail<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">SimpleMailMessage<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>mail<span class=\"token punctuation\">.<\/span>javamail<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">JavaMailSender<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>stereotype<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">Service<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">EmailService<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">JavaMailSender<\/span> mailSender<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Value<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;${spring.mail.username}&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">\/\/ \u6ce8\u5165\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u503c<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">String<\/span> fromEmail<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">EmailService<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">JavaMailSender<\/span> mailSender<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>mailSender <span class=\"token operator\">&#061;<\/span> mailSender<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">sendSimpleEmail<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span> toEmail<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">String<\/span> subject<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">String<\/span> body<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SimpleMailMessage<\/span> message <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">SimpleMailMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        message<span class=\"token punctuation\">.<\/span><span class=\"token function\">setFrom<\/span><span class=\"token punctuation\">(<\/span>fromEmail<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u53d1\u4ef6\u4eba\u5730\u5740<\/span><br \/>\n        message<span class=\"token punctuation\">.<\/span><span class=\"token function\">setTo<\/span><span class=\"token punctuation\">(<\/span>toEmail<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>            <span class=\"token comment\">\/\/ \u6536\u4ef6\u4eba\u5730\u5740<\/span><br \/>\n        message<span class=\"token punctuation\">.<\/span><span class=\"token function\">setSubject<\/span><span class=\"token punctuation\">(<\/span>subject<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ \u90ae\u4ef6\u4e3b\u9898<\/span><br \/>\n        message<span class=\"token punctuation\">.<\/span><span class=\"token function\">setText<\/span><span class=\"token punctuation\">(<\/span>body<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>             <span class=\"token comment\">\/\/ \u90ae\u4ef6\u6b63\u6587<\/span><br \/>\n        mailSender<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u90ae\u4ef6\u53d1\u9001\u6210\u529f!&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>4. \u521b\u5efa\u4e00\u4e2a Web \u63a7\u5236\u5668\u6765\u6d4b\u8bd5<\/h4>\n<p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 RestController&#xff0c;\u901a\u8fc7 HTTP \u8bf7\u6c42\u6765\u89e6\u53d1\u90ae\u4ef6\u53d1\u9001\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>beans<span class=\"token punctuation\">.<\/span>factory<span class=\"token punctuation\">.<\/span>annotation<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">Autowired<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>web<span class=\"token punctuation\">.<\/span>bind<span class=\"token punctuation\">.<\/span>annotation<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">GetMapping<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>web<span class=\"token punctuation\">.<\/span>bind<span class=\"token punctuation\">.<\/span>annotation<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">RequestParam<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>web<span class=\"token punctuation\">.<\/span>bind<span class=\"token punctuation\">.<\/span>annotation<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">RestController<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token annotation punctuation\">&#064;RestController<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">EmailController<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">EmailService<\/span> emailService<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">EmailController<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">EmailService<\/span> emailService<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>emailService <span class=\"token operator\">&#061;<\/span> emailService<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;GetMapping<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/send-email&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">String<\/span> <span class=\"token function\">sendEmail<\/span><span class=\"token punctuation\">(<\/span><span class=\"token annotation punctuation\">&#064;RequestParam<\/span> <span class=\"token class-name\">String<\/span> <span class=\"token keyword\">to<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        emailService<span class=\"token punctuation\">.<\/span><span class=\"token function\">sendSimpleEmail<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">to<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u8fd9\u662f\u4e00\u5c01\u6d4b\u8bd5\u90ae\u4ef6&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8fd9\u662f\u4e00\u5c01\u7531 Spring Boot \u53d1\u9001\u7684\u7eaf\u6587\u672c\u90ae\u4ef6\u3002&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\u90ae\u4ef6\u53d1\u9001\u8bf7\u6c42\u5df2\u63d0\u4ea4&#xff01;\u8bf7\u68c0\u67e5\u4f60\u7684\u90ae\u7bb1\u3002&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>5. \u4e3b\u5e94\u7528\u7c7b<\/h4>\n<p>\u8fd9\u662f Spring Boot \u5e94\u7528\u7684\u5165\u53e3\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>boot<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token namespace\">org<span class=\"token punctuation\">.<\/span>springframework<span class=\"token punctuation\">.<\/span>boot<span class=\"token punctuation\">.<\/span>autoconfigure<span class=\"token punctuation\">.<\/span><\/span><span class=\"token class-name\">SpringBootApplication<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token annotation punctuation\">&#064;SpringBootApplication<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">MailApplication<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">MailApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u8fd0\u884c\u548c\u6d4b\u8bd5<\/h4>\n<li>\u8fd0\u884c MailApplication \u7c7b\u3002<\/li>\n<li>\u6253\u5f00\u6d4f\u89c8\u5668\u6216\u4f7f\u7528\u5de5\u5177&#xff08;\u5982 Postman&#xff09;&#xff0c;\u8bbf\u95ee\u4ee5\u4e0b URL&#xff1a;<br \/>\nhttp:\/\/localhost:8080\/send-email?to&#061;target&#064;example.com<br \/>\n\u8bf7\u5c06 target&#064;example.com \u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u6536\u4ef6\u4eba\u90ae\u7bb1\u5730\u5740\u3002<\/li>\n<p>\u5982\u679c\u4e00\u5207\u914d\u7f6e\u6b63\u786e&#xff0c;\u4f60\u4f1a\u5728\u63a7\u5236\u53f0\u770b\u5230\u201c\u90ae\u4ef6\u53d1\u9001\u6210\u529f!\u201d\u7684\u8f93\u51fa&#xff0c;\u5e76\u4e14\u6536\u4ef6\u4eba\u4f1a\u6536\u5230\u8fd9\u5c01\u6d4b\u8bd5\u90ae\u4ef6\u3002<\/p>\n<h2>2\u3001\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u95ee\u9898&#xff1a;MailConnectException<\/h2>\n<p>\u9879\u76ee\u542f\u52a8\u540e&#xff0c;\u6d4b\u8bd5\u62a5\u9519&#xff1a;<br \/>\norg.springframework.mail.MailSendException: Mail server connection failed. Failed messages: org.eclipse.angus.mail.util.MailConnectException: Couldn\u2019t connect to host, port: smtp.gmail.com, 587; timeout -1;<\/p>\n<p>\u8fd9\u4e2a\u62a5\u9519\u7684\u539f\u56e0\u662f\u4e0d\u80fd\u8fde\u63a5\u5230\u8c37\u6b4c\u7684SMTP\u670d\u52a1\u5668\u3002<\/p>\n<h2>3\u3001\u89e3\u51b3\u529e\u6cd5<\/h2>\n<p>\u9996\u5148&#xff0c;\u4f60\u9700\u8981\u5728\u8c37\u6b4c\u7684\u8d26\u53f7\u8bbe\u7f6e\u9875\u9762\u5f00\u542f\u767b\u5f55\u7684\u201c\u4e24\u6b65\u9a8c\u8bc1\u201d&#xff0c;\u6309\u7167\u63d0\u793a\u8981\u6c42\u6765\u5c31\u884c\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154426-6898be5a5ae23.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154426-6898be5a81e61.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5176\u6b21&#xff0c;\u4e0d\u9700\u8981\u8bbe\u7f6e\u8c37\u6b4c\u90ae\u7bb1\u7684POP\u6216\u8005IMAP\u3002\u5f88\u591a\u9648\u65e7\u7684\u6280\u672f\u535a\u5ba2\u8bf4\u8981\u5f00\u542fPOP\u6216\u8005IMAP&#xff0c;\u76ee\u524d&#xff08;2025\u5e748\u67086\u65e5&#xff09;\u662f\u4e0d\u9700\u8981\u8bbe\u7f6e\u7684&#xff0c;\u8c37\u6b4c\u90ae\u7bb1\u7684POP\u9ed8\u8ba4\u662f\u5173\u95ed\u72b6\u6001&#xff0c;IMAP\u9ed8\u8ba4\u662f\u5f00\u542f\u72b6\u6001&#xff0c;SMTP\u670d\u52a1\u8fde\u540cIMAP\u4e00\u8d77\u662f\u9ed8\u8ba4\u5f00\u542f\u3002<br \/>\n\u5982\u679c\u4f7f\u7528\u7684\u662f\u5176\u5b83\u90ae\u7bb1\u7684SMTP\u670d\u52a1\u53d1\u9001\u90ae\u4ef6&#xff0c;\u5219\u5177\u4f53\u4ee5\u5176\u5b83\u90ae\u7bb1\u7684\u8bf4\u660e\u4e3a\u51c6\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154426-6898be5ab6220.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u7136\u540e&#xff0c;\u5728\u8c37\u6b4c\u8bbe\u7f6e\u9875\u9762\u641c\u7d22\u6846\u4e2d\u641c\u7d22\u201c\u5e94\u7528\u4e13\u7528\u5bc6\u7801\u201d<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154427-6898be5b79384.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u7136\u540e\u968f\u4fbf\u8f93\u5165\u4e00\u4e2a\u540d\u79f0&#xff0c;\u70b9\u51fb\u521b\u5efa\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154427-6898be5bd3143.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n\u7136\u540e\u4f1a\u51fa\u73b0\u4e00\u4e2a16\u4f4d\u6570\u5b57\u7684\u5bc6\u7801&#xff0c;\u5176\u683c\u5f0f\u7c7b\u4f3c\u201caaaa bbbb cccc dddd&#034;&#xff0c;\u8fd9\u4e2a\u5bc6\u7801\u53ea\u51fa\u73b0\u4e00\u6b21&#xff0c;\u52a1\u5fc5\u8bb0\u4e0b\u6765\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154427-6898be5be89fc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u63a5\u7740\u8f6c\u5230Spring Boot\u7684\u914d\u7f6e\u6587\u4ef6&#xff08;\u6bd4\u5982application.properties)&#xff0c;\u5c06\u5bc6\u7801\u586b\u5230\u5982\u4e0b\u4f4d\u7f6e&#xff1a;<br \/>\nspring.mail.password&#061;aaaabbbbccccdddd<br \/>\n\u8fd9\u4e2a\u5bc6\u7801\u4e2d\u95f4\u4e0d\u8981\u6709\u4efb\u4f55\u7a7a\u683c&#xff0c;\u4e5f\u4e0d\u8981\u4f7f\u7528\u5f15\u53f7\u5305\u56f4\u3002\u6211\u6d4b\u8bd5\u7684\u65f6\u5019\u62a5\u9519&#xff0c;\u5c31\u662f\u56e0\u4e3a\u8fd9\u91cc\u51fa\u95ee\u9898\u4e86&#xff0c;\u8c37\u6b4c\u5b98\u65b9\u7ed9\u7684\u5bc6\u7801\u662f\u6709\u7a7a\u683c\u7684&#xff0c;\u9700\u8981\u628a\u7a7a\u683c\u5220\u6389\u3002<\/p>\n<p>\u5982\u679c\u8fd9\u4e2a\u5730\u65b9\u8bbe\u7f6e\u6210\u4e0b\u9762\u8fd9\u6837&#xff0c;\u5c31\u4f1a\u62a5\u9519&#xff1a;<br \/>\nspring.mail.password&#061;aaaa bbbb cccc dddd<br \/>\nspring.mail.password&#061;\u201caaaa bbbb cccc dddd\u201d<\/p>\n<p>\u6309\u7167\u4e0a\u9762\u914d\u7f6e\u540e&#xff0c;\u91cd\u542f\u670d\u52a1&#xff0c;\u7136\u540e\u6d4b\u8bd5&#xff0c;\u5c31\u80fd\u6536\u5230\u8c37\u6b4c\u53d1\u8fc7\u6765\u7684\u6d4b\u8bd5\u90ae\u4ef6\u4e86\u3002<\/p>\n<p>\u53c2\u8003\u535a\u5ba2&#xff1a;<br \/>\n\u5982\u4f55\u4f7f\u7528Gmail\u7684SMTP\u670d\u52a1\u5668\u53d1\u9001\u90ae\u4ef6&#xff1a;https:\/\/www.vpsdawanjia.com\/9613.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb763\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 Spring Boot \u53d1\u9001\u90ae\u4ef6\u7684\u6700\u5c0f\u5b8c\u6574\u793a\u4f8b\u3002\u8fd9\u4e2a\u793a\u4f8b\u4f7f\u7528 Gmail \u7684 SMTP \u670d\u52a1\uff0c\u53d1\u9001\u4e00\u5c01\u7b80\u5355\u7684\u7eaf\u6587\u672c\u90ae\u4ef6\u3002\u524d\u63d0\u8981\u6c42\uff1a\u4f7f\u7528idea\u7684\u5f15\u5bfc\u642d\u5efa\u4e00\u4e2aSpringBoot\u7684web\u9879\u76ee\u57fa\u7840\u6846\u67b6\u3002<\/p>\n","protected":false},"author":2,"featured_media":51514,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[98],"topic":[],"class_list":["post-51520","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/51520.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb763\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 Spring Boot \u53d1\u9001\u90ae\u4ef6\u7684\u6700\u5c0f\u5b8c\u6574\u793a\u4f8b\u3002\u8fd9\u4e2a\u793a\u4f8b\u4f7f\u7528 Gmail \u7684 SMTP \u670d\u52a1\uff0c\u53d1\u9001\u4e00\u5c01\u7b80\u5355\u7684\u7eaf\u6587\u672c\u90ae\u4ef6\u3002\u524d\u63d0\u8981\u6c42\uff1a\u4f7f\u7528idea\u7684\u5f15\u5bfc\u642d\u5efa\u4e00\u4e2aSpringBoot\u7684web\u9879\u76ee\u57fa\u7840\u6846\u67b6\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/51520.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-10T15:44:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154426-6898be5a5ae23.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51520.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/51520.html\",\"name\":\"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-10T15:44:29+00:00\",\"dateModified\":\"2025-08-10T15:44:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/51520.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/51520.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51520.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/51520.html","og_locale":"zh_CN","og_type":"article","og_title":"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb763\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 Spring Boot \u53d1\u9001\u90ae\u4ef6\u7684\u6700\u5c0f\u5b8c\u6574\u793a\u4f8b\u3002\u8fd9\u4e2a\u793a\u4f8b\u4f7f\u7528 Gmail \u7684 SMTP \u670d\u52a1\uff0c\u53d1\u9001\u4e00\u5c01\u7b80\u5355\u7684\u7eaf\u6587\u672c\u90ae\u4ef6\u3002\u524d\u63d0\u8981\u6c42\uff1a\u4f7f\u7528idea\u7684\u5f15\u5bfc\u642d\u5efa\u4e00\u4e2aSpringBoot\u7684web\u9879\u76ee\u57fa\u7840\u6846\u67b6\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/51520.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-10T15:44:29+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810154426-6898be5a5ae23.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/51520.html","url":"https:\/\/www.wsisp.com\/helps\/51520.html","name":"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-10T15:44:29+00:00","dateModified":"2025-08-10T15:44:29+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/51520.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/51520.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/51520.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u8c37\u6b4c\u90ae\u7bb1SMTP\u670d\u52a1\u5668\u8fde\u63a5\u5f02\u5e38\uff1aMailConnectException: Couldn\u2018t connect to host, port: smtp.gmail.com, 587"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=51520"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51520\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/51514"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=51520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=51520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=51520"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=51520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}