Foren
Not able to send mail from liferay hook
saurab rajkarnikar, geändert vor 11 Jahren.
Not able to send mail from liferay hook
New Member Beiträge: 2 Beitrittsdatum: 03.04.13 Neueste Beiträge
I am trying to send email from a hook I have using both MailEngine and MailServiceUtil, but I have not yet been able to send it. My code is as below :
In this I am getting the following error,
I found a mail.jar file in my liferay installation but I am not able to use it. I tried importing javax.mail in my pom file with artifactid com.sun but still get this error. Does anybody here know what the problem is ?
Thanks
InternetAddress from=null;
InternetAddress to=null;
try {
from = new InternetAddress("test@test.com", "Admin admin");
to = new InternetAddress(newUser.getEmailAddress(), newUser.getFirstName());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MailMessage mailMessage = new MailMessage();
mailMessage.setFrom(from);
mailMessage.setTo(to);
mailMessage.setBody(body);
mailMessage.setSubject(subject);
MailServiceUtil.sendEmail(mailMessage);
In this I am getting the following error,
java.lang.LinkageError: loader constraint violation: when resolving method "com.liferay.portal.kernel.mail.MailMessage.setFrom(Ljavax/mail/internet/InternetAddress;)V" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, com/lftechnology/sbworkbench/hooks/createaccount/CustomCreateAccountAction, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, com/liferay/portal/kernel/mail/MailMessage, have different Class objects for the type javax/mail/internet/InternetAddress used in the signature
I found a mail.jar file in my liferay installation but I am not able to use it. I tried importing javax.mail in my pom file with artifactid com.sun but still get this error. Does anybody here know what the problem is ?
Thanks
Siby Mathew, geändert vor 11 Jahren.
RE: Not able to send mail from liferay hook
Expert Beiträge: 268 Beitrittsdatum: 04.03.11 Neueste Beiträge
Hi Saurab,
This seems to be a jar file issue.
I am using the mail.jar from tomcat/lib/ext folder. Cant you use the same ?
Thanks,
Siby
This seems to be a jar file issue.
I am using the mail.jar from tomcat/lib/ext folder. Cant you use the same ?
Thanks,
Siby
saurab rajkarnikar, geändert vor 11 Jahren.
RE: Not able to send mail from liferay hook
New Member Beiträge: 2 Beitrittsdatum: 03.04.13 Neueste BeiträgeSiby Mathew:
Hi Saurab,
This seems to be a jar file issue.
I am using the mail.jar from tomcat/lib/ext folder. Cant you use the same ?
Thanks,
Siby
I am not able to use that, my portlet is a maven project and need to add the library to a pom.xml file. So I cannot add the external jar to my project.
Paul Gloessl, geändert vor 10 Jahren.
RE: Not able to send mail from liferay hook
New Member Beiträge: 12 Beitrittsdatum: 15.07.13 Neueste Beiträge
Hi,
if you still have this problem one solution would be adding the jar as provided dependency (see this tutorial ) .
Another solution, in my opionion the better one, would be using the Liferay Message Bus through the SubscriptionSender class (see here)
if you still have this problem one solution would be adding the jar as provided dependency (see this tutorial ) .
Another solution, in my opionion the better one, would be using the Liferay Message Bus through the SubscriptionSender class (see here)
Rahul Pande, geändert vor 11 Jahren.
RE: Not able to send mail from liferay hook
Expert Beiträge: 310 Beitrittsdatum: 07.07.10 Neueste Beiträge
Hi Saurabh,
Please try following code for creating mail message.
HTH
Rahul
Please try following code for creating mail message.
InternetAddress from = new InternetAddress({Email address}, {From name});
InternetAddress to = new InternetAddress({Email address}, {To name});
MailMessage message = new MailMessage(from, to, {Email subject}, {Email body}, {Send as html or plain text : true / false});
MailServiceUtil.sendEmail(message);
HTH
Rahul