Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Robert Lalyko
Password Reset Mail - use other Email Address
June 23, 2012 4:28 PM
Answer

Robert Lalyko

Rank: New Member

Posts: 3

Join Date: February 8, 2012

Recent Posts

Hi all,
i'm stuck on the following Problem:
i need to send the Email with the Password Reset Link to an Mail Address of the user, which is stored in an Expando Attribute. Mail sending to arbitrary addresses can be done with the MailServiceUtil, so far so good. I use this in a custom BaseStrutsPortletAction as a Hook.
But i need the Mail Body with the actual link to reset your Password, and this is the Problem. I had a look in the forgotPasswordAction and there the body is retrieved via PortletPreferences. If i do this in my custom BaseStrutsPortletAction i get null. Has anyone an idea how to get the Mail Content? Maybe by using another Util-Class?
Many thanks and regards,
Robert
Jelmer Kuperus
RE: Password Reset Mail - use other Email Address
June 23, 2012 6:31 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Try getting the preferences like this

1PortletPreferences preferences =  PortletPreferencesFactoryUtil.getPortletSetup(request, PortletKeys.LOGIN);


Btw the behaviour of UserLocalService.sendPassword is such that if the preference is null the body is loaded from portal properties. So if its unset you must do this :

1PrefsPropsUtil.getString(PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_BODY);
Robert Lalyko
RE: Password Reset Mail - use other Email Address
June 24, 2012 3:06 AM
Answer

Robert Lalyko

Rank: New Member

Posts: 3

Join Date: February 8, 2012

Recent Posts

Hi Jelmer,
at first thanks for your answer. I tried the way you posted to get the PortletPreferences, but they are still null emoticon.
The second snippet you've posted leads to "com/liferay/portlet/admin/dependencies/email_password_reset_body.tmpl", i guess that's the template Name. But how can i now get the Template content and fill it with the right params (reset link etc.)?
For sending email i use the MailServiceUtil, where i just can pass a body as plain String, so the message body has to be constructed before. I want to use the default Email Reset Notification Message...

1
2String body = <READ FROM TEMPLATE???>
3String subject = <READ FROM TEMPLATE???>
4
5InternetAddress to = new InternetAddress( alternativeEmailAddress, user.getFirstName() + StringPool.SPACE + user.getLastName() );
6InternetAddress from = new InternetAddress( admin.getEmailAddress(), admin.getFirstName() + StringPool.SPACE + user.getLastName() );
7MailMessage message = new MailMessage( from, to,subject, body, true );
8MailServiceUtil.sendEmail( message );


Thanks and regards,
Robert
Jelmer Kuperus
RE: Password Reset Mail - use other Email Address
June 24, 2012 7:10 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Ah.. Meh

Take a look at what i do in the code of this post http://www.liferay.com/community/forums/-/message_boards/message/6436989 then
Robert Lalyko
RE: Password Reset Mail - use other Email Address
June 24, 2012 10:26 AM
Answer

Robert Lalyko

Rank: New Member

Posts: 3

Join Date: February 8, 2012

Recent Posts

Hi Jelmer,
thanks for your post. I'm now able to get the Forgot Email Template and i want to fill it like you posted through String replace. The only thing i'm now missing is the generated reset link. Is there a service that generates this link or where can i get it from? I searched a lot with google but found nothing...
Many thanks and regards,
Robert
Jelmer Kuperus
RE: Password Reset Mail - use other Email Address
June 24, 2012 11:57 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Something like this should do it :


 1ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
 2
 3Ticket ticket = TicketLocalServiceUtil.addTicket(
 4    companyId, User.class.getName(), userId,
 5    TicketConstants.TYPE_PASSWORD, null, expirationDate,
 6    serviceContext);
 7
 8String passwordResetURL =
 9    serviceContext.getPortalURL() + serviceContext.getPathMain() +
10        "/portal/update_password?p_l_id="+
11            serviceContext.getPlid() +
12                "&ticketKey=" + ticket.getKey();