Fórum

MailEngine.send() not useable?

François LE QUEMENER, modificado 14 Anos atrás.

MailEngine.send() not useable?

Junior Member Postagens: 48 Data de Entrada: 18/09/09 Postagens Recentes
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, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

thumbnail
Pravin Pawar, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 62 Data de Entrada: 17/11/09 Postagens Recentes
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, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 33 Data de Entrada: 17/03/09 Postagens Recentes
Hi,

where can I find InternetAddress class???

Thx,
NB
thumbnail
Pravin Pawar, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 62 Data de Entrada: 17/11/09 Postagens Recentes
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, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 33 Data de Entrada: 17/03/09 Postagens Recentes
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, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 62 Data de Entrada: 17/11/09 Postagens Recentes
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, modificado 14 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 33 Data de Entrada: 17/03/09 Postagens Recentes
Ok, and how can I handle this Exception problem... (please, see attached image)

Thanks,
N.
thumbnail
jelmer kuperus, modificado 13 Anos atrás.

RE: MailEngine.send() not useable?

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
MailEngineException extends from org.apache.commons.lang.exception.NestableException, do you have commons-lang on your classpath ?
Rubén García Tamayo, modificado 12 Anos atrás.

RE: MailEngine.send() not useable?

New Member Postagens: 7 Data de Entrada: 10/10/11 Postagens Recentes
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, modificado 10 Anos atrás.

RE: MailEngine.send() not useable?

Regular Member Postagens: 158 Data de Entrada: 05/03/10 Postagens Recentes
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, modificado 8 Anos atrás.

RE: MailEngine.send() not useable?

New Member Postagens: 13 Data de Entrada: 25/02/15 Postagens Recentes
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, modificado 13 Anos atrás.

RE: MailEngine.send() not useable?

Junior Member Postagens: 39 Data de Entrada: 05/08/10 Postagens Recentes
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);
   }
}