/**
  * @see CEvent::HandleEvent()
  * @see bxmail()
  *
  * @param string $to
  * @param string $subject
  * @param string $message
  * @param string $additionalHeaders Additional headers setted by Bitrix.
  *
  * @return bool
  */
 function custom_mail($to, $subject, $message, $additionalHeaders = '')
 {
     // Cache to send many mails in one script run.
     static $transport, $sender;
     try {
         if (!$sender) {
             if (!$transport) {
                 $host = COption::GetOptionString('sh.mailtransport', 'host');
                 if (COption::GetOptionInt('sh.mailtransport', 'ssl')) {
                     $host = 'ssl://' . $host;
                 }
                 $port = COption::GetOptionInt('sh.mailtransport', 'port');
                 $user = COption::GetOptionString('sh.mailtransport', 'username');
                 $password = COption::GetOptionString('sh.mailtransport', 'password');
                 $transport = new Net_SMTP($host, $port);
                 if (PEAR::isError($connectionResult = $transport->connect())) {
                     throw new Capall_MailTransportException($connectionResult);
                 }
                 // TODO Server without authentication?..
                 if (PEAR::isError($authenticationResult = $transport->auth($user, $password))) {
                     throw new Capall_MailTransportException($authenticationResult);
                 }
             }
             $sender = new Capall_MailTransport_Sender($transport);
         }
         $sender->send($to, $subject, $message, $additionalHeaders);
         return true;
     } catch (Capall_MailTransportException $error) {
         CEventLog::Log('WARNING', 'MAILTRANSPORT_ERROR', 'sh.mailtransport', null, $error->__toString());
         return false;
     } catch (Exception $error) {
         // Unknown error...
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Applies action
  *
  * @return  boolean success
  */
 protected function main()
 {
     $recipient = Nexista_Path::parseInlineFlow($this->params['recipient']);
     $sender = Nexista_Path::parseInlineFlow($this->params['sender']);
     $subject = "Subject: " . Nexista_Path::parseInlineFlow($this->params['subject']) . "\n";
     $body = Nexista_Flow::getbypath($this->params['body']);
     $host = Nexista_Path::parseInlineFlow($this->params['host']);
     if (require 'Net/SMTP.php') {
         $smtp = new Net_SMTP($host);
         $e = $smtp->connect();
         $smtp->mailFrom($sender);
         $disclosed_recipients = "To: ";
         if (is_array($recipient)) {
             foreach ($recipient as $to) {
                 if (PEAR::isError($res = $smtp->rcptTo($to))) {
                     die("Unable to add recipients {$to}: " . $res->getMessage() . "\n");
                 }
                 $disclosed_recipients .= $to;
             }
         } else {
             if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
                 die("Unable to add single recipient {$recipient} for {$host}: " . $res->getMessage() . "\n");
             }
             $disclosed_recipients .= $recipient;
         }
         $disclosed_recipients .= "\n";
         $headers = $disclosed_recipients . $subject;
         $smtp->data($headers . "\r\n" . $body);
         $smtp->disconnect();
     } else {
         // try using mail()
     }
 }
Exemplo n.º 3
0
 /**
  * Build a standardized string describing the current SMTP error.
  *
  * @param string $text       Custom string describing the error context.
  * @param PEAR_Error $error  PEAR_Error object.
  * @param integer $e_code    Error code.
  *
  * @throws Horde_Mail_Exception
  */
 protected function _error($text, $error, $e_code)
 {
     /* Split the SMTP response into a code and a response string. */
     list($code, $response) = $this->_smtp->getResponse();
     /* Abort current SMTP transaction. */
     $this->_smtp->rset();
     /* Build our standardized error string. */
     throw new Horde_Mail_Exception($text . ' [SMTP: ' . $error->getMessage() . " (code: {$code}, response: {$response})]", $e_code);
 }
Exemplo n.º 4
0
    public function deliver(&$Mailer, $settings = array())
    {
        $Message =& $Mailer->Message;
        
        $SmtpClient =& Mail::factory('smtp', $settings);

        include_once 'Net/SMTP.php';

        if (!($smtp = new Net_SMTP($SmtpClient->host, $SmtpClient->port, $SmtpClient->localhost))) {
            return PEAR::raiseError('unable to instantiate Net_SMTP object');
        }

        if ($SmtpClient->debug) {
            $smtp->setDebug(true);
        }

        if (PEAR::isError($smtp->connect($SmtpClient->timeout))) {
            trigger_error('unable to connect to smtp server '.$SmtpClient->host.':'.$SmtpClient->port, E_USER_NOTICE);
            return false;
        }

        if ($SmtpClient->auth) {
            $method = is_string($SmtpClient->auth) ? $SmtpClient->auth : '';

            if (PEAR::isError($smtp->auth($SmtpClient->username, $SmtpClient->password, $method))) {
                trigger_error('unable to authenticate to smtp server', E_USER_ERROR);
            }
        }

        $from = is_array($Message->from) ? array_shift(array_values($Message->from)) : $Message->from;

        if (PEAR::isError($smtp->mailFrom($from))) {
            trigger_error('unable to set sender to [' . $from . ']', E_USER_ERROR);
        }

        $recipients = $SmtpClient->parseRecipients($Message->getRecipients());
        
        if (PEAR::isError($recipients)) {
            return $recipients;
        }

        foreach ($recipients as $recipient) {
            if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
                return PEAR::raiseError('unable to add recipient [' .
                $recipient . ']: ' . $res->getMessage());
            }
        }

        if (PEAR::isError($smtp->data($Mailer->getRawMessage()))) {
            return PEAR::raiseError('unable to send data');
        }

        $smtp->disconnect();
    }
