Thursday, May 22, 2014

Method to configure the Email in Liferay Server:

1. Login with valid username and password with following URL:

http://localhost:8087/c/portal/login


2. Go to Control Panel

3. Go to Server >> Server Administration 

4. Click on Mail Tab.

5. Fill the required information as mentioned below.



6.  Now the configuration is ready. 
7. User following method to send mail.

public static void sendEmail(String mailBody,String mailSubject) {
String senderMailAddress = "surendra84@gmail.com";
String receiverMailAddress = "surendra84@gmail.com";
try {
MailMessage mailMessage = new MailMessage();
mailMessage.setBody(mailBody);
mailMessage.setSubject(mailSubject);
mailMessage.setFrom(new InternetAddress(senderMailAddress));
mailMessage.setTo(new InternetAddress(receiverMailAddress));
MailServiceUtil.sendEmail(mailMessage);
} catch (Exception e) {
e.printStackTrace();
}
}

8. Now deploy the portlet and cann the defined method inside portlet to send the information.

This part is working fine for me.

Second scenario:

This section shows how to configure the SMTP server with an email address in Apache Tomcat. 
In the file: $LP/conf/Catalina/localhost/ROOT.xml 

}}} 
If you are using a Gmail account you should do the following: 
name="mail/MailSession"
auth="Container"
type="javax.mail.Session"
mail.imap.host="localhost"
mail.pop.host="localhost"
mail.store.protocol="imap"
mail.transport.protocol="smtp"
mail.smtp.host="smtp.gmail.com"
mail.smtp.port="465"
mail.smtp.auth="true"
mail.smtp.starttls.enable="true"
mail.smtp.user="username"
password="*****"
mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
/>


No comments: