<?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>Best Practice Recommendation For Overriding Default Liferay Mail Engine</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121283371" />
  <subtitle>Best Practice Recommendation For Overriding Default Liferay Mail Engine</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121283371</id>
  <updated>2026-04-06T17:11:28Z</updated>
  <dc:date>2026-04-06T17:11:28Z</dc:date>
  <entry>
    <title>RE: Best Practice Recommendation For Overriding Default Liferay Mail Engine</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121285580" />
    <author>
      <name>Christopher Dawson</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121285580</id>
    <updated>2021-12-08T16:41:31Z</updated>
    <published>2021-12-08T14:38:19Z</published>
    <summary type="html">&lt;p&gt;Thank you both for your comments/suggestions. I will give the
  MessageBus destination override a try.&lt;/p&gt;
&lt;p&gt;I think I got hung up on the idea that since the mail framework was
  still initialized by Spring - I was out of options for cleanly
  leveraging OSGI to do the override.&lt;/p&gt;
&lt;p&gt;Thanks again!&lt;/p&gt;</summary>
    <dc:creator>Christopher Dawson</dc:creator>
    <dc:date>2021-12-08T14:38:19Z</dc:date>
  </entry>
  <entry>
    <title>RE: Best Practice Recommendation For Overriding Default Liferay Mail Engine</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121285374" />
    <author>
      <name>Dominik Marks</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121285374</id>
    <updated>2021-12-08T12:49:37Z</updated>
    <published>2021-12-08T12:49:36Z</published>
    <summary type="html">&lt;p&gt;As far as I know Liferay uses the MessageBus to send mails. The
  destination is called &amp;quot;liferay/mail&amp;quot;. If you create your own
  listener for that destination and replace the existing one you should
  be able to handle all mail sending.&lt;/p&gt;
&lt;p&gt;Pseudo-Code (derived from a real project):&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;@Component(
    immediate = true,
    service = CustomMailMessageListener.class
)
public class CustomMailMessageListener extends MailMessageListener {

    @Reference(target = &amp;quot;(destination.name=liferay/mail)&amp;quot;)
    private Destination destination;

    private List&amp;lt;MessageListener&amp;gt; messageListeners;


    @Activate
    @Modified
    protected void activate(Map&amp;lt;String, Object&amp;gt; properties) {
        this.messageListeners = new ArrayList&amp;lt;&amp;gt;(this.destination.getMessageListeners());

        this.destination.unregisterMessageListeners();

        this.destination.register(this);
    }

    @Deactivate
    protected void deactivate(Map&amp;lt;String, Object&amp;gt; proprties) {
        this.destination.unregisterMessageListeners();

        for (MessageListener messageListener : messageListeners) {
            this.destination.register(messageListener);
        }
    }

    @Override
    protected void doMailMessage(MailMessage mailMessage) throws Exception {
		...

		CustomMailEngine.send(mailMessage);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Dominik Marks</dc:creator>
    <dc:date>2021-12-08T12:49:36Z</dc:date>
  </entry>
  <entry>
    <title>RE: Best Practice Recommendation For Overriding Default Liferay Mail Engine</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121284058" />
    <author>
      <name>Olaf Kock</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121284058</id>
    <updated>2021-12-07T10:53:57Z</updated>
    <published>2021-12-07T10:53:56Z</published>
    <summary type="html">&lt;p&gt;I haven't tried overriding the mail engine, but the first place I'd
  look at is the Message Queue: AFAIK mails are sent/handled through the
  queue, and if you manage to get a queue-listener that is triggered
  before/instead of Liferay's default implementation, you'd have what
  you need. That should be possible through OSGi - but again: I have no
  experience doing so, just a vague expectation about this direction
  being workable&lt;/p&gt;</summary>
    <dc:creator>Olaf Kock</dc:creator>
    <dc:date>2021-12-07T10:53:56Z</dc:date>
  </entry>
  <entry>
    <title>Best Practice Recommendation For Overriding Default Liferay Mail Engine</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121283270" />
    <author>
      <name>Christopher Dawson</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121283270</id>
    <updated>2021-12-07T10:51:32Z</updated>
    <published>2021-12-06T18:39:07Z</published>
    <summary type="html">&lt;p&gt;Hello Liferay Dev Community:&lt;/p&gt;
&lt;p&gt;Migration question with regards to Liferay's mail engine.&lt;/p&gt;
&lt;p&gt;In 6.2.x I was able to override the mail system to leverage an third
  party API (not SMTP) based system - Postmark.&lt;br /&gt; This required an
  ext plugin that contained overrides
    for &lt;em&gt;mail-spring.xml&lt;/em&gt;, &lt;em&gt;MailEngine, MailServiceImpl,
    MailMessageListener &amp;amp; MailMesssage&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I am attempting to provide the same functionality in our 7.3.x
  deployment. However I am uncertain of the best approach here given
  that I am running into road blocks no matter which solution I attempt.
  So far I have tried:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;EXT Plugin - created via
    the &lt;strong&gt;war-core-ext&lt;em&gt; &lt;/em&gt;&lt;/strong&gt;blade template in Liferay
    Workspace.   &lt;ol&gt;
      &lt;li&gt;Main issue here is that the newly created plugin project gets
        an immediate build error which prevents me from even compiling code. &lt;/li&gt;
      &lt;li&gt;I also cannot find a way to introduce libraries into this
        project. In 6.2.x I was able to use
        the &lt;em&gt;liferay-plugin-package.properties&lt;/em&gt; file to
        incorporate dependencies from the server's libraries. This no
        longer appears to be functioning.&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;
  &lt;li&gt;EXT Module - created via the &lt;strong&gt;Module Ext
    Project &lt;/strong&gt;blade template in Liferay Workspace  &lt;ol&gt;
      &lt;li&gt;While I'm able to specify &lt;em&gt;apps.petra.petra-mail&lt;/em&gt; as
        the original module to override - I am unable to get my module
        project to compile and deploy to my local development server&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;
  &lt;li&gt;Service Wrapper - also created via Liferay Workspace blade
    template  &lt;ol&gt;
      &lt;li&gt;

        &lt;em&gt;portal-impl/src/com/liferay/mail/messaging/MailMessageListener.java&lt;/em&gt;
        is not defined as an OSGI component (since it is instantiated
        via Spring in the &lt;em&gt;mail-spring.xml&lt;/em&gt; file). I cannot
        retrieve anything related to it via the GoGo shell. So this
        prevents me from overriding it via the recommended OSGI Service
        ranking approach&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Bottom line: the Liferay mail engine is stil being instantiated by
  Spring and not (as far as I can tell) being exposed as an OSGI service. &lt;/p&gt;
&lt;p&gt;Should I be continuing to look at either options 1 or 2 above (since
  option 3 seems like a dead end)? Or is there some other option out there?&lt;/p&gt;
&lt;p&gt;Thanks in advance for any help/suggestions!!&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Note:&lt;/strong&gt; I am aware that Postmark offers an SMTP
  approach - however some of the advanced functionality that we wish to
  utilize is only exposed via their API - not over SMTP. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>Christopher Dawson</dc:creator>
    <dc:date>2021-12-06T18:39:07Z</dc:date>
  </entry>
</feed>