Exemplo n.º 5
0
 function check()
 {
     $ff = HTML_FlexyFramework::get();
     if (empty($ff->Core_Notify) || empty($ff->Core_Notify['routes'])) {
         return;
     }
     $helo = $this->getHelo();
     echo "HELO : {$helo} \n";
     $error = array();
     foreach ($ff->Core_Notify['routes'] as $server => $settings) {
         if (empty($settings['domains']) || empty($settings['username']) || empty($settings['password'])) {
             $error[] = "{$server} - Missing domains / username / password";
             continue;
         }
         $socket_options = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false));
         if (empty($settings['port'])) {
             $settings['port'] = 25;
         }
         $smtp = new Net_SMTP($server, $settings['port'], $helo, false, 0, $socket_options);
         //            $smtp->setDebug(true);
         echo "Connecting : {$server}:{$settings['port']} \n";
         $res = $smtp->connect(10);
         if (is_a($res, 'PEAR_Error')) {
             $error[] = "{$server} - Cound not connect";
             continue;
         }
         echo "Login As : {$settings['username']}:{$settings['password']} \n";
         $res = $smtp->auth($settings['username'], $settings['password']);
         if (is_a($res, 'PEAR_Error')) {
             $error[] = "{$server} - Cound not login";
             continue;
         }
     }
     if (!empty($error)) {
         print_r($error);
         exit;
     }
     return;
 }
 /**
  * @see CEvent::HandleEvent()
  * @see bxmail()
  *
  * @param string $to
  * @param string $subject
  * @param string $message
  * @param string $additionalHeaders
  */
 public function send($to, $subject, $message, $additionalHeaders = '')
 {
     preg_match('/From: (.+)\\n/i', $additionalHeaders, $matches);
     list(, $from) = $matches;
     if (PEAR::isError($settingResult = $this->_transport->mailFrom(trim($from)))) {
         throw new Capall_MailTransportException($settingResult);
     }
     // $to string may contains many recipients.
     $recipients = explode(',', $to);
     foreach ($recipients as $recipient) {
         $recipient = trim($recipient);
         if (!empty($recipient)) {
             if (PEAR::isError($settingResult = $this->_transport->rcptTo($recipient))) {
                 throw new Capall_MailTransportException($settingResult);
             }
         }
     }
     $eol = CAllEvent::GetMailEOL();
     $additionalHeaders .= $eol . 'To: ' . $to;
     $additionalHeaders .= $eol . 'Subject: ' . $subject;
     if (PEAR::isError($sendingResult = $this->_transport->data($additionalHeaders . "\r\n\r\n" . $message))) {
         throw new Capall_MailTransportException($sendingResult);
     }
 }
Exemplo n.º 7
0
 public function post(RFC5322Message $message)
 {
     $message->getHeader()->setValue("To", $this->recipient);
     $conn = new Net_SMTP($this->host->getHost(), $this->host->getPort());
     $conn->connect();
     $conn->mailFrom($this->bounceaddress);
     $conn->rcptTo($this->recipient);
     $conn->data($message->getPlain());
     $conn->disconnect();
     return true;
 }
Exemplo n.º 8
0
function send_email($U)
{
    #send_email is just a function that takes an email input, together with a host and send
    #INPUTS: $U = array($email, $subject, $message) =>EMAIL CAN BE AN ARRAY OF RECIPIENTS :-)
    extract($U);
    require_once S3DB_SERVER_ROOT . '/pearlib/Net/SMTP.php';
    $host = $GLOBALS['s3db_info']['server']['email_host'];
    $from = '*****@*****.**';
    if (!is_array($email)) {
        $email = array($email);
    }
    $rcpt = $email;
    $subj = 'Subject: ' . $subject;
    $body = $message;
    /* Create a new Net_SMTP object. */
    if (!($smtp = new Net_SMTP($host))) {
        die("Unable to instantiate Net_SMTP object\n");
    }
    /* Connect to the SMTP server. */
    if (PEAR::isError($e = $smtp->connect())) {
        die($e->getMessage() . "\n");
    }
    /* Send the 'MAIL FROM:' SMTP command. */
    if (PEAR::isError($smtp->mailFrom($from))) {
        die("Unable to set sender to <{$from}>\n");
    }
    /* Address the message to each of the recipients. */
    foreach ($rcpt as $to) {
        if (PEAR::isError($res = $smtp->rcptTo($to))) {
            die("Unable to add recipient <{$to}>: " . $res->getMessage() . "\n");
        }
    }
    /* Set the body of the message. */
    if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
        die("Unable to send data\n");
    }
    /* Disconnect from the SMTP server. */
    $smtp->disconnect();
}
Exemplo n.º 9
0
<?php

return;
// Security because webroot.
require 'Net/SMTP.php';
$host = 'mail.example.com';
$from = '*****@*****.**';
$rcpt = array('*****@*****.**', '*****@*****.**');
$subj = "Subject: Test Message\n";
$body = "Body Line 1\nBody Line 2";
/* Create a new Net_SMTP object. */
if (!($smtp = new Net_SMTP($host))) {
    die("Unable to instantiate Net_SMTP object\n");
}
/* Connect to the SMTP server. */
if (PEAR::isError($e = $smtp->connect())) {
    die($e->getMessage() . "\n");
}
$smtp->auth('username', 'password');
/* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
    die("Unable to set sender to <{$from}>\n");
}
/* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
    if (PEAR::isError($res = $smtp->rcptTo($to))) {
        die("Unable to add recipient <{$to}>: " . $res->getMessage() . "\n");
    }
}
/* Set the body of the message. */
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
Exemplo n.º 10
0
<?php

