All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kapil.framework.email.DirectEmailDispatcher Maven / Gradle / Ivy

Go to download

This is a set of utilities and classes that I have found useful over the years. In my career spanning over a decade, I have time and again written the same code or some part of the code over and over again. I never found the time to collate the details in a reusable library. This project will be a collection of such files. The work that I have been doing is more than 5 years old, however the project has been conceived in 2011.

The newest version!
/**
 * File name:     DirectEmailProcessor.java
 * Author:        Sapient Corporation
 * Creation date: Jun 07, 2007
 */
package com.kapil.framework.email;

import org.apache.commons.lang.exception.ExceptionUtils;

import com.kapil.framework.logger.ILogger;
import com.kapil.framework.logger.LogFactory;

/**
 * Processes an email in real time, i.e. sends it immediately.
 */
public final class DirectEmailDispatcher extends BaseEmailDispatcher
{
    private static final ILogger LOGGER = LogFactory.getInstance().getLogger(DirectEmailDispatcher.class);
    
    
    public DirectEmailDispatcher(EmailServer server)
    {
        super(server);
    }
    
    
    /**
     * Sends an email using an email host.
     * 
     * @param emailContent An {@link EmailVO} object containing information about the email to be sent.
     * @return boolean true if the email is sent successfully, false otherwise.
     */
    public boolean dispatchEmail(EmailVO emailContent)
    {
        boolean result = false;

        try
        {
            super.sendEmail(emailContent);
            result = true;
        }
        catch (Exception e)
        {
            // On Development environment, the processor is called with a non-existent email host name deliberately.  This is required to ensure
            // that a real email server isn't bombarded with multiple emails in a working day.  However, using a dummy email host name throws
            // exceptions.  The check below ensures that the log message isn't output on the Development environment, as it unnecessarily
            // confuses users.
            LOGGER.error("An error occurred while attempting to send an email message.  Details are provided below.");
            LOGGER.error(ExceptionUtils.getFullStackTrace(e));
        }

        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy