MailService.java

  1. /*
  2.  * Copyright (c) 2002-2022, City of Paris
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  *  1. Redistributions of source code must retain the above copyright notice
  10.  *     and the following disclaimer.
  11.  *
  12.  *  2. Redistributions in binary form must reproduce the above copyright notice
  13.  *     and the following disclaimer in the documentation and/or other materials
  14.  *     provided with the distribution.
  15.  *
  16.  *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
  17.  *     contributors may be used to endorse or promote products derived from
  18.  *     this software without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  24.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30.  * POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  * License 1.0
  33.  */
  34. package fr.paris.lutece.portal.service.mail;

  35. import fr.paris.lutece.portal.service.daemon.AppDaemonService;
  36. import fr.paris.lutece.portal.service.daemon.Daemon;
  37. import fr.paris.lutece.portal.service.datastore.DatastoreService;
  38. import fr.paris.lutece.portal.service.portal.PortalService;
  39. import fr.paris.lutece.portal.service.spring.SpringContextService;
  40. import fr.paris.lutece.portal.service.util.AppPathService;
  41. import fr.paris.lutece.portal.service.util.AppPropertiesService;
  42. import fr.paris.lutece.util.mail.FileAttachment;
  43. import fr.paris.lutece.util.mail.UrlAttachment;

  44. import java.util.List;

  45. /**
  46.  * Application Mail Service
  47.  */
  48. public final class MailService
  49. {
  50.     private static final String KEY_NO_REPLY_EMAIL = "portal.site.site_property.noreply_email";
  51.     private static final String PROPERTY_MAIL_NOREPLY_EMAIL = "mail.noreply.email";
  52.     private static final String BEAN_MAIL_QUEUE = "mailQueue";

  53.     /** Creates a new instance of AppMailService */
  54.     private MailService( )
  55.     {
  56.     }

  57.     /**
  58.      * Enqueues a mail item to be sent
  59.      *
  60.      * @param item
  61.      *            the mail item to enqueue
  62.      */
  63.     private static void enqueue( MailItem item )
  64.     {
  65.         getQueue( ).send( item );
  66.         AppDaemonService.signalDaemon( MailSenderDaemon.DAEMON_ID );
  67.     }

  68.     /**
  69.      * Send a HTML message asynchronously. The message is queued until a daemon thread send all awaiting messages
  70.      *
  71.      * @param strRecipientsTo
  72.      *            The list of the main recipients email.Every recipient must be separated by the mail separator define in config.properties
  73.      * @param strSenderName
  74.      *            The sender name.
  75.      * @param strSenderEmail
  76.      *            The sender email address.
  77.      * @param strSubject
  78.      *            The message subject.
  79.      * @param strMessage
  80.      *            The message.
  81.      */
  82.     public static void sendMailHtml( String strRecipientsTo, String strSenderName, String strSenderEmail, String strSubject, String strMessage )
  83.     {
  84.         sendMailHtml( strRecipientsTo, null, null, strSenderName, strSenderEmail, strSubject, strMessage );
  85.     }

  86.     /**
  87.      * Send a HTML message asynchronously. The message is queued until a daemon thread send all awaiting messages
  88.      *
  89.      * @param strRecipientsTo
  90.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  91.      * @param strRecipientsCc
  92.      *            The recipients list of the carbon copies .
  93.      * @param strRecipientsBcc
  94.      *            The recipients list of the blind carbon copies .
  95.      * @param strSenderName
  96.      *            The sender name.
  97.      * @param strSenderEmail
  98.      *            The sender email address.
  99.      * @param strSubject
  100.      *            The message subject.
  101.      * @param strMessage
  102.      *            The message.
  103.      */
  104.     public static void sendMailHtml( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName, String strSenderEmail,
  105.             String strSubject, String strMessage )
  106.     {
  107.         sendMailHtml( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, strMessage, false );
  108.     }

  109.     /**
  110.      * Send a HTML message asynchronously. The message is queued until a daemon thread send all awaiting messages
  111.      *
  112.      * @param strRecipientsTo
  113.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  114.      * @param strRecipientsCc
  115.      *            The recipients list of the carbon copies .
  116.      * @param strRecipientsBcc
  117.      *            The recipients list of the blind carbon copies .
  118.      * @param strSenderName
  119.      *            The sender name.
  120.      * @param strSenderEmail
  121.      *            The sender email address.
  122.      * @param strSubject
  123.      *            The message subject.
  124.      * @param strMessage
  125.      *            The message.
  126.      * @param bUniqueRecipientTo
  127.      *            true if the mail must be send unitarily for each recipient
  128.      */
  129.     public static void sendMailHtml( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName, String strSenderEmail,
  130.             String strSubject, String strMessage, boolean bUniqueRecipientTo )
  131.     {
  132.         MailItem item = new MailItem( );
  133.         item.setRecipientsTo( strRecipientsTo );
  134.         item.setRecipientsCc( strRecipientsCc );
  135.         item.setRecipientsBcc( strRecipientsBcc );
  136.         item.setSenderName( strSenderName );
  137.         item.setSenderEmail( strSenderEmail );
  138.         item.setSubject( strSubject );
  139.         item.setMessage( strMessage );
  140.         item.setFormat( MailItem.FORMAT_HTML );
  141.         item.setUniqueRecipientTo( bUniqueRecipientTo );

  142.         enqueue( item );
  143.     }

  144.     /**
  145.      * Send a HTML message asynchronously with the attachments associated to the message . The message is queued until a daemon thread send all awaiting
  146.      * messages
  147.      *
  148.      * @param strRecipientsTo
  149.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  150.      * @param strSenderName
  151.      *            The sender name.
  152.      * @param strSenderEmail
  153.      *            The sender email address.
  154.      * @param strSubject
  155.      *            The message subject.
  156.      * @param strMessage
  157.      *            The message.
  158.      * @param urlsAttachement
  159.      *            The List of UrlAttachement Object, containing the URL of attachments associated with their content-location.
  160.      */
  161.     public static void sendMailMultipartHtml( String strRecipientsTo, String strSenderName, String strSenderEmail, String strSubject, String strMessage,
  162.             List<UrlAttachment> urlsAttachement )
  163.     {
  164.         sendMailMultipartHtml( strRecipientsTo, null, null, strSenderName, strSenderEmail, strSubject, strMessage, urlsAttachement, null );
  165.     }

  166.     /**
  167.      * Send a HTML message asynchronously with the attachments associated to the message and attached files . The message is queued until a daemon thread send
  168.      * all awaiting messages
  169.      *
  170.      * @param strRecipientsTo
  171.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  172.      * @param strRecipientsCc
  173.      *            The recipients list of the carbon copies .
  174.      * @param strRecipientsBcc
  175.      *            The recipients list of the blind carbon copies .
  176.      * @param strSenderName
  177.      *            The sender name.
  178.      * @param strSenderEmail
  179.      *            The sender email address.
  180.      * @param strSubject
  181.      *            The message subject.
  182.      * @param strMessage
  183.      *            The message.
  184.      * @param urlsAttachement
  185.      *            The List of UrlAttachement Object, containing the URL of attachments associated with their content-location
  186.      * @param filesAttachement
  187.      *            The list of attached files.
  188.      */
  189.     public static void sendMailMultipartHtml( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName,
  190.             String strSenderEmail, String strSubject, String strMessage, List<UrlAttachment> urlsAttachement, List<FileAttachment> filesAttachement )
  191.     {
  192.         sendMailMultipartHtml( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, strMessage, urlsAttachement,
  193.                 filesAttachement, false );
  194.     }

  195.     /**
  196.      * Send a HTML message asynchronously with the attachments associated to the message and attached files . The message is queued until a daemon thread send
  197.      * all awaiting messages
  198.      *
  199.      * @param strRecipientsTo
  200.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  201.      * @param strRecipientsCc
  202.      *            The recipients list of the carbon copies .
  203.      * @param strRecipientsBcc
  204.      *            The recipients list of the blind carbon copies .
  205.      * @param strSenderName
  206.      *            The sender name.
  207.      * @param strSenderEmail
  208.      *            The sender email address.
  209.      * @param strSubject
  210.      *            The message subject.
  211.      * @param strMessage
  212.      *            The message.
  213.      * @param urlsAttachement
  214.      *            The List of UrlAttachement Object, containing the URL of attachments associated with their content-location
  215.      * @param filesAttachement
  216.      *            The list of attached files.
  217.      * @param bUniqueRecipientTo
  218.      *            true if the mail must be send unitarily for each recipient
  219.      */
  220.     public static void sendMailMultipartHtml( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName,
  221.             String strSenderEmail, String strSubject, String strMessage, List<UrlAttachment> urlsAttachement, List<FileAttachment> filesAttachement,
  222.             boolean bUniqueRecipientTo )
  223.     {
  224.         MailItem item = new MailItem( );
  225.         item.setRecipientsTo( strRecipientsTo );
  226.         item.setRecipientsCc( strRecipientsCc );
  227.         item.setRecipientsBcc( strRecipientsBcc );
  228.         item.setSenderName( strSenderName );
  229.         item.setSenderEmail( strSenderEmail );
  230.         item.setSubject( strSubject );
  231.         item.setMessage( strMessage );
  232.         item.setFormat( MailItem.FORMAT_MULTIPART_HTML );
  233.         item.setUrlsAttachement( urlsAttachement );
  234.         item.setFilesAttachement( filesAttachement );
  235.         item.setUniqueRecipientTo( bUniqueRecipientTo );

  236.         enqueue( item );
  237.     }

  238.     /**
  239.      * Send a calendar message asynchronously. The message is queued until a daemon thread send all awaiting messages
  240.      *
  241.      * @param strRecipientsTo
  242.      *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
  243.      * @param strSenderName
  244.      *            The sender name.
  245.      * @param strSenderEmail
  246.      *            The sender email address.
  247.      * @param strSubject
  248.      *            The message subject.
  249.      * @param strMessage
  250.      *            The message.
  251.      * @param strCalendarMessage
  252.      *            The calendar message
  253.      * @param bCreateEvent
  254.      *            True to create the calendar event, false to remove it
  255.      */
  256.     public static void sendMailCalendar( String strRecipientsTo, String strSenderName, String strSenderEmail, String strSubject, String strMessage,
  257.             String strCalendarMessage, boolean bCreateEvent )
  258.     {
  259.         sendMailCalendar( strRecipientsTo, null, null, strSenderName, strSenderEmail, strSubject, strMessage, strCalendarMessage, bCreateEvent );
  260.     }

  261.     /**
  262.      * Send a calendar message asynchronously. The message is queued until a daemon thread send all awaiting messages
  263.      *
  264.      * @param strRecipientsTo
  265.      *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
  266.      * @param strRecipientsCc
  267.      *            The recipients list of the carbon copies .
  268.      * @param strRecipientsBcc
  269.      *            The recipients list of the blind carbon copies .
  270.      * @param strSenderName
  271.      *            The sender name.
  272.      * @param strSenderEmail
  273.      *            The sender email address.
  274.      * @param strSubject
  275.      *            The message subject.
  276.      * @param strMessage
  277.      *            The message.
  278.      * @param strCalendarMessage
  279.      *            The calendar message
  280.      * @param bCreateEvent
  281.      *            True to create the calendar event, false to remove it
  282.      */
  283.     public static void sendMailCalendar( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName, String strSenderEmail,
  284.             String strSubject, String strMessage, String strCalendarMessage, boolean bCreateEvent )
  285.     {
  286.         sendMailCalendar( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, strMessage, strCalendarMessage,
  287.                 bCreateEvent, false );
  288.     }

  289.     /**
  290.      * Send a calendar message asynchronously. The message is queued until a daemon thread send all awaiting messages
  291.      *
  292.      * @param strRecipientsTo
  293.      *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
  294.      * @param strRecipientsCc
  295.      *            The recipients list of the carbon copies .
  296.      * @param strRecipientsBcc
  297.      *            The recipients list of the blind carbon copies .
  298.      * @param strSenderName
  299.      *            The sender name.
  300.      * @param strSenderEmail
  301.      *            The sender email address.
  302.      * @param strSubject
  303.      *            The message subject.
  304.      * @param strMessage
  305.      *            The message.
  306.      * @param strCalendarMessage
  307.      *            The calendar message
  308.      * @param bCreateEvent
  309.      *            True to create the calendar event, false to remove it
  310.      * @param bUniqueRecipientTo
  311.      *            true if the mail must be send unitarily for each recipient
  312.      */
  313.     public static void sendMailCalendar( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName, String strSenderEmail,
  314.             String strSubject, String strMessage, String strCalendarMessage, boolean bCreateEvent, boolean bUniqueRecipientTo )
  315.     {
  316.         MailItem item = new MailItem( );
  317.         item.setRecipientsTo( strRecipientsTo );
  318.         item.setRecipientsCc( strRecipientsCc );
  319.         item.setRecipientsBcc( strRecipientsBcc );
  320.         item.setSenderName( strSenderName );
  321.         item.setSenderEmail( strSenderEmail );
  322.         item.setSubject( strSubject );
  323.         item.setMessage( strMessage );
  324.         item.setCalendarMessage( strCalendarMessage );
  325.         item.setCreateEvent( bCreateEvent );
  326.         item.setFormat( MailItem.FORMAT_CALENDAR );
  327.         item.setUniqueRecipientTo( bUniqueRecipientTo );

  328.         enqueue( item );
  329.     }

  330.     /**
  331.      * Send a text message asynchronously. The message is queued until a daemon thread send all awaiting messages
  332.      *
  333.      * @param strRecipientsTo
  334.      *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
  335.      * @param strSenderName
  336.      *            The sender name.
  337.      * @param strSenderEmail
  338.      *            The sender email address.
  339.      * @param strSubject
  340.      *            The message subject.
  341.      * @param strMessage
  342.      *            The message.
  343.      */
  344.     public static void sendMailText( String strRecipientsTo, String strSenderName, String strSenderEmail, String strSubject, String strMessage )
  345.     {
  346.         sendMailText( strRecipientsTo, null, null, strSenderName, strSenderEmail, strSubject, strMessage );
  347.     }

  348.     /**
  349.      * Send a text message asynchronously. The message is queued until a daemon thread send all awaiting messages
  350.      *
  351.      * @param strRecipientsTo
  352.      *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
  353.      * @param strRecipientsCc
  354.      *            The recipients list of the carbon copies .
  355.      * @param strRecipientsBcc
  356.      *            The recipients list of the blind carbon copies .
  357.      * @param strSenderName
  358.      *            The sender name.
  359.      * @param strSenderEmail
  360.      *            The sender email address.
  361.      * @param strSubject
  362.      *            The message subject.
  363.      * @param strMessage
  364.      *            The message.
  365.      */
  366.     public static void sendMailText( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName, String strSenderEmail,
  367.             String strSubject, String strMessage )
  368.     {
  369.         sendMailText( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, strMessage, false );
  370.     }

  371.     /**
  372.      * Send a text message asynchronously. The message is queued until a daemon thread send all awaiting messages
  373.      *
  374.      * @param strRecipientsTo
  375.      *            The list of the main recipients email. Every recipient must be separated by the mail separator defined in config.properties
  376.      * @param strRecipientsCc
  377.      *            The recipients list of the carbon copies .
  378.      * @param strRecipientsBcc
  379.      *            The recipients list of the blind carbon copies .
  380.      * @param strSenderName
  381.      *            The sender name.
  382.      * @param strSenderEmail
  383.      *            The sender email address.
  384.      * @param strSubject
  385.      *            The message subject.
  386.      * @param strMessage
  387.      *            The message.
  388.      * @param bUniqueRecipientTo
  389.      *            true if the mail must be send unitarily for each recipient
  390.      */
  391.     public static void sendMailText( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName, String strSenderEmail,
  392.             String strSubject, String strMessage, boolean bUniqueRecipientTo )
  393.     {
  394.         MailItem item = new MailItem( );
  395.         item.setRecipientsTo( strRecipientsTo );
  396.         item.setRecipientsCc( strRecipientsCc );
  397.         item.setRecipientsBcc( strRecipientsBcc );
  398.         item.setSenderName( strSenderName );
  399.         item.setSenderEmail( strSenderEmail );
  400.         item.setSubject( strSubject );
  401.         item.setMessage( strMessage );
  402.         item.setFormat( MailItem.FORMAT_TEXT );
  403.         item.setUniqueRecipientTo( bUniqueRecipientTo );

  404.         enqueue( item );
  405.     }

  406.     /**
  407.      * Send a text message asynchronously with attached files. The message is queued until a daemon thread send all awaiting messages
  408.      *
  409.      * @param strRecipientsTo
  410.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  411.      * @param strSenderName
  412.      *            The sender name.
  413.      * @param strSenderEmail
  414.      *            The sender email address.
  415.      * @param strSubject
  416.      *            The message subject.
  417.      * @param strMessage
  418.      *            The message.
  419.      * @param filesAttachement
  420.      *            The list of attached files.
  421.      */
  422.     public static void sendMailMultipartText( String strRecipientsTo, String strSenderName, String strSenderEmail, String strSubject, String strMessage,
  423.             List<FileAttachment> filesAttachement )
  424.     {
  425.         sendMailMultipartText( strRecipientsTo, null, null, strSenderName, strSenderEmail, strSubject, strMessage, filesAttachement );
  426.     }

  427.     /**
  428.      * Send a text message asynchronously with attached files. The message is queued until a daemon thread send all awaiting messages
  429.      *
  430.      * @param strRecipientsTo
  431.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  432.      * @param strRecipientsCc
  433.      *            The recipients list of the carbon copies .
  434.      * @param strRecipientsBcc
  435.      *            The recipients list of the blind carbon copies .
  436.      * @param strSenderName
  437.      *            The sender name.
  438.      * @param strSenderEmail
  439.      *            The sender email address.
  440.      * @param strSubject
  441.      *            The message subject.
  442.      * @param strMessage
  443.      *            The message.
  444.      * @param filesAttachement
  445.      *            The list of attached files.
  446.      */
  447.     public static void sendMailMultipartText( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName,
  448.             String strSenderEmail, String strSubject, String strMessage, List<FileAttachment> filesAttachement )
  449.     {
  450.         sendMailMultipartText( strRecipientsTo, strRecipientsCc, strRecipientsBcc, strSenderName, strSenderEmail, strSubject, strMessage, filesAttachement,
  451.                 false );
  452.     }

  453.     /**
  454.      * Send a text message asynchronously with attached files. The message is queued until a daemon thread send all awaiting messages
  455.      *
  456.      * @param strRecipientsTo
  457.      *            The list of the main recipients email.Every recipient must be separated by the mail separator defined in config.properties
  458.      * @param strRecipientsCc
  459.      *            The recipients list of the carbon copies .
  460.      * @param strRecipientsBcc
  461.      *            The recipients list of the blind carbon copies .
  462.      * @param strSenderName
  463.      *            The sender name.
  464.      * @param strSenderEmail
  465.      *            The sender email address.
  466.      * @param strSubject
  467.      *            The message subject.
  468.      * @param strMessage
  469.      *            The message.
  470.      * @param filesAttachement
  471.      *            The list of attached files.
  472.      * @param bUniqueRecipientTo
  473.      *            true if the mail must be send unitarily for each recipient
  474.      */
  475.     public static void sendMailMultipartText( String strRecipientsTo, String strRecipientsCc, String strRecipientsBcc, String strSenderName,
  476.             String strSenderEmail, String strSubject, String strMessage, List<FileAttachment> filesAttachement, boolean bUniqueRecipientTo )
  477.     {
  478.         MailItem item = new MailItem( );
  479.         item.setRecipientsTo( strRecipientsTo );
  480.         item.setRecipientsCc( strRecipientsCc );
  481.         item.setRecipientsBcc( strRecipientsBcc );
  482.         item.setSenderName( strSenderName );
  483.         item.setSenderEmail( strSenderEmail );
  484.         item.setSubject( strSubject );
  485.         item.setMessage( strMessage );
  486.         item.setFormat( MailItem.FORMAT_MULTIPART_TEXT );
  487.         item.setFilesAttachement( filesAttachement );
  488.         item.setUniqueRecipientTo( bUniqueRecipientTo );

  489.         enqueue( item );
  490.     }

  491.     /**
  492.      * Shutdown the service
  493.      */
  494.     public static void shutdown( )
  495.     {
  496.         // if there is mails that have not been sent call the daemon to flush the list
  497.         Daemon daemon = AppDaemonService.getDaemon( MailSenderDaemon.DAEMON_ID );

  498.         if ( daemon != null )
  499.         {
  500.             daemon.run( );
  501.         }
  502.     }

  503.     /**
  504.      * Returns a no reply email address defined in config.properties
  505.      *
  506.      * @return A no reply email
  507.      */
  508.     public static String getNoReplyEmail( )
  509.     {
  510.         String strDefault = AppPropertiesService.getProperty( PROPERTY_MAIL_NOREPLY_EMAIL );

  511.         return DatastoreService.getDataValue( KEY_NO_REPLY_EMAIL, strDefault );
  512.     }

  513.     /**
  514.      * Returns the mail queue
  515.      *
  516.      * @return the mail queue
  517.      */
  518.     public static IMailQueue getQueue( )
  519.     {
  520.         return SpringContextService.getBean( BEAN_MAIL_QUEUE );
  521.     }

  522.     /**
  523.      * Extract a collection of elements to be attached to a mail from an HTML string.
  524.      *
  525.      * The collection contains the Url used for created DataHandler for each url associated with an HTML tag img, script or link. Those urls must start with the
  526.      * url strBaseUrl.
  527.      *
  528.      * @param strHtml
  529.      *            The HTML code.
  530.      * @param strBaseUrl
  531.      *            The base url, can be null in order to extract all urls.
  532.      * @param useAbsoluteUrl
  533.      *            Determine if we use absolute or relative url for attachement content-location
  534.      * @return a collection of UrlAttachment Object for created DataHandler associated with attachment urls.
  535.      */
  536.     public static List<UrlAttachment> getUrlAttachmentList( String strHtml, String strBaseUrl, boolean useAbsoluteUrl )
  537.     {
  538.         return MailUtil.getUrlAttachmentList( strHtml, strBaseUrl, useAbsoluteUrl );
  539.     }

  540.     /**
  541.      * Return a String that contains a list of recipients separated with mail separator
  542.      *
  543.      * @param listRecipients
  544.      *            a list of string recipients
  545.      * @return a String that contains a list of recipients separated with mail separator
  546.      */
  547.     public static String getStrRecipients( List<String> listRecipients )
  548.     {
  549.         return MailUtil.getStrRecipients( listRecipients );
  550.     }

  551.     /**
  552.      * Get a string that contains an html link to the site back office or front office.
  553.      *
  554.      * @param strBaseUrl
  555.      *            The base url of the site
  556.      * @param linkToFrontOffice
  557.      *            True if the link should be directed to the front office, false if it should be directed to the back office.
  558.      * @return A string containing an html link.
  559.      */
  560.     public static String getSiteLink( String strBaseUrl, boolean linkToFrontOffice )
  561.     {
  562.         StringBuilder sb = new StringBuilder( );
  563.         String strSiteName = PortalService.getSiteName( );

  564.         if ( strSiteName != null )
  565.         {
  566.             sb.append( "<a title=\"" );
  567.             sb.append( strSiteName );
  568.             sb.append( "\" href=\"" );
  569.             sb.append( strBaseUrl );

  570.             String strUrl;

  571.             if ( linkToFrontOffice )
  572.             {
  573.                 strUrl = AppPathService.getPortalUrl( );
  574.             }
  575.             else
  576.             {
  577.                 strUrl = AppPathService.getAdminMenuUrl( );
  578.             }

  579.             if ( strUrl != null )
  580.             {
  581.                 sb.append( strUrl );
  582.             }

  583.             sb.append( "\" >" );
  584.             sb.append( strSiteName );
  585.             sb.append( "</a>" );
  586.         }

  587.         return sb.toString( );
  588.     }
  589. }