Pages

Hot News

Wednesday 5 August 2015

Email send in Liferay through JavaMail API?

Hi Guys,

Let's get a very brief idea about mail send in Liferay.

Email is an integral part of business communication.
Java offers the JavaMail API to make possible email communication from our applications easily.
It is a platform- and protocol-independent framework built as a part of the Java EE spectrum of web/enterprise application development.

The JavaMail API is a set of abstract classes defining the objects that comprise a mail system.

The Protocol of JavaMail

Protocol literally means maintaining certain norms, code of conduct, and so on.

Creating an application with email support is as simple as any Java programming, but the technical aspects behind the scene are quite intriguing and require some understanding of network protocols.

Let's get an idea of protocols supported by the JavaMail API.

SMTP - To supports the mechanism to deliver email.
POP - Mailbox mechanism use on the Internet to get mails.
IMAP - An advanced protocol for receiving messages, multiple mailbox support, mailbox sharing, and so forth.
MIME -It's concerned with the content of the message transfer such as message format, attachments, and so on.

 In liferay its pretty easy to do configuration.

1. GMAIL Configuration,

mail.session.mail.store.protocol=imap
mail.session.mail.transport.protocol=smtp

#smtp properties
mail.session.mail.smtp.host=smtp.gmail.com
mail.session.mail.smtp.password=_PASSWORD
mail.session.mail.smtp.user=_USEREMAILADDRESS

mail.session.mail.smtp.port=465
mail.session.mail.smtp.auth=true
mail.session.mail.smtp.starttls.enable=true
mail.session.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

mail.session.mail.smtp.socketFactory.fallback=false
mail.session.mail.smtp.socketFactory.port=465
# Other protocols mail.session.mail.imap.host=localhost
#mail.session.mail.pop3.host=localhost
#mail.session.mail.pop.host=smtp.gmail.com

2. Office 365 Configuration,

portal.host=_USEREMAILADDRESS
portal.password=_PASSWORD
mail.smtp.host=smtp.office365.com
mail.smtp.socketFactory.port=587
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.auth=true
mail.smtp.port=587
mail.smtp.starttls.enable=true

You can read these properties via portal-ext.properties in your class through PropsUtil.get() Method.

Please take note as,  I am showcase demo only for Office365 Mail.

Let's Create Utility class and define method.

MailSendHelper.java

public final class MailSendHelper {

private MailSendHelper(){}

public static void sendEmail(InternetAddress from,InternetAddress to, String subject, String bodyContent) {
final String userEmail = PropsUtil.get("portal.host");
final String password = PropsUtil.get("portal.password");
Session mailSession = null;
Properties props = new Properties();
props.put("mail.smtp.host","smtp.office365.com");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", true);
props.put("mail.smtp.ssl.trust", "smtp.office365.com");
props.put("mail.debug", true);

mailSession = Session.getInstance(props,
     new javax.mail.Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(userEmail ,password );
     }
});  try {
Message message = new MimeMessage(session);
message.setFrom(from);
message.setRecipient(Message.RecipientType.TO, to);
message.setSubject(subject);
message.setContent(bodyContent, "text/html; charset=utf-8");
Transport.send(message);
LOG.info("DONE");
} catch (MessagingException e) {
LOG.error("Error occured in MailSendHelper",e);
}
}
private static final Log LOG = LogFactoryUtil.getLog(MailSendHelper.class);
}

JAVAMail API Download from this location: http://www.oracle.com/technetwork/java/javamail/javamail145-1904579.html

Hope this article will help you. :)



Monday 25 May 2015

EBS Payment integration with Liferay Portal

Hi Guys,

Today, I am going to represent and explain you how to integrate payment system in Liferay Portal

Please find the attached document and refer it. Then follow below instructions for EBS payment integration with Liferay Portal.

Step 1,

public class FLEBSIntegrationConstants {
public static final String ACTION_PAYMENT = "ebsPaymentResponse";
public static final String PAGE_PAYMENT = "/html/flebsintegration/pay.jsp";
public static final String PAGE_SUCCESS = "/html/flebsintegration/success.jsp";
public static final String PAGE_RESPONSE = "/html/flebsintegration/response.jsp";
public static final String RESPONSE = "response.jsp";
}

Step 2,

Create view.jsp in your portlet

This is the <b>Flebs Integration</b> portlet in View mode.
<portlet:renderURL var="ebsPaymentURL">
<portlet:param name="jspPage" value="<%=FLEBSIntegrationConstants.PAGE_PAYMENT %>" />
</portlet:renderURL>

<br />
<a href="${ebsPaymentURL}">Click Here for Payment &raquo;</a>

Step 3,
In controller class, Action Method of Pay.jsp
/*
* i. Credentials to test the payment
Card Number – 4111111111111111
Expiry – 07/16
CVV – 123
Bank – EBS

   ii.  Payment Request URL:
Test – https://testing.secure.ebs.in/pg/ma/sale/pay
Production – https://secure.ebs.in/pg/ma/sale/pay

or

Test – https://testing.secure.ebs.in/pg/ma/sale/vpc
Production – https://secure.ebs.in/pg/ma/sale/vpc

   iii. Merchant Login URL
Test – https://testing.secure.ebs.in
Production – https://secure.ebs.in

* API Request URL
* Test – https://testing.secure.ebs.in/api/1_0
* Production – https://secure.ebs.in/api/1_0
*/

public void ebsPaymentResponse(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String DR = (String)actionRequest.getParameter("DR");
System.out.println("---------DR-----------" +DR);

/////
String key = "ebskey"; //Your Secret Key
StringBuffer data1 = new StringBuffer().append(DR);
for (int i=0; i < data1.length(); i++){
if(data1.charAt(i)== ' ')
data1.setCharAt(i,'+');
}
Base64 base64 = new Base64();
byte[] data = base64.decode(data1.toString());
RC4 rc4 = new RC4(key);
byte[] result = rc4.rc4(data);


ByteArrayInputStream byteIn = new ByteArrayInputStream (result, 0, result.length);
DataInputStream dataIn = new DataInputStream (byteIn);
String recvString1 = "";
String recvString = "";
recvString1 = dataIn.readLine();
int i =0;
while(recvString1 != null ){
i++;
if(i > 705) break;
recvString += recvString1 + "\n";
recvString1 = dataIn.readLine();
}
recvString  = recvString.replace( "=&","=--&" ) ;
System.out.println("--------RECVSTR---------" +recvString);
////
StringTokenizer st = new StringTokenizer(recvString, "=&");
String field ,val;
while(st.hasMoreTokens()) {
field = st.nextToken();

val = st.nextToken();

System.out.print(field+" :--->");
System.out.println(val);

}

PortalUtil.copyRequestParameters(actionRequest, actionResponse);
actionResponse.setRenderParameter("mvcPath", FLEBSIntegrationConstants.RESPONSE);

}

Step 4, response.jsp

hello, <%=request.getParameter("DR")%>



That's All !!
Let me know if u have any suggestions/queries, I would like to hear from your side.