require 'Net/SMTP.php';
$host = 'mail.example.com';
$from = '*****@*****.**';
$rcpt = array('*****@*****.**', '*****@*****.**');
$subj = "Subject: Test Message\n";
$body = "Body Line 1\nBody Line 2";
/* Create a new Net_SMTP object. */
if (!($smtp = new Net_SMTP($host))) {
    die("Unable to instantiate Net_SMTP object\n");
}
/* Connect to the SMTP server. */
if (PEAR::isError($e = $smtp->connect())) {
    die($e->getMessage() . "\n");
}
/* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
    die("Unable to set sender to <{$from}>\n");
}
/* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
    if (PEAR::isError($res = $smtp->rcptTo($to))) {
        die("Unable to add recipient <{$to}>: " . $res->getMessage() . "\n");
    }
}
/* Set the body of the message. */
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
    die("Unable to send data\n");
}
/* Disconnect from the SMTP server. */
Exemplo n.º 11
0
 /**
  * Implements Mail::send() function using SMTP.
  * 
  * @param mixed $recipients Either a comma-seperated list of recipients
  *              (RFC822 compliant), or an array of recipients,
  *              each RFC822 valid. This may contain recipients not
  *              specified in the headers, for Bcc:, resending
  *              messages, etc.
  *
  * @param array $headers The array of headers to send with the mail, in an
  *              associative array, where the array key is the
  *              header name (ie, 'Subject'), and the array value
  *              is the header value (ie, 'test'). The header
  *              produced from those values would be 'Subject:
  *              test'.
  *
  * @param string $body The full text of the message body, including any
  *               Mime parts, etc.
  *
  * @return mixed Returns true on success, or a PEAR_Error
  *               containing a descriptive error message on
  *               failure.
  * @access public
  */
 function send($recipients, $headers, $body)
 {
     include_once 'Net/SMTP.php';
     if (!($smtp = new Net_SMTP($this->host, $this->port))) {
         return new PEAR_Error('unable to instantiate Net_SMTP object');
     }
     if (PEAR::isError($smtp->connect())) {
         return new PEAR_Error('unable to connect to smtp server ' . $this->host . ':' . $this->port);
     }
     if ($this->auth) {
         if (PEAR::isError($smtp->auth($this->username, $this->password))) {
             return new PEAR_Error('unable to authenticate to smtp server');
         }
         if (PEAR::isError($smtp->identifySender())) {
             return new PEAR_Error('unable to identify smtp server');
         }
     }
     list($from, $text_headers) = $this->prepareHeaders($headers);
     if (!isset($from)) {
         return new PEAR_Error('No from address given');
     }
     if (PEAR::isError($smtp->mailFrom($from))) {
         return new PEAR_Error('unable to set sender to [' . $from . ']');
     }
     $recipients = $this->parseRecipients($recipients);
     foreach ($recipients as $recipient) {
         if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
             return new PEAR_Error('unable to add recipient [' . $recipient . ']: ' . $res->getMessage());
         }
     }
     if (PEAR::isError($smtp->data($text_headers . "\n" . $body))) {
         return new PEAR_Error('unable to send data');
     }
     $smtp->disconnect();
     return true;
 }
Exemplo n.º 12
0
function smtp_send($from, $recips, $body, $ehlo = "maia")
{
    global $dbh;
    global $lang;
    $select = "SELECT smtp_server, smtp_port FROM maia_config WHERE id = 0";
    $sth = $dbh->query($select);
    if ($row = $sth->fetchrow()) {
        $host = $row["smtp_server"];
        $port = $row["smtp_port"];
    }
    $sth->free();
    $rcpt = explode(" ", $recips);
    /* Create a new Net_SMTP object. */
    if (!($smtp = new Net_SMTP($host, $port, $ehlo))) {
        $smtp->disconnect();
        return "550 " . $lang['error_connect'] . ": " . "Unable to instantiate Net_SMTP object\n";
    }
    /* Connect to the SMTP server. */
    if (PEAR::isError($e = $smtp->connect())) {
        $smtp->disconnect();
        return "550 " . $lang['error_connect'] . ": " . $e->getMessage() . "\n";
    }
    /* Send the 'MAIL FROM:' SMTP command. */
    if (PEAR::isError($smtp->mailFrom($from))) {
        return "550 " . $lang['error_mail'];
    }
    /* Address the message to each of the recipients. */
    foreach ($rcpt as $to) {
        if (PEAR::isError($res = $smtp->rcptTo($to))) {
            $smtp->disconnect();
            return "550 " . $lang['error_rcpt'] . ": " . $res->getMessage() . "\n";
        }
    }
    /* Set the body of the message. */
    if (PEAR::isError($smtp->data($body))) {
        $smtp->disconnect();
        return "550 " . $lang['error_body'];
    }
    $response = $smtp->getResponse();
    /* Disconnect from the SMTP server. */
    $smtp->disconnect();
    return join(" ", $response);
}
Exemplo n.º 13
0
 function Mail($to, $to_name, $from, $from_name, $subject, $text, $type = 'text')
 {
     //----
     include_once 'lib/PEAR/Net/SMTP.php';
     //----
     $to_name = $this->MailEsc($to_name);
     $from_name = $this->MailEsc($from_name);
     $subject = $this->MailEsc($subject);
     //----
     $headers = "MIME-Version: 1.0\r\n" . "Return-Path: {$from}\r\n" . "X-Mailer: MQL4 site\r\n" . "Date: " . date('r') . "\r\n" . "Message-Id: " . time() . '.' . preg_replace('/[^0-9a-z-]+/iu', '-', $to) . "@wr.com\r\n";
     //----
     if ($type == 'text') {
         $headers .= "Content-type: text/plain; charset=UTF-8\r\n";
     } else {
         $headers .= "Content-type: text/html; charset=UTF-8\r\n";
     }
     //----
     if ($to_name != '') {
         $headers .= "To: {$to_name} <{$to}>\r\n";
     } else {
         $headers .= "To: {$to}\r\n";
     }
     if ($from_name != '') {
         $headers .= "From: {$from_name} <{$from}>\r\n";
     } else {
         $headers .= "From: {$from}\r\n";
     }
     //----
     $smtp = new Net_SMTP(T_SMTP_SERVER, 25, T_SMTP_LOGIN);
     $smtp->connect();
     //----
     if (PEAR::isError($e = $smtp->auth(T_SMTP_LOGIN, T_SMTP_PASSWORD))) {
         $smtp->disconnect();
         return false;
     }
     //----
     if (PEAR::isError($smtp->mailFrom($from))) {
         $smtp->disconnect();
         return false;
     }
     //----
     if (PEAR::isError($smtp->rcptTo($to))) {
         $smtp->disconnect();
         return false;
     }
     //----
     if (PEAR::isError($smtp->data("Subject: {$subject}\r\n" . $headers . "\r\n" . $text))) {
         $smtp->disconnect();
         return false;
     }
     //----
     $smtp->disconnect();
     //----
     return true;
 }
