java - 向用户发送自动电子邮件
问题描述
我想每月(第 28 天)发送一封自动电子邮件。在本地,该方法有效并发送了电子邮件,但是当我在服务器上部署应用程序时,发送电子邮件的方法不起作用,因此电子邮件不会发送给用户。
不知道是什么问题??
注意:云上的 prod 数据库(putty)。
该应用程序在产品上运行并且没有显示任何问题,但是发送电子邮件的方法不起作用,因为它不发送电子邮件
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootHelloWorldApplication.class, args);
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/...","name database","password");
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
int day = calendar.get(Calendar.DATE);
if(day == 28) {
Statement ccf = con.createStatement();
ResultSet ddj = ccf.executeQuery("SELECT gestion_cra.employe.email FROM gestion_cra.employe");
while(ddj.next()) {
String mel = ddj.getString("email");
JavaMailUtil.senMail(mel);
}
}
方法发送邮件:
public static void senMail(String recepiant) throws MessagingException {
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", "send.one.com");
properties.put("mail.smtp.port", "587");
String MyAccountEmail = "mail";
String Password ="password";
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(MyAccountEmail, Password);
}
});
Message message = prepareMessage(session, MyAccountEmail, recepiant);
Transport.send(message);
}
应用程序属性:
jwt.secret=....//
jwt.get.token.uri=/login
spring.datasource.url = jdbc:mysql://localhost:3306/...
spring.datasource.initialization-mode=always
spring.jpa.hibernate.ddl-auto = update
spring.datasource.username = //name of database
spring.datasource.password = //password
server.address=0.0.0.0
解决方案
推荐阅读
- wordpress - 无法编辑我的 wordpress 页脚背景颜色
- node.js - 通过node js上传数据到redshift
- java - 在 vSphere 环境中部署 Spring Web 应用程序
- html - 练习带复选框的字段集
- database - PostgresSQl 11 PITR 恢复 - 不恢复所有可用的 Wal 文件
- spring-boot - Jacoco 测试报告不包括 integrationTest
- java - 你如何在java中正确导入文件?
- node.js - 如何将 metamask 与 ethers.js 连接并获取余额?
- c# - 如何将zip文件发送到api
- sql - 标记 BigQuery 表中前 20% 的记录