留言板

Hook between new user account and mail portlet?

thumbnail
Wen Ching Chua,修改在12 年前。

Hook between new user account and mail portlet?

Junior Member 帖子: 72 加入日期: 11-4-18 最近的帖子
Hi everyone,

Is it possible to create a hook to do this? or plugin or something similar?

When I create an user account, it will have access to a mail portlet via user group & site templates. The user account will have the same email and password with my gmail account. Each time I create an user account, i need to manually configure in the mail settings. Is okay if it is small amount of users, but very tedious when i need to add a lot of users.

Is there a way to automate this creation and linkage to the mail portlet? Someone suggested service hooks, but I am not sure how to start?

Any tips or guides on this one?

Thanks.
thumbnail
Anil Sunkari,修改在12 年前。

RE: Hook between new user account and mail portlet?

Expert 帖子: 427 加入日期: 09-8-12 最近的帖子
Myself also waiting for the response on the above requirement .
Thanks Wen
thumbnail
Leo Pratlong,修改在12 年前。

RE: Hook between new user account and mail portlet?

Expert 帖子: 363 加入日期: 10-7-6 最近的帖子
Hi,

I'm not sure to have understand what you just explained. But here is a way to send e-mail using JavaMail:


private static String fromName;
    private static String fromAddress;
    static {
        try {
            fromName = PrefsPropsUtil.getString(PropsKeys.ADMIN_EMAIL_FROM_NAME);
            fromAddress = PrefsPropsUtil.getString(PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
        } catch (Exception ex) {
            LOG.error("Please, configure Mail and SMTP parameters on your Control Panel.");
            fromName = "";
            fromAddress = "";
        }
    }

private void sendEMail(final String body, final String object, final List<string> emailaddresss)
        throws PortletException, IOException, AddressException {
        
        final InternetAddress from = new InternetAddress(fromAddress, fromName);
        for (final String email : emailaddresss) {
            final InternetAddress to = new InternetAddress(email);
            final MailMessage mailMessage = new MailMessage(from, to, object, body, true);
            MailServiceUtil.getService().sendEmail(mailMessage);
        }
}
</string>


You can use this code in a plugin Ext with an override of a Liferay class.
thumbnail
Ravi Kumar Gupta,修改在12 年前。

RE: Hook between new user account and mail portlet?

Liferay Legend 帖子: 1302 加入日期: 09-6-24 最近的帖子
Wen Ching Chua:
Someone suggested service hooks, but I am not sure how to start?


Hi,

Most probably I did not get a clear idea of what you want to do. But looks like whenever a user is created you want to achieve some more. Like you want to create something automatically. And the quoted line also gives me the same hint.

For that one solution can be to create hook. Create a hook so that whenever a new user is added to the system you will be able to perform some operation.
You need to write a class like this

package me.rkg.hooks;

import com.liferay.portal.ModelListenerException;
import com.liferay.portal.model.ModelListener;
//import com.liferay.portal.model.User;

public class UserHook implements ModelListener {

    public void onAfterCreate(Object model) throws ModelListenerException {
        //Add your implementation here
        com.liferay.portal.model.User mdlObj 
                = (com.liferay.portal.model.User) model;
    }

    public void onAfterAddAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
        //Add your implementation here
    }

    public void onAfterRemove(Object model) throws ModelListenerException {
        //Add your implementation here
    }

    public void onAfterRemoveAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
        //Add your implementation here
    }

    public void onAfterUpdate(Object model) throws ModelListenerException {
        //Add your implementation here
    }

    public void onBeforeAddAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
        //Add your implementation here
    }

    public void onBeforeCreate(Object model) throws ModelListenerException {
        //Add your implementation here
    }

    public void onBeforeRemove(Object model) throws ModelListenerException {
        //Add your implementation here
    }

    public void onBeforeRemoveAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
        //Add your implementation here
    }

    public void onBeforeUpdate(Object model) throws ModelListenerException {
        //Add your implementation here
    }

}


Add a portal.properties in the same hook war and use the following property

value.object.listener.com.liferay.portal.model.User=me.rkg.hooks.UserHook

After this whenever a user is created control will come to onAfterCreate() method where you can write your custom code.

I hope this helps

Regards
Ravi Kumar Gupta