Example usage for com.liferay.portal.kernel.log LogUtil log

List of usage examples for com.liferay.portal.kernel.log LogUtil log

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.log LogUtil log.

Prototype

public static void log(Log log, Throwable throwable, String message) 

Source Link

Usage

From source file:com.liferay.petra.mail.MailEngine.java

License:Open Source License

private static void _send(Session session, Message message, InternetAddress[] bulkAddresses, int batchSize)
        throws MailEngineException {

    try {//from  ww w . j  av  a2s  . c  om
        boolean smtpAuth = GetterUtil.getBoolean(_getSMTPProperty(session, "auth"));
        String smtpHost = _getSMTPProperty(session, "host");
        int smtpPort = GetterUtil.getInteger(_getSMTPProperty(session, "port"), Account.PORT_SMTP);
        String user = _getSMTPProperty(session, "user");
        String password = _getSMTPProperty(session, "password");

        if (smtpAuth && Validator.isNotNull(user) && Validator.isNotNull(password)) {

            String protocol = GetterUtil.getString(session.getProperty("mail.transport.protocol"),
                    Account.PROTOCOL_SMTP);

            Transport transport = session.getTransport(protocol);

            transport.connect(smtpHost, smtpPort, user, password);

            Address[] addresses = null;

            if (ArrayUtil.isNotEmpty(bulkAddresses)) {
                addresses = bulkAddresses;
            } else {
                addresses = message.getAllRecipients();
            }

            for (int i = 0;; i++) {
                Address[] batchAddresses = _getBatchAddresses(addresses, i, batchSize);

                if (ArrayUtil.isEmpty(batchAddresses)) {
                    break;
                }

                transport.sendMessage(message, batchAddresses);
            }

            transport.close();
        } else {
            if (ArrayUtil.isNotEmpty(bulkAddresses)) {
                int curBatch = 0;

                Address[] portion = _getBatchAddresses(bulkAddresses, curBatch, batchSize);

                while (ArrayUtil.isNotEmpty(portion)) {
                    Transport.send(message, portion);

                    curBatch++;

                    portion = _getBatchAddresses(bulkAddresses, curBatch, batchSize);
                }
            } else {
                Transport.send(message);
            }
        }
    } catch (MessagingException me) {
        if (me.getNextException() instanceof SocketException) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to connect to a valid mail server. Please "
                        + "make sure one is properly configured: " + me.getMessage());
            }
        } else {
            LogUtil.log(_log, me, "Unable to send message: " + me.getMessage());
        }

        if (_isThrowsExceptionOnFailure()) {
            throw new MailEngineException(me);
        }
    }
}