<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How can I send mails with MailEngine ?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=4892125" />
  <subtitle>How can I send mails with MailEngine ?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=4892125</id>
  <updated>2026-04-07T04:27:23Z</updated>
  <dc:date>2026-04-07T04:27:23Z</dc:date>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9908605" />
    <author>
      <name>Abzal Amantaev</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9908605</id>
    <updated>2011-07-07T11:34:23Z</updated>
    <published>2011-07-07T11:34:23Z</published>
    <summary type="html">Hi &lt;br /&gt;N. Belo!&lt;br /&gt;&lt;br /&gt;I have the same error, if you solved this problem, please show me..</summary>
    <dc:creator>Abzal Amantaev</dc:creator>
    <dc:date>2011-07-07T11:34:23Z</dc:date>
  </entry>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4911179" />
    <author>
      <name>N. Belo</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4911179</id>
    <updated>2010-04-29T16:53:01Z</updated>
    <published>2010-04-29T16:53:01Z</published>
    <summary type="html">Ok,&lt;br /&gt;&lt;br /&gt;the Exception problem is fixed. All I had to do was to import the commons-lang.jar.&lt;br /&gt;That&amp;#39;s because the MailEngineException implementation depends of that class.&lt;br /&gt;&lt;br /&gt;But now I have one compilation problem.&lt;br /&gt;&lt;span style="color: #3C3EC0"&gt;&lt;em&gt;&lt;br /&gt;Compiling 1 source file to C:\Liferay-sdk\portlets\send-mail-portlet\build\web\WEB-INF\classes&lt;br /&gt;C:\Liferay-sdk\portlets\send-mail-portlet\docroot\WEB-INF\src\com\sample\jsp\portlet\JSPPortlet.java:134: cannot access javax.mail.internet.InternetAddress&lt;br /&gt;class file for javax.mail.internet.InternetAddress not found&lt;br /&gt;                MailEngine.send(from, to, subject, body);&lt;br /&gt;1 error&lt;br /&gt;C:\Liferay-sdk\portlets\send-mail-portlet\nbproject\build-impl.xml:417: The following error occurred while executing this line:&lt;br /&gt;C:\Liferay-sdk\portlets\send-mail-portlet\nbproject\build-impl.xml:244: Compile failed; see the compiler error output for details.&lt;br /&gt;BUILD FAILED (total time: 0 seconds)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I believe the usage of this library should be included in the compilation process and not imported. Does anyone have a clue what is the problem??&lt;br /&gt;&lt;br /&gt;This problem was verified with a portlet builded using Netbeans(With Portal Pack Pluggin) and when I use Liferay-sdk.&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;N.</summary>
    <dc:creator>N. Belo</dc:creator>
    <dc:date>2010-04-29T16:53:01Z</dc:date>
  </entry>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4894445" />
    <author>
      <name>N. Belo</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4894445</id>
    <updated>2010-04-25T20:45:29Z</updated>
    <published>2010-04-25T20:45:29Z</published>
    <summary type="html">Hi,&lt;br /&gt;&lt;br /&gt;Thank you for reply. That looks good. &lt;br /&gt;I believe that my problem is that I need to know which mail.jar contains InternetAddress class should I use to avoid the link problem.&lt;br /&gt;&lt;br /&gt;Do you know where is the mail.jar that as defined the InternetAddress class and MailEngine is refering to? How about this Exception? (please, see attached image)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I am developing with Liferay SDK and using Tomcat 6. I&amp;#39;ve added the library mail.jar from &lt;strong&gt;/Tomcat-6.0.18/lib/ext/&lt;/strong&gt; or from &lt;strong&gt;liferay-sdk/lib/&lt;/strong&gt; to my portlet so I could compile my code using the InternetAddress class.&lt;br /&gt;&lt;br /&gt;Then I&amp;#39;ve deployed the portlet, and when I try to use the InternetAddress class I get the link error that I&amp;#39;ve mentioned.&lt;br /&gt;&lt;br /&gt;Thanks.&lt;br /&gt;BR,&lt;br /&gt;N.</summary>
    <dc:creator>N. Belo</dc:creator>
    <dc:date>2010-04-25T20:45:29Z</dc:date>
  </entry>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4893586" />
    <author>
      <name>Tomáš Polešovský</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4893586</id>
    <updated>2010-04-25T06:30:15Z</updated>
    <published>2010-04-25T06:30:15Z</published>
    <summary type="html">Hi &lt;br /&gt;&lt;div class="quote-title"&gt;N. Belo:&lt;/div&gt;&lt;blockquote&gt;The InternetAddress class has to be imported from /tomcat6.0.18/lib/ext/mail.jar and when I use it I have this error in logs...&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;And why do you need to do this? The /tomcat6.0.18/lib/ext/mail.jar already contains the javax/mail/internet/InternetAddress.class&lt;br /&gt;&lt;br /&gt;Are you building your sources against the same version of the mail.jar? The problem with InternetAddress was with the tomcat 5.x.&lt;br /&gt;&lt;br /&gt;-- tom</summary>
    <dc:creator>Tomáš Polešovský</dc:creator>
    <dc:date>2010-04-25T06:30:15Z</dc:date>
  </entry>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4893098" />
    <author>
      <name>Corné Aussems</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4893098</id>
    <updated>2010-04-24T20:49:04Z</updated>
    <published>2010-04-24T20:49:04Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;This works for me;&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;
import javax.mail.internet.InternetAddress;
import javax.portlet.RenderRequest;

import org.apache.log4j.Logger;

import com.liferay.portal.kernel.mail.SMTPAccount;
import com.liferay.util.mail.MailEngine;
import com.liferay.util.mail.MailEngineException;