Exemplo n.º 14
0
    $vars['htaccess_error'] = true;
}
if (isset($_SESSION['missing_ext'])) {
    $vars['missing_ext'] = '<h2>Optional PHP Extensions</h2>
	<p>The following optional PHP extensions are missing. You may enable
	additional @Mail features if you install them</p><ul>';
    foreach ($_SESSION['missing_ext'] as $ext) {
        $vars['missing_ext'] .= "<li>{$ext} functions</i>";
    }
    $vars['missing_ext'] .= '</ul>';
}
$vars['output'] = parse("{$htmlPath}/step7.phtml", $vars);
// Send a test email
set_include_path('../' . PATH_SEPARATOR . get_include_path());
include '../libs/PEAR/Net/SMTP.php';
$smtp = new Net_SMTP($pref['smtphost']);
if ($smtp->connect(10) === true) {
    $msg = <<<EOF
To: {$pref['admin_email']}
From: {$pref['admin_email']}
Subject: @MailPHP {$pref['version']} test message [{$_SESSION['reg']['hostname']}]

Hello,

This is only a test message of your configuration.

The @Mail software can successfully send email via the SMTP server {$pref['smtphost']}.

This will allow users to send email via the @Mail web-interface.

Enjoy
Exemplo n.º 15
0
 $webmailDir = realpath('../');
 if ($_POST['subscribe'] == 1) {
     if (ini_get('allow_url_fopen')) {
         file_get_contents("http://calacode.cmail1.com/s/337247/?cm-337247-337247={$adminEmail}");
     } else {
         // dirty hack using <img> tag...
         $_SESSION['subscribe_hack'] = 1;
     }
 }
 if (empty($smtpHost)) {
     $smtpHost = 'localhost';
 }
 // Try to connect to SMTP host
 set_include_path('../' . PATH_SEPARATOR . get_include_path());
 require_once '../libs/PEAR/Net/SMTP.php';
 $smtp = new Net_SMTP($smtpHost);
 $con = $smtp->connect();
 if (isset($_POST['smtp_auth'])) {
     $_SESSION['pref']['smtpauth_username'] = $_POST['smtpauth_username'];
     $_SESSION['pref']['smtpauth_password'] = $_POST['smtpauth_password'];
     if ($smtp->auth($_SESSION['pref']['smtpauth_username'], $_SESSION['pref']['smtpauth_password']) !== true) {
         $errors['smtp_error'] .= "The SMTP authentication details provided are incorrect. Please verify you have the correct username and password. Check your SMTP configuration for further details, or use an SMTP server which you have IP relay permissions.";
         $vars['smtphost'] = $_SESSION['pref']['smtphost'];
         $vars['smtpauth_username'] = $_SESSION['pref']['smtpauth_username'];
         $vars['smtpauth_password'] = $_SESSION['pref']['smtpauth_password'];
         $vars['admin_email'] = $_SESSION['pref']['admin_email'];
         $vars['smtp_auth_error'] = '1';
         $vars['smtp_auth_check'] = 'checked';
     } else {
         $_SESSION['pref']['smtpauth_username'] = '';
         $_SESSION['pref']['smtpauth_password'] = '';
Exemplo n.º 16
0
 function deliver($catch_smtp_error = true)
 {
     global $pref, $atmail, $domains;
     $rcpt = array();
     // Make an array with the email addresses to deliver the
     // message to
     /*
     	    $rcpt = array_merge($rcpt, preg_split('/;|,/', $this->EmailTo));
     
     if (!empty($this->EmailCC))
     	$rcpt = array_merge($rcpt, preg_split('/;|,/', $this->EmailCC));
     
     if (!empty($this->EmailBCC))
     	$rcpt = array_merge($rcpt, preg_split('/;|,/', $this->EmailBCC));
     */
     $rcpt = $this->EmailTo;
     if (!empty($this->EmailCC)) {
         $rcpt .= ",{$this->EmailCC}";
     }
     if (!empty($this->EmailBCC)) {
         $rcpt .= ",{$this->EmailBCC}";
     }
     // Remove personal part - it is not needed for send RCPT cmd
     // and just causes problems for the address parser if it contains
     // certain utf-8 chars (e.g. Japanese)
     $rcpt = preg_replace('/".+?"/', '', $rcpt);
     $rcpt = Mail_RFC822::parseAddressList($rcpt, null, false);
     $mail = array();
     $groupmails = 0;
     // Loop through the non-existant recipients
     foreach ($rcpt as $entry) {
         // The entry is a group email-address
         if ($entry->host == 'Group') {
             $users = $this->abook->getgroup($entry->mailbox);
             foreach ($users as $user) {
                 // Skip emailing the selected user, if local, and the user does not exist any longer
                 if ($this->rcptOK($user)) {
                     $groupmails++;
                     array_push($mail, $user);
                 }
             }
         } elseif ($entry->host == 'SharedGroup') {
             $users = $this->abook->getsharedgroup($entry->mailbox);
             foreach ($users as $user) {
                 // Skip emailing the selected user, if local, and the user does not exist any longer
                 if ($this->rcptOK($user)) {
                     $groupmails++;
                     array_push($mail, $user);
                 }
             }
         } else {
             array_push($mail, stripslashes("{$entry->mailbox}@{$entry->host}"));
         }
     }
     // Block more then X outgoing recipients at a time ( useful to prevent spammers/bots abusing the service )
     if (count($mail) - $groupmails > $pref['max_recipients_per_msg']) {
         $this->smtperror("Cannot send to more than {$pref['max_recipients_per_msg']} users per email message.");
     }
     require_once 'Net/SMTP.php';
     $smtp = new Net_SMTP($pref['smtphost'], null, $_SERVER['HTTP_HOST']);
     //$smtp->setDebug(true);
     if ($smtp->connect(30) !== true) {
         if ($catch_smtp_error) {
             $this->smtperror("Error connecting to {$pref['smtphost']} - Check the hostname resolves, accepts incoming SMTP connections and is active.");
         } else {
             return false;
         }
     }
     // Check if we should use each account's username and password
     // for the SMTP
     if ($pref['smtp_per_account_auth']) {
         $pref['smtpauth_username'] = $atmail->auth->get_username();
         $pref['smtpauth_password'] = $atmail->auth->get_password();
     }
     // Optionally authenticate with the SMTP server
     if ($pref['smtpauth_username'] && $pref['smtpauth_password']) {
         if ($smtp->auth($pref['smtpauth_username'], $pref['smtpauth_password']) !== true) {
             if ($catch_smtp_error) {
                 $this->smtperror("Error authenticating to {$pref['smtphost']} - Check the SMTP authentication is correct");
             } else {
                 $this->smtp_error_msg = "Error authenticating to {$pref['smtphost']} - Check the SMTP authentication is correct";
                 return false;
             }
         }
     }
     $smtp->mailFrom($this->EmailFrom);
     $fails = array();
     //$smtp->setDebug(true);
     foreach ($mail as $v) {
         $res = $smtp->rcptTo($v);
         if (PEAR::isError($res)) {
             if ($catch_smtp_error) {
                 $output = $res->getMessage();
                 $this->smtperror("Could not send message to SMTP server. Check you have access to send messages via the server and that all To/CC/BCC addresses are valid\\nError: {$output}");
                 break;
             } else {
                 $fails[] = $v;
                 continue;
             }
         }
     }
     $res = $smtp->data($this->headers . "\r\n\r\n" . $this->body);
     if (PEAR::isError($res)) {
         if ($catch_smtp_error) {
             $this->smtperror("Message rejected by SMTP server. Check message content and attachments\\nServer Responded: " . $res->getMessage());
         } else {
             $this->smtp_error_msg = "Message rejected by SMTP server. Check message content and attachments\nServer Responded: " . $res->getMessage();
             return false;
         }
     } elseif ($pref['install_type'] == 'standalone') {
         // Only log sent msgs if running only as webmail client
         // as Exim already does this when in server mode
         foreach ($mail as $addr) {
             $addr = preg_replace('/\\s+/', '', $addr);
             $this->log->write_log("SendMail", "WebMail:{$_SERVER['REMOTE_ADDR']}:{$addr}");
         }
     }
     $smtp->disconnect();
     // Reset some fields back to the raw UTF8 copy, since it's sent to the browser
     $this->EmailSubject = $this->RawEmailSubject;
     return $fails;
 }
Exemplo n.º 17
0
function _verifyEmail($email)
{
    if ($arrMxRRs = _getMXHosts($email)) {
        require_once ASCMS_LIBRARY_PATH . '/PEAR/Net/SMTP.php';
        foreach ($arrMxRRs as $arrMxRR) {
            if (!\PEAR::isError($objSMTP = new \Net_SMTP($arrMxRR['EXCHANGE'])) && !\PEAR::isError($objSMTP->connect(2)) && !\PEAR::isError($e = $objSMTP->vrfy($email))) {
                return $objSMTP->getResponse();
            }
        }
        return 0;
    }
    return false;
}
Exemplo n.º 18
0
function open_smtp(&$arr_mail_account, &$smtp, $account_no, $debug_flag)
{
    // account list array, from config.php
    global $arrAccountsSmtp;
    // $account_noの範囲チェック
    if ($account_no <= 0 || $account_no > count($arrAccountsSmtp)) {
        printf("<p>アカウント指定Noが範囲外です<br/>account=%d</p>\n", $account_no);
        return false;
    }
    // メールアカウント情報(サーバ名、ユーザ名、パスワード等)を得る
    $arr_mail_account = GetMailAccount($arrAccountsSmtp[$account_no - 1][1], 'smtp');
    if (!isset($arr_mail_account['server']) || !isset($arr_mail_account['user']) || !isset($arr_mail_account['password']) || strcmp($arr_mail_account['protocol'], 'smtp')) {
        print "<p>メールアカウント管理エラー(server/user/password値が得られないか、protocolがsmtpでない)</p>\n";
        return false;
    }
    // 新しい Net_SMTP オブジェクトを作成します
    if (!($smtp = new Net_SMTP($arr_mail_account['server'], $arr_mail_account['port']))) {
        print "<p>ネットワーク異常(SMTPオブジェクト作成不能)</p>";
        return false;
    }
    // デバッグ出力を、stdoutに送る
    if ($debug_flag) {
        $smtp->setDebug(true);
    }
    // SMTP サーバに接続します
    if (PEAR::isError($e = $smtp->connect())) {
        print "<p>ネットワーク異常(SMTPでコネクション不能)</p>";
        return false;
    }
    // ユーザ名、パスワードを用いてSMTPログオンします
    // (Digest-MD5, CRAMMD5, LOGIN, PLAINの順に暗号強度の高いもので接続します)
    if (PEAR::isError($e = $smtp->auth($arr_mail_account['user'], $arr_mail_account['password']))) {
        $smtp->disconnect();
        print "<p>SMTPサーバの認証に失敗</p>";
        return false;
    }
    printf("<p>接続:%s@%s:%s</p>\n", $arr_mail_account['user'], $arr_mail_account['server'], $arr_mail_account['port']);
    return true;
}
Exemplo n.º 19
0
 /**
  * Sends and e-mail using Net_SMTP.
  *
  * @param Email $email
  * @return string Error message, or null upon success.
  */
 public static function smtp(&$email)
 {
     /*
         if ( isset($GLOBALS['phpmail']) && $GLOBALS['phpmail'] )
         {
           $rfc = new \Mail_RFC822();
           $pureAddresses = $rfc->parseAddressList($email->to());
           foreach( $pureAddresses as $address )
           {
             $to = $address->mailbox. "@". $address->host;
             mail( $to, $email->subject(), $email->body(), $email->headers() );
           }
           return;
         }
     */
     Log::debug("Mailer: subject:[" . $email->subject() . "], from:[" . $email->from() . "], to:" . print_r($email->recipients(), true));
     if (!Config::$smtpHost) {
         $error = "Mailer: no SMTP host supplied";
         Log::debug($error);
         return $error;
     }
     if (!($smtp = new \Net_SMTP(Config::$smtpHost, Config::$smtpPort, $_SERVER['SERVER_NAME']))) {
         $error = "Mailer: unable to instantiate Net_SMTP object";
         Log::debug($error);
         return $error;
     }
     // $smtp->setDebug(true);
     $pear = new \PEAR();
     if ($pear->isError($e = $smtp->connect())) {
         $error = "Mailer: connect error: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     if (Config::$smtpUser && $pear->isError($e = $smtp->auth(Config::$smtpUser, Config::$smtpPass, Config::$smtpAuthType))) {
         $error = "Mailer: authentication error: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     $rfc = new \Mail_RFC822();
     $pureAddresses = $rfc->parseAddressList($email->from());
     $from = $pureAddresses[0]->mailbox . "@" . $pureAddresses[0]->host;
     if ($pear->isError($e = $smtp->mailFrom($from))) {
         $error = "Unable to set sender to [{$from}]: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     foreach ($email->recipients() as $toAddress) {
         $pureAddresses = $rfc->parseAddressList($toAddress);
         foreach ($pureAddresses as $address) {
             $to = $address->mailbox . "@" . $address->host;
             if ($pear->isError($e = $smtp->rcptTo($to))) {
                 $error = "Unable to set recipient to [{$to}]: " . $e->getMessage();
                 Log::debug($error);
                 return $error;
             }
         }
     }
     if ($pear->isError($e = $smtp->data($email->data()))) {
         $error = "Unable to set data: " . $e->getMessage();
         Log::debug($error);
         return $error;
     }
     Log::debug("Mailer: sent: " . $smtp->_arguments[0]);
     $smtp->disconnect();
     return null;
 }
Exemplo n.º 20
0
 /**
  * Get Net_SMTP instance
  *
  * Returned instance must be authenticated and connected.
  *
  * @param string $provider
  *   Any provider defined in the 'netsmtp' variable
  *
  * @return Net_SMTP
  *   Or null if instance could not be created or could not connect
  *   to SMTP server
  */
 protected function getInstance($provider = self::PROVIDER_DEFAULT)
 {
     $isTLS = false;
     $config = variable_get('netsmtp');
     if (empty($config[$provider])) {
         $this->setError(sprintf("Provider '%s' does not exists, fallback on default", $provider), WATCHDOG_WARNING);
         if (empty($config[$provider])) {
             $this->setError(sprintf("Default provider is not set", $provider));
             return null;
         }
     }
     if (empty($config[$provider]['hostname'])) {
         $this->setError(sprintf("Provider '%s' has no hostname", $provider));
         return null;
     }
     $info = array_filter($config[$provider]) + array('port' => null, 'username' => null, 'use_ssl' => false, 'password' => '', 'localhost' => null);
     if ($info['use_ssl']) {
         if ('tls' === $info['use_ssl']) {
             $info['hostname'] = 'tls://' . $info['hostname'];
             $isTLS = true;
         } else {
             $info['hostname'] = 'ssl://' . $info['hostname'];
         }
         if (empty($info['port'])) {
             $info['port'] = self::DEFAULT_SSL_PORT;
         }
     }
     // Attempt connection
     $smtp = new Net_SMTP($info['hostname'], $info['port'], $info['localhost']);
     if ($this->PEAR->isError($e = $smtp->connect())) {
         $this->setError($e);
         return null;
     }
     if (!empty($info['username'])) {
         if ($this->PEAR->isError($e = $smtp->auth($info['username'], $info['password'], '', $isTLS))) {
             $this->setError($e);
             return null;
         }
     }
     // Finally! We did it I guess.
     return $smtp;
 }
Exemplo n.º 21
0
 | See http://www.imobmail.org/ for more details or visit our bugtracker |
 | at http://trac.imobmail.org/                                          |
 |                                                                       |    
 | Use of iMobMail at your own risk!                                     |
 |                                                                       |
 +-----------------------------------------------------------------------+
*/
require_once "Net/SMTP.php";
include 'config.php';
$from = $SMTP_SENDERADDRESS;
$fromname = $SMTP_SENDERNAME;
$to = $_POST["to"];
$cc = $_POST["cc"];
$subject = $_POST["subj"];
$body = $_POST["textbody"];
$smtp_host_conn = new Net_SMTP($SMTP_SERVER);
$result = $smtp_host_conn->connect($smtp_timeout);
if (PEAR::isError($result)) {
    $smtp_host_conn = null;
    $smtp_host_conn->rset();
    $smtp_host_conn->disconnect();
    die("Connection failed: " . $result->getMessage());
}
$result = $smtp_host_conn->auth($SMTP_USER, $SMTP_PASSWORD, $smtp_auth_type);
if (PEAR::isError($result)) {
    $smtp_host_conn->rset();
    $smtp_host_conn->disconnect();
    die("Authentication failure: " . $result->getMessage());
}
if (PEAR::isError($smtp_host_conn->mailFrom($from))) {
    die("Unable to set sender to <{$from}>\n");
Exemplo n.º 22
0
 /**
  * Send the DATA command.
  *
  * @param mixed $data      The message data, either as a string or an open
  *                         file resource.
  * @param string $headers  The message headers. If $headers is provided,
  *                         $data is assumed to contain only body data.
  *
  * @throws PEAR_Exception
  */
 public function data($data, $headers = null)
 {
     /* Verify that $data is a supported type. */
     if (!is_string($data) && !is_resource($data)) {
         return Net_SMTP::raiseError('Expected a string or file resource');
     }
     /* Start by considering the size of the optional headers string.  We
      * also account for the addition 4 character "\r\n\r\n" separator
      * sequence. */
     $size = is_null($headers) ? 0 : strlen($headers) + 4;
     if (is_resource($data)) {
         $stat = fstat($data);
         if ($stat === false) {
             return Net_SMTP::raiseError('Failed to get file size');
         }
         $size += $stat['size'];
     } else {
         $size += strlen($data);
     }
     /* RFC 1870, section 3, subsection 3 states "a value of zero indicates
      * that no fixed maximum message size is in force".  Furthermore, it
      * says that if "the parameter is omitted no information is conveyed
      * about the server's fixed maximum message size". */
     $limit = isset($this->_esmtp['SIZE']) ? $this->_esmtp['SIZE'] : 0;
     if ($limit > 0 && $size >= $limit) {
         $this->disconnect();
         return Net_SMTP::raiseError('Message size exceeds server limit');
     }
     /* Initiate the DATA command. */
     //if (PEAR::isError($error = $this->_put('DATA'))) {
     if (($error = $this->_put('DATA')) === false) {
         return $error;
     }
     //if (PEAR::isError($error = $this->_parseResponse(354))) {
     if (($error = $this->_parseResponse(354)) === false) {
         return $error;
     }
     /* If we have a separate headers string, send it first. */
     if (!is_null($headers)) {
         $this->quotedata($headers);
         //if (PEAR::isError($result = $this->_send($headers . "\r\n\r\n"))) {
         if (($result = $this->_send($headers . "\r\n\r\n")) === false) {
             return $result;
         }
     }
     /* Now we can send the message body data. */
     if (is_resource($data)) {
         /* Stream the contents of the file resource out over our socket
          * connection, line by line.  Each line must be run through the
          * quoting routine. */
         while (strlen($line = fread($data, 8192)) > 0) {
             /* If the last character is an newline, we need to grab the
              * next character to check to see if it is a period. */
             while (!feof($data)) {
                 $char = fread($data, 1);
                 $line .= $char;
                 if ($char != "\n") {
                     break;
                 }
             }
             $this->quotedata($line);
             //if (PEAR::isError($result = $this->_send($line))) {
             if (($result = $this->_send($line)) === false) {
                 return $result;
             }
         }
     } else {
         /* Break up the data by sending one chunk (up to 512k) at a time.
          * This approach reduces our peak memory usage. */
         for ($offset = 0; $offset < $size;) {
             $end = $offset + 512000;
             /* Ensure we don't read beyond our data size or span multiple
              * lines.  quotedata() can't properly handle character data
              * that's split across two line break boundaries. */
             if ($end >= $size) {
                 $end = $size;
             } else {
                 for (; $end < $size; $end++) {
                     if ($data[$end] != "\n") {
                         break;
                     }
                 }
             }
             /* Extract our chunk and run it through the quoting routine. */
             $chunk = substr($data, $offset, $end - $offset);
             $this->quotedata($chunk);
             /* If we run into a problem along the way, abort. */
             //if (PEAR::isError($result = $this->_send($chunk))) {
             if (($result = $this->_send($chunk)) === false) {
                 return $result;
             }
             /* Advance the offset to the end of this chunk. */
             $offset = $end;
         }
     }
     /* Finally, send the DATA terminator sequence. */
     //if (PEAR::isError($result = $this->_send("\r\n.\r\n"))) {
     if (($result = $this->_send("\r\n.\r\n")) === false) {
         return $result;
     }
     /* Verify that the data was successfully received by the server. */
     //if (PEAR::isError($error = $this->_parseResponse(250, $this->pipelining))) {
     if (($error = $this->_parseResponse(250, $this->pipelining)) === false) {
         return $error;
     }
     return true;
 }
Exemplo n.º 23
0
 /**
  * Implements Mail::send() function using SMTP.
  *
  * @param mixed $recipients Either a comma-seperated list of recipients
  *              (RFC822 compliant), or an array of recipients,
  *              each RFC822 valid. This may contain recipients not
  *              specified in the headers, for Bcc:, resending
  *              messages, etc.
  *
  * @param array $headers The array of headers to send with the mail, in an
  *              associative array, where the array key is the
  *              header name (e.g., 'Subject'), and the array value
  *              is the header value (e.g., 'test'). The header
  *              produced from those values would be 'Subject:
  *              test'.
  *
  * @param string $body The full text of the message body, including any
  *               Mime parts, etc.
  *
  * @return mixed Returns true on success, or a PEAR_Error
  *               containing a descriptive error message on
  *               failure.
  * @access public
  */
 function send($recipients, $headers, $body)
 {
     include_once 'Net/SMTP.php';
     if (!($smtp = new Net_SMTP($this->host, $this->port, $this->localhost))) {
         return new PEAR_Error('unable to instantiate Net_SMTP object');
     }
     if (PEAR::isError($smtp->connect())) {
         return new PEAR_Error('unable to connect to smtp server ' . $this->host . ':' . $this->port);
     }
     if ($this->auth) {
         $method = is_string($this->auth) ? $this->auth : '';
         if (PEAR::isError($smtp->auth($this->username, $this->password, $method))) {
             return new PEAR_Error('unable to authenticate to smtp server');
         }
     }
     list($from, $text_headers) = $this->prepareHeaders($headers);
     /*
      * Since few MTAs are going to allow this header to be forged unless
      * it's in the MAIL FROM: exchange, we'll use Return-Path instead of
      * From: if it's set.
      */
     if (!empty($headers['Return-Path'])) {
         $from = $headers['Return-Path'];
     }
     if (!isset($from)) {
         return new PEAR_Error('No from address given');
     }
     if (PEAR::isError($smtp->mailFrom($from))) {
         return new PEAR_Error('unable to set sender to [' . $from . ']');
     }
     $recipients = $this->parseRecipients($recipients);
     foreach ($recipients as $recipient) {
         if (PEAR::isError($res = $smtp->rcptTo($recipient))) {
             return new PEAR_Error('unable to add recipient [' . $recipient . ']: ' . $res->getMessage());
         }
     }
     if (PEAR::isError($smtp->data($text_headers . "\r\n" . $body))) {
         return new PEAR_Error('unable to send data');
     }
     $smtp->disconnect();
     return true;
 }
Exemplo n.º 24
0
 /**
  */
 public function send($recipients, array $headers, $body)
 {
     $headers = $this->_sanitizeHeaders($headers);
     // Prepare headers
     list($from, $textHeaders) = $this->prepareHeaders($headers);
     try {
         $from = $this->_getFrom($from, $headers);
     } catch (Horde_Mail_Exception $e) {
         $this->_error('no_from');
     }
     // Prepare recipients
     foreach ($this->parseRecipients($recipients) as $rcpt) {
         list(, $host) = explode('@', $rcpt);
         $mx = $this->_getMx($host);
         if (!$mx) {
             $this->_error('no_mx', array('rcpt' => $rcpt));
         }
         $connected = false;
         foreach (array_keys($mx) as $mserver) {
             $this->_smtp = new Net_SMTP($mserver, $this->_params['port'], $this->_params['mailname']);
             // configure the SMTP connection.
             if ($this->_params['debug']) {
                 $this->_smtp->setDebug(true);
             }
             // attempt to connect to the configured SMTP server.
             $res = $this->_smtp->connect($this->_params['timeout']);
             if ($res instanceof PEAR_Error) {
                 $this->_smtp = null;
                 continue;
             }
             // connection established
             if ($res) {
                 $connected = true;
                 break;
             }
         }
         if (!$connected) {
             $this->_error('not_connected', array('host' => implode(', ', array_keys($mx)), 'port' => $this->_params['port'], 'rcpt' => $rcpt));
         }
         // Verify recipient
         if ($this->_params['vrfy']) {
             $res = $this->_smtp->vrfy($rcpt);
             if ($res instanceof PEAR_Error) {
                 $this->_error('failed_vrfy_rcpt', array('rcpt' => $rcpt));
             }
         }
         // mail from:
         $args['verp'] = $this->_params['verp'];
         $res = $this->_smtp->mailFrom($from, $args);
         if ($res instanceof PEAR_Error) {
             $this->_error('failed_set_from', array('from' => $from));
         }
         // rcpt to:
         $res = $this->_smtp->rcptTo($rcpt);
         if ($res instanceof PEAR_Error) {
             $this->_error('failed_set_rcpt', array('rcpt' => $rcpt));
         }
         // Don't send anything in test mode
         if ($this->_params['test']) {
             $res = $this->_smtp->rset();
             if ($res instanceof PEAR_Error) {
                 $this->_error('failed_rset');
             }
             $this->_smtp->disconnect();
             $this->_smtp = null;
             return;
         }
         // Send data. Net_SMTP does necessary EOL conversions.
         $res = $this->_smtp->data($body, $textHeaders);
         if ($res instanceof PEAR_Error) {
             $this->_error('failed_send_data', array('rcpt' => $rcpt));
         }
         $this->_smtp->disconnect();
         $this->_smtp = null;
     }
 }
Exemplo n.º 25
0
 static function validate_login_smtp($username, $password)
 {
     $hostname = explode(":", SETUP_AUTH_HOSTNAME_SMTP);
     if (!isset($hostname[1])) {
         $hostname[1] = 25;
     }
     if (isset($hostname[2]) and !extension_loaded("openssl")) {
         sys_log_message_alert("login", sprintf("{t}%s is not compiled / loaded into PHP.{/t}", "SMTP / OpenSSL"));
         return false;
     }
     $smtp = new Net_SMTP((isset($hostname[2]) ? $hostname[2] . "://" : "") . $hostname[0], $hostname[1]);
     if (PEAR::isError($e = $smtp->connect(10)) or PEAR::isError($e = $smtp->auth($username, $password))) {
         sys_log_message_alert("login", sprintf("{t}Login failed from %s.{/t} (smtp) ({t}Username{/t}: %s, %s)", _login_get_remoteaddr(), $username, $e->getMessage()));
         return false;
     } else {
         return true;
     }
 }