掲示板

mail configuration and velocity template for email

10年前 に Anu malik によって更新されました。

mail configuration and velocity template for email

New Member 投稿: 18 参加年月日: 13/12/05 最新の投稿
LoadProprtiesValue loadValues=new LoadProprtiesValue();
loadValues.readConfig();
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host",smtp.gmail.com);//add other smtp server like gmail
props.put("mail.smtp.port", "25");
//Session session = Session.getInstance(props);
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,pswd);//set username pswd for authentication
}
});

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(Constants.setFrom));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("example@liferay.com"));// set email Address

message.setSubject("Example to send message");

message.setText(content);
Transport.send(message);

/* if u want to create a template for email using velocit template
// first, get and initialize an engine

VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
ve.init();


VelocityContext velocityContext = new VelocityContext();
velocityContext.put("NAME",firstName);
velocityContext.put("TAGLINE",tagline.getNextTagLines());
velocityContext.put("MOBILE",PersonalPhone );
velocityContext.put("EMAIL",emailidd );
velocityContext.put("DATE",showDate );
StringWriter writer = new StringWriter();

ve.mergeTemplate("templates/visitrequest11.vm" , "UTF-8", velocityContext, writer);
String content = writer.getBuffer().toString();

message.setContent(content, "text/html");

// Send message
Transport.send(message);
*/

Regards ,
Anu