001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.mail;
029
030import org.opencms.main.CmsLog;
031
032import org.apache.commons.logging.Log;
033import org.apache.commons.mail.Email;
034import org.apache.commons.mail.EmailException;
035
036/**
037 * Sends an email using a Thread, so that the application can
038 * continue without waiting for the mail to be send.<p>
039 *
040 * @since 6.0.0
041 */
042public class CmsMailTransport extends Thread {
043
044    /** The log object for this class. */
045    private static final Log LOG = CmsLog.getLog(CmsMailTransport.class);
046
047    /** The email to be send. */
048    private Email m_email;
049
050    /**
051     * Creates a new CmsMailTransport.<p>
052     *
053     * @param email the email to be send with this transport
054     */
055    public CmsMailTransport(Email email) {
056
057        m_email = email;
058    }
059
060    /**
061     * @see java.lang.Thread#run()
062     */
063    @Override
064    public void run() {
065
066        try {
067            m_email.send();
068        } catch (EmailException e) {
069            if (LOG.isErrorEnabled()) {
070                LOG.error(Messages.get().getBundle().key(Messages.LOG_SEND_MAIL_ERR_0), e);
071            }
072        }
073    }
074
075    /**
076     * Sends the email in this transport object,
077     * same as calling <code>start()</code>.<p>
078     */
079    public void send() {
080
081        start();
082    }
083}