向用户发送自动电子邮件

问题描述

我想每月(第28天)发送一次自动电子邮件。在本地该方法有效并且已发送电子邮件,但是当我在服务器上部署该应用程序时,发送电子邮件方法不起作用,因此该电子邮件不会发送给用户
我不知道出什么问题了?

注意:云上的prod数据库(putty)。
该应用程序可以在prod上运行,并且没有出现任何问题,但是发送电子邮件方法不起作用,因为它不发送电子邮件

   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);  
                 }
                  
           } 

sendMail方法

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);
        
}

application.properties:

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)