I have attached my example source here. I have a html template and path in system. My objective is need to send the HTML template with message in mail. But i have to append the HTML message using html path. How to do this.
public class SendMail {
public void sendingEmailToClient(String sEmail,String sUserName,String htmlPath) throws Exception{
String fromMerchant=null;
String merchantPassword=null;
String toClientMail=null;
String userName=null;
String smtp=null;
String smtpServer=null;
String smtpSocketFactory=null;
String smtpPort=null;
String socketFactoryClass=null;
String sslSocketFactory=null;
String smtpAuthentication=null;
String smtpAuthenticateState=null;
String mailSmtpPort=null;
if(sEmail!=null && !sEmail.isEmpty() && sUserName !=null && !sUserName.isEmpty()){
toClientMail=sEmail;
userName=sUserName;
System.out.println("The user name is ==>"+userName);
fromMerchant="[email protected]";
merchantPassword="passw0rd";
Properties properties=new Properties();
smtp="mail.smtp.host";
smtpServer="smtp.gmail.com";
smtpSocketFactory="mail.smtp.socketFactory.port";
smtpPort="465";
socketFactoryClass="mail.smtp.socketFactory.class";
sslSocketFactory="javax.net.ssl.SSLSocketFactory";
smtpAuthentication="mail.smtp.auth";
smtpAuthenticateState="true";
mailSmtpPort="mail.smtp.port";
properties.put(smtp,smtpServer);
properties.put(smtpSocketFactory, smtpPort);
properties.put(socketFactoryClass, sslSocketFactory);
properties.put(smtpAuthentication, smtpAuthenticateState);
properties.put(mailSmtpPort,smtpPort);
Session session=Session.getDefaultInstance(properties,new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication ("[email protected]","passw0rd");
}
});
try{
MimeMessage message=new MimeMessage(session);
message.setFrom(new InternetAddress("LoyaltyCart"));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(toClientMail));
message.setText(" Hi "+userName+"\n You have successfully registered on YourShopping !!.. \n We heartly welcomes you and save your money, buy new products...");
**//Need to append the HTML template using file path with message like message.setHTMLTemplate**
Transport.send(message);
System.out.println("message sent successfully");
message.setText("You have successfully registered on YourShopping !!..");
message.setText("We heartly welcomes you and save your money, buy new products...");
}catch(Exception e){
throw new RuntimeException(e);
}
}
}}