Foren

MailEngine.send() not useable?

François LE QUEMENER, geändert vor 14 Jahren.

MailEngine.send() not useable?

Junior Member Beiträge: 48 Beitrittsdatum: 18.09.09 Neueste Beiträge
Hi,
I'm tryiong to send emails in Liferay. I use MailEngine.send(from, to, subject, body); but then Eclipse tells me there is an exception that is unhandled:
Unhandled exception type MailEngineException

Smart as I am, I add the try/catch block :
		try {
			MailEngine.send(from, to, subject, body);
		} catch (MailEngineException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


Now, Eclipse tells me:
No exception of type MailEngineException can be thrown; an exception type must be a subclass of Throwable

I am developing this hook in an external eclipse project. I tried to copy the source file in the Liferay plugin SDK and it goes well. So I thought about a wrong version of util-java.jar, but I'm using the 5.2.2.

Do you see what's going on?

Thanks
vcvijayan MCA, geändert vor 14 Jahren.

RE: MailEngine.send() not useable?

thumbnail
Pravin Pawar, geändert vor 14 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 62 Beitrittsdatum: 17.11.09 Neueste Beiträge
MailMessage message = new MailMessage(from, to, subject, mailBody, true);


How can we use MailService to send email for Multiple Recipient?

So I have used MailEngine class for that.
MailEngine.send(fromInternetAddress, toInternetAddresses, subject, body.toString()) method of MailEngine class.
Where toInternetAddresses is declared as an array of InternetAddress.

This method is working well with one of our custom portlet.
thumbnail
N. Belo, geändert vor 14 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 33 Beitrittsdatum: 17.03.09 Neueste Beiträge
Hi,

where can I find InternetAddress class???

Thx,
NB
thumbnail
Pravin Pawar, geändert vor 13 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 62 Beitrittsdatum: 17.11.09 Neueste Beiträge
InternetAddress class comes with JavaMail API. You can import this class as javax.mail.internet.InternetAddress.

You can declare the InternetAddress array like this way to send the mail to multiple receipents...


InternetAddress[] toInternetAddresses =
	new InternetAddress[] {new InternetAddress(toEmailAddress)};
thumbnail
N. Belo, geändert vor 13 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 33 Beitrittsdatum: 17.03.09 Neueste Beiträge
Hi Pravin,

Thank you for your reply but I've already imported the JavaMail API from /tomcat-6.0.18/lib/ext/mai.jar

and got this error:

11:00:41,820 ERROR [jsp:165] java.lang.LinkageError: loader constraints violated when linking javax/mail/internet/InternetAddress class

The error is caused by this line of code:

MailMessage message = new MailMessage(from, to, subject, mailBody, true);


If I use the other method, I don't know how to handle the MailEngineException because it's not a Throwable exception

try {
MailEngine.send(fromAddress, toAddress, subject, body);
} catch (MailEngineException ex) {
Logger.getLogger(FileMng.class.getName()).log(Level.SEVERE, null, ex);

}

Sorry, about this, but i've done a lot of code for this project and this issue about emails doesn't make sense.

Thank you.
BR,
N.
thumbnail
Pravin Pawar, geändert vor 13 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 62 Beitrittsdatum: 17.11.09 Neueste Beiträge
Please see the below code which I have used to send the mail, which can help you!

protected void addTimesheet(ActionRequest actionRequest) throws Exception {		    
   try{
        long userId = ParamUtil.getLong(actionRequest, "userId");
	long managerId = ParamUtil.getLong(actionRequest, "managerId");
        User user = UserLocalServiceUtil.getUserById(userId);	
        User managet = UserLocalServiceUtil.getUserById(managerId);	

	InternetAddress fromInternetAddress = new InternetAddress(user.getEmailAddress(), user.getFullName());
	InternetAddress[] toInternetAddresses = new InternetAddress[]{new InternetAddress(manager.getEmailAddress())};
			
	String subject = user.getFullName()+" Timesheet";
	StringBuffer body = new StringBuffer();
	
	body.append("Dear Sir,\n");
	body.append("I have completed all the task specified in the timesheet and requesting ");
	body.append("for approve the timesheet. \n");
	body.append("Let me know if you have any question. \n");
	body.append("\n");
	body.append("Thanks,\n");
	body.append(user.getFirstName());
	if (_log.isDebugEnabled()) {
		_log.debug("Sending email to " + toInternetAddresses);
	}
			
	MailEngine.send(fromInternetAddress, toInternetAddresses, subject, body.toString());
			
   }catch(Exception e){
       if (_log.isErrorEnabled()) {
           _log.error(e.getMessage(), e);
   }
}
thumbnail
N. Belo, geändert vor 13 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 33 Beitrittsdatum: 17.03.09 Neueste Beiträge
Ok, and how can I handle this Exception problem... (please, see attached image)

Thanks,
N.
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: MailEngine.send() not useable?

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
MailEngineException extends from org.apache.commons.lang.exception.NestableException, do you have commons-lang on your classpath ?
Rubén García Tamayo, geändert vor 12 Jahren.

RE: MailEngine.send() not useable?

New Member Beiträge: 7 Beitrittsdatum: 10.10.11 Neueste Beiträge
jelmer kuperus:
MailEngineException extends from org.apache.commons.lang.exception.NestableException, do you have commons-lang on your classpath ?


Thank you very much jelmer!! this works pretty good!!!
thumbnail
Achmed Tyrannus Albab, geändert vor 10 Jahren.

RE: MailEngine.send() not useable?

Regular Member Beiträge: 158 Beitrittsdatum: 05.03.10 Neueste Beiträge
Rubén García Tamayo:
jelmer kuperus:
MailEngineException extends from org.apache.commons.lang.exception.NestableException, do you have commons-lang on your classpath ?


Thank you very much jelmer!! this works pretty good!!!


Can you tell me how did you fix it?
I am having same problem and im not sure ho wto fix using eclipse Juno.
Claudiu Teodorescu, geändert vor 8 Jahren.

RE: MailEngine.send() not useable?

New Member Beiträge: 13 Beitrittsdatum: 25.02.15 Neueste Beiträge
Achmed Tyrannus Albab:
Rubén García Tamayo:
jelmer kuperus:
MailEngineException extends from org.apache.commons.lang.exception.NestableException, do you have commons-lang on your classpath ?


Thank you very much jelmer!! this works pretty good!!!


Can you tell me how did you fix it?
I am having same problem and im not sure ho wto fix using eclipse Juno.



Hi Achmed,

I belive that is too late for you but this is what I did:

1. go and download from internet apache-commons-lang.jar ( http://www.java2s.com/Code/Jar/a/Downloadapachecommonslangjar.htm )
2. after that on eclipse: right click on project -> Properties -> Java Build Path -> tab Libraries -> Add External JAR -> choose the jar file -> OK

Now is suppose to work. The problem is that what they say: is missing class org.apache.commons.lang.exception.NestableException !!!

Claudiu
thumbnail
kitie vbr, geändert vor 13 Jahren.

RE: MailEngine.send() not useable?

Junior Member Beiträge: 39 Beitrittsdatum: 05.08.10 Neueste Beiträge
Hello, I tried whith your code, but don´t recognize me _log.isDebugEnabled() and

_log.isDebugEnabled()

Where do you declare _log?????

Thanks a lot




Pravin Pawar:
Please see the below code which I have used to send the mail, which can help you!

protected void addTimesheet(ActionRequest actionRequest) throws Exception {		    
   try{
        long userId = ParamUtil.getLong(actionRequest, "userId");
	long managerId = ParamUtil.getLong(actionRequest, "managerId");
        User user = UserLocalServiceUtil.getUserById(userId);	
        User managet = UserLocalServiceUtil.getUserById(managerId);	

	InternetAddress fromInternetAddress = new InternetAddress(user.getEmailAddress(), user.getFullName());
	InternetAddress[] toInternetAddresses = new InternetAddress[]{new InternetAddress(manager.getEmailAddress())};
			
	String subject = user.getFullName()+" Timesheet";
	StringBuffer body = new StringBuffer();
	
	body.append("Dear Sir,\n");
	body.append("I have completed all the task specified in the timesheet and requesting ");
	body.append("for approve the timesheet. \n");
	body.append("Let me know if you have any question. \n");
	body.append("\n");
	body.append("Thanks,\n");
	body.append(user.getFirstName());
	if (_log.isDebugEnabled()) {
		_log.debug("Sending email to " + toInternetAddresses);
	}
			
	MailEngine.send(fromInternetAddress, toInternetAddresses, subject, body.toString());
			
   }catch(Exception e){
       if (_log.isErrorEnabled()) {
           _log.error(e.getMessage(), e);
   }
}