我正在使用以下代码用 Java 发送电子邮件。我没有收到任何错误,但电子邮件似乎没有到达(即使是垃圾邮件,我已经等了将近一天了)
List<SimpleMailMessage> messages = new ArrayList<>();
...
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost("smtp.gmail.com");
sender.setPort(587);
sender.setUsername("mysecretemail@gmail.com");
sender.setPassword("mysecretpassw0rd");
sender.setProtocol("smtp");
Properties mailProperties = new Properties();
mailProperties.setProperty("mail.smtp.auth", "true");
mailProperties.setProperty("mail.smtp.starttls.enable", "true");
mailProperties.setProperty("mail.smtp.quitwait", "false");
mailProperties.setProperty("mail.debug", "true");
sender.setJavaMailProperties(mailProperties);
sender.send(messages.toArray(new SimpleMailMessage[messages.size()]));