function run_mail_queue()
{
    global $config;
    // Get pending mails
    $filter = array('status' => 0);
    $mails = get_db_all_rows_filter('tpending_mail', $filter);
    // No pending mails
    if ($mails === false) {
        return;
    }
    // Init mailer
    $mailer = null;
    try {
        // Use local mailer if host not provided - Attach not supported !!
        if (empty($config['smtp_host'])) {
            // Empty snmp conf. System sendmail transport
            $transport = mail_get_transport();
            $mailer = mail_get_mailer($transport);
        } else {
            $mailer = mail_get_mailer();
        }
    } catch (Exception $e) {
        integria_logwrite(sprintf("Mail transport failure: %s", $e->getMessage()));
        return;
    }
    foreach ($mails as $email) {
        try {
            //Check if the email was sent at least once
            if (mail_send($email, $mailer) > 0) {
                process_sql_delete('tpending_mail', array('id' => (int) $email['id']));
            } else {
                throw new Exception(__('The mail send failed'));
            }
        } catch (Exception $e) {
            $retries = $email['attempts'] + 1;
            if ($retries > $config['smtp_queue_retries']) {
                $status = 1;
                insert_event('MAIL_FAILURE', 0, 0, $email['recipient'] . ' - ' . $e->getMessage());
            } else {
                $status = 0;
            }
            $values = array('status' => $status, 'attempts' => $retries);
            $where = array('id' => (int) $email['id']);
            process_sql_update('tpending_mail', $values, $where);
            $to = trim(ascii_output($email['recipient']));
            integria_logwrite(sprintf('SMTP error sending to %s (%s)', $to, $e->getMessage()));
        }
    }
}
Exemple #2
0
        if (!empty($port)) {
            $transport_conf['port'] = $port;
        }
        if (!empty($user)) {
            $transport_conf['user'] = $user;
        }
        if (!empty($pass)) {
            $transport_conf['pass'] = $pass;
        }
        if (!empty($proto)) {
            $transport_conf['proto'] = $proto;
        }
    }
    try {
        // If the transport can connect, it will not throw an exception
        mail_get_transport($transport_conf);
        // Success
        echo json_encode(array('result' => true, 'message' => __('Success')));
        return;
    } catch (Exception $e) {
        // Failure
        echo json_encode(array('result' => false, 'message' => $e->getMessage()));
        return;
    }
}
if ($change_template_alert) {
    echo "<div style='float: left;'><img style='padding:10px;' src='images/icon_delete.png' alt='" . __('Delete') . "'></div>";
    echo "<div style='float: left; font-size:15px; font-weight: bold; margin-top:32px;'><b>" . __('Are you sure you want to change action?') . "</b></br>";
    echo "<span style='font-size:13px; font-weight: normal; line-height: 1.5em;'>" . __('Remove template contents') . "</span></div>";
    echo '<form id="change_template_form" method="post">';
    echo print_submit_button(__('Delete'), "delete_btn", false, 'class="sub close" width="160px;"', true);
/**
 * Returns a valid mailer for Swift.
 *
 * @param Swift_Transport $transport Mail transport (optional).
 *   If the transport is empty, a transport will be created using
 *   the $config values. If $config['smtp_host'] is empty, the mailer
 *   will be the local sendmail. 
 *
 * @return Swift_Mailer The mailer which can send messages.
 *
 * @throws Swift_TransportException if the transport can't connect
 */
function mail_get_mailer($transport = null)
{
    global $config;
    if (empty($transport)) {
        $transport_conf = array();
        if (!empty($config['smtp_host'])) {
            $transport_conf['host'] = $config['smtp_host'];
            if (!empty($config['smtp_port'])) {
                $transport_conf['port'] = $config['smtp_port'];
            }
            if (!empty($config['smtp_user'])) {
                $transport_conf['user'] = $config['smtp_user'];
            }
            if (!empty($config['smtp_pass'])) {
                $transport_conf['pass'] = $config['smtp_pass'];
            }
            if (!empty($config['smtp_proto'])) {
                $transport_conf['proto'] = $config['smtp_proto'];
            }
        }
        $transport = mail_get_transport($transport_conf);
    }
    return Swift_Mailer::newInstance($transport);
}