0

My need is I want to use any kind of loop in setContent() but as it is a method, I am not allowed to do this. So do you have any alternate method for doing this?

Look into my code below

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

Can anyone please tell me that how can I pass dynamic content in message.setContent()

krlzlx
  • 5,752
  • 14
  • 47
  • 55
vivek
  • 1
  • 2
  • Possible duplicate of [How do I send an HTML email?](http://stackoverflow.com/questions/5068827/how-do-i-send-an-html-email) – gtonic Oct 16 '16 at 19:20
  • My question is different sir, What I want to do, I just want to pass dynamic contents in setContent(). Moreover my need is I want to use any kind of loop in setContent() but as it is a method, I am not allowed to do this. So do you have any alternate method for doing this? – vivek Oct 17 '16 at 09:52

1 Answers1

0

I guess, you are looking for velocity template engine:

Velocity Email Templates * Link 1

Velocity Email Templates * Link 2

Community
  • 1
  • 1
Nitish Raj
  • 137
  • 1
  • 2
  • 12