public class Emailer {
	private static final Logger logger = Logger.getLogger(Emailer.class);
	private static void send(
			InternetAddress from, InternetAddress[] to, InternetAddress[] cc,
			InternetAddress[] bcc, InternetAddress[] bulkAddresses,
			String subject, String body, boolean htmlFormat,
			InternetAddress[] replyTo, String messageId, String inReplyTo,
			File[] attachments)
		throws MailEngineException {
		
		SMTPAccount smtpAccount = null;
		
		MailEngine.send(
				from,to, cc,
				 bcc, bulkAddresses,
				subject, body, htmlFormat,
				replyTo, messageId, inReplyTo,
				attachments,smtpAccount);

	}	

	public static void sendEmail(final String from, final String to,
			final String bcc, final String subject, final String body,
			final File[] attachments) throws Exception {

		InternetAddress[] toS = new InternetAddress[] { new InternetAddress(to) };
		InternetAddress fromS = new InternetAddress(from);
		InternetAddress[] bccS = null;
		if (bcc != null)
			bccS = new InternetAddress[] { new InternetAddress(bcc) };

		InternetAddress[] cc = null;
		InternetAddress[] bulkAddresses = null;
		boolean htmlFormat = true;
		InternetAddress[] replyTo = null;
		String messageId = null;
		String inReplyTo = null;

		Emailer.send(fromS, toS, cc, bccS, bulkAddresses, subject, body,
				htmlFormat, replyTo, messageId, inReplyTo, attachments);
	}
}&lt;/code&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Corné Aussems</dc:creator>
    <dc:date>2010-04-24T20:49:04Z</dc:date>
  </entry>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4892844" />
    <author>
      <name>N. Belo</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4892844</id>
    <updated>2010-04-24T15:25:20Z</updated>
    <published>2010-04-24T15:25:20Z</published>
    <summary type="html">Hi Tom,&lt;br /&gt;&lt;br /&gt;Thank you for your post. I&amp;#39;ve already had look into those documents, but I am still confused how to handle with MailEngine exceptions.&lt;br /&gt;&lt;br /&gt;The InternetAddress class has to be imported from /tomcat6.0.18/lib/ext/mail.jar and when I use it I have this error in logs...&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #E6A40C"&gt;java.lang.LinkageError: Class javax/mail/internet/InternetAddress violates loader constraints&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There is a post about this problem, but it was written 3 years ago and the solution is not applicable anymore.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.liferay.com/web/guest/community/forums/-/message_boards/message/99219"&gt;java.lang.LinkageError Post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Can you put here a small sample of code about how to send emails in a portlet?&lt;br /&gt;&lt;br /&gt;Thank you for your help.&lt;br /&gt;BR,&lt;br /&gt;N.</summary>
    <dc:creator>N. Belo</dc:creator>
    <dc:date>2010-04-24T15:25:20Z</dc:date>
  </entry>
  <entry>
    <title>RE: How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4892530" />
    <author>
      <name>Tomáš Polešovský</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4892530</id>
    <updated>2010-04-24T06:46:03Z</updated>
    <published>2010-04-24T06:46:03Z</published>
    <summary type="html">Hi,&lt;br /&gt;&lt;br /&gt;MailEngineException is NestedException, which is Exception and Throwable (see &lt;a href="http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/exception/NestableException.html"&gt;NestedException javadoc&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;InternetAddress is not in javax.mail package, but in javax.mail.internet package.&lt;br /&gt;&lt;br /&gt;For full understanding of the MailEngine you can also look at the Liferay 5.2 &lt;a href="http://docs.liferay.com/portal/5.2/javadocs/util-java/com/liferay/util/mail/MailEngine.java.html"&gt;MailEngine source&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;-- tom</summary>
    <dc:creator>Tomáš Polešovský</dc:creator>
    <dc:date>2010-04-24T06:46:03Z</dc:date>
  </entry>
  <entry>
    <title>How can I send mails with MailEngine ?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4892124" />
    <author>
      <name>N. Belo</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4892124</id>
    <updated>2010-04-23T20:34:35Z</updated>
    <published>2010-04-23T20:34:35Z</published>
    <summary type="html">Hi all,&lt;br /&gt;&lt;br /&gt;I have my portal-ext.properties configured correctly to use an smtp server.&lt;br /&gt;I&amp;#39;ve tested this connection and it works fine.&lt;br /&gt;&lt;br /&gt;Now I want to use MailEngine.send(fromAddress, toAddress, subject, body)&lt;br /&gt;to simply send an email. And the problem is that MailEngineException is not a Throwable exception, but a NestedException&lt;br /&gt;&lt;br /&gt;&lt;em&gt;        try {&lt;br /&gt;            MailEngine.send(fromAddress, toAddress, subject, body);&lt;br /&gt;        } catch (&lt;strong&gt;MailEngineException ex&lt;/strong&gt;) {&lt;br /&gt;            Logger.getLogger(MyClass.class.getName()).log(Level.SEVERE, null, ex);&lt;br /&gt;        }&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve found some workarounds for this, but they use &lt;strong&gt;InternetAdress&lt;/strong&gt; class which doesn&amp;#39;t exist in my &lt;u&gt;javax.mail.*&lt;/u&gt; &lt;br /&gt;&lt;br /&gt;I am using Liferay bundle with Tomcat 6 and the development is all made with liferay SDK.&lt;br /&gt;&lt;br /&gt;Can someone help me in this simple task of sending an email?&lt;br /&gt;&lt;br /&gt;Thank you.&lt;br /&gt;N.</summary>
    <dc:creator>N. Belo</dc:creator>
    <dc:date>2010-04-23T20:34:35Z</dc:date>
  </entry>
</feed>
