Pages

Hot News

Showing posts with label Liferay. Show all posts
Showing posts with label Liferay. Show all posts

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. :)



Saturday, 19 April 2014

Display Webcontent in JSP?

Hi guys,

There are many way to display webcontent in jsp.
Here, I am explaining  two easiest way.

First Way :
If you are thinking to display web content in JSP page, Its only 2 steps you follow as given below :


Step 1.

Put Below configuration in " portal-ext.properties " :

article.name=YourJournalArticleName
no.actical.text=No Article Exists with this name.

Step 2.
Put Below code inside your jsp.
JSP File : 

<%
String content = StringPool.BLANK;
try{ 
String articleName = PropsUtil.get("article.name");

JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);
String articleId = journalArticle.getArticleId(); 
JournalArticleDisplay articleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScoprGroupId(), articleId,"","",themeDisplay);
content = articleDisplay.getContent();
}Catch(Exception e){
content = PropsUtil.get("no.article.text");
}
%>

<%= content %>

*Note: In this way you required to restart server because we have updated portal-ext.properties file.

 ----------------------------------------------------------------------------------------------------------------------------------

Alternate cool option to display webcontent in jsp as:

Follow the list of below steps.
Step 1:

Put below code inside your java class.
For retrieve the wecontentid  and  GroupId.

 long lGroupId = themeDisplay.getScopeGroupId();
String lGroupName = themeDisplay.getScopeGroupName();


JournalArticle jArticleId = JournalArticleLocalServiceUtil.getArticleByUrlTitle(

lGroupId, "webcontentname");

renderReq.setAttribute("lGroupId", lGroupId);
renderReq.setAttribute("jArticleId", jArticleId.getArticleId());

Step 2:

Put below code inside your jsp.


<liferay-ui:journal-article articleId="${jArticleId}"

groupId="${lGroupId}" />

*Note: If we are follow the above way then we don't required to restart the server.

That's all !!

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

Thursday, 17 April 2014

Cognos Integration with Liferay Portal.


There are two easiest way from which we can achieve this things.

1. IFrame
2. WSRP

1. IFrames:
  • This is one of the easier options
  • It is very useful when you have lots of things to expose or to display third party data.
  • It provides loose-coupling between Portal and Cognos so as reports change the Portal doesn't need to change
Implementation way:
  • The portlet will be accessible to logged in user only. Either This portlet has been developed as a custom portlet using Plugins-SDK or OOB Iframe portlet.
  • To display third party data in iframe so used iFrame to achieve this functionality. The information is being fetched by the web services.
  • Using Iframe in cognos-integration-portlet makes it possible to embed another HTML page inside the current page.  
  • Furthermore the user can navigate through the embedded page without loosing the context of the portal page.

The configurations for this portlet are stored in portlet.properties file under WEB-INF/src folder. Here is a reference of the same:

cognos.page.targeturl =
cognos.graphic.format=


2. WSRP:
  • You can expose cognos portlets running on a WebSphere server as a WSRP (Web Services for Remote Portlets) producer.
  • In your portal, you can consume the cognos portlets via the OOB WSRP portlet .
  • This provides a good level of decoupling because the Cognos portlets can run on a separate WAS server from your Portal server.

That's it!!:)