在java email API中发送动态内容(重复数据)

时间:2016-10-16 19:08:39

标签: java html email-templates

我的需要是我想在setContent()中使用任何类型的循环,但由于它是一种方法,我不允许这样做。那么你有没有其他方法来做到这一点?

查看下面的代码

String to = ""; //change accordingly

//Get the session object  
Properties props = new Properties();  
props.put("mail.smtp.host", "smtp.gmail.com");  
props.put("mail.smtp.socketFactory.port", "465");  
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");  
props.put("mail.smtp.auth", "true");  
props.put("mail.smtp.port", "465");                            

Session sessions = Session.getDefaultInstance(props,new javax.mail.Authenticator()
{
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication("", ""); //change accordingly  
    }  
});         

MimeMessage message = new MimeMessage(sessions);  
message.setFrom(new InternetAddress("")); //change accordingly  
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));  
message.setSubject("sai");       
message.setContent("Here we can pass html format including css","text/html");

Transport.send(message);

任何人都可以告诉我如何在message.setContent()

中传递动态内容

1 个答案:

答案 0 :(得分:0)

我想,你正在寻找速度模板引擎:

Velocity Email Templates * Link 1

Velocity Email Templates * Link 2