Esempio n. 1
0
 /**
  * send reminders
  * @param SugarBean $bean
  * @param Administration $admin
  * @param array $recipients
  * @return boolean
  */
 protected function sendReminders(SugarBean $bean, Administration $admin, $recipients)
 {
     global $sugar_config;
     $user = new User();
     $user->retrieve($bean->created_by);
     $OBCharset = $GLOBALS['locale']->getPrecedentPreference('default_email_charset');
     ///////////////////EMAIL///////////////////////////
     require_once "include/SugarPHPMailer.php";
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     if (empty($admin->settings['notify_send_from_assigning_user'])) {
         $from_address = $admin->settings['notify_fromaddress'];
         $from_name = $admin->settings['notify_fromname'] ? "" : $admin->settings['notify_fromname'];
     } else {
         $from_address = $user->emailAddress->getReplyToAddress($user);
         $from_name = $user->full_name;
     }
     $mail->From = $from_address;
     $mail->FromName = $from_name;
     $mail->Body = "Напоминание о сделке '{$bean->name}' - {$sugar_config['site_url']}/index.php?action=DetailView&module=Opportunities&record={$bean->id}";
     $mail->Subject = "SugarCRM::Напоминание о сделке";
     $oe = new OutboundEmail();
     $oe = $oe->getSystemMailerSettings();
     if (empty($oe->mail_smtpserver)) {
         $GLOBALS['log']->fatal("Email Reminder: error sending email, system smtp server is not set");
         return;
     }
     foreach ($recipients as $r) {
         $mail->ClearAddresses();
         $mail->AddAddress($r['email'], $GLOBALS['locale']->translateCharsetMIME(trim($r['name']), 'UTF-8', $OBCharset));
         $mail->prepForOutbound();
         if (!$mail->Send()) {
             $GLOBALS['log']->fatal("Email Reminder: error sending e-mail (method: {$mail->Mailer}), (error: {$mail->ErrorInfo})");
         }
     }
     ///////////////////SMS///////////////////////////
     require_once 'custom/sms/sms.php';
     $sms = new sms();
     $sms->parent_type = 'Users';
     foreach ($recipients as $r) {
         $sms->parent_id = $r['id'];
         $sms->pname = $r['name'];
         $type = "Напоминание о сделке ";
         $text = $type . $bean->name;
         /*if($sms->send_message($r['number'], $text) == "SENT")
         		return true;
                   else
         		return false;*/
     }
     ///////////////////ALERT/////////////////////////// !TODO
     /*$timeStart = strtotime($db->fromConvert($bean->date_start, 'datetime'));
     		$this->addAlert($app_strings['MSG_JS_ALERT_MTG_REMINDER_CALL'], $bean->name, $app_strings['MSG_JS_ALERT_MTG_REMINDER_TIME'].$timedate->to_display_date_time($db->fromConvert($bean->date_remind, 'datetime')) , $app_strings['MSG_JS_ALERT_MTG_REMINDER_DESC'].$bean->description. $app_strings['MSG_JS_ALERT_MTG_REMINDER_CALL_MSG'] , $timeStart - strtotime($this->now), 'index.php?action=DetailView&module=Opportunities&record=' . $bean->id);
     		*/
     return true;
 }
 public function notify_on_delete($bean, $event, $arguments)
 {
     //Send an email to the department manager
     require_once "include/SugarPHPMailer.php";
     $email_obj = new Email();
     $defaults = $email_obj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $defaults["email"];
     $mail->FromName = $defaults["name"];
     $mail->Subject = "Account record deleted";
     $mail->Body = "The account record with ID: " . $bean->id . ", Name: " . $bean->name . ", Address: " . $bean->billing_address_street . ", " . $bean->billing_address_city . ", " . $bean->billing_address_state . ", " . $bean->billing_address_postalcode . ", " . $bean->billing_address_country . " is being deleted.";
     $mail->prepForOutbound();
     $mail->AddAddress("*****@*****.**");
     @$mail->Send();
 }
Esempio n. 3
0
function sendSugarPHPMail($tos, $subject, $body)
{
    require_once 'include/SugarPHPMailer.php';
    require_once 'modules/Administration/Administration.php';
    global $current_user;
    $mail = new SugarPHPMailer();
    $admin = new Administration();
    $admin->retrieveSettings();
    if ($admin->settings['mail_sendtype'] == "SMTP") {
        $mail->Host = $admin->settings['mail_smtpserver'];
        $mail->Port = $admin->settings['mail_smtpport'];
        if ($admin->settings['mail_smtpauth_req']) {
            $mail->SMTPAuth = TRUE;
            $mail->Username = $admin->settings['mail_smtpuser'];
            $mail->Password = $admin->settings['mail_smtppass'];
        }
        $mail->Mailer = "smtp";
        $mail->SMTPKeepAlive = true;
    } else {
        $mail->mailer = 'sendmail';
    }
    $mail->IsSMTP();
    // send via SMTP
    if ($admin->settings['mail_smtpssl'] == '2') {
        $mail->SMTPSecure = "tls";
    } elseif ($admin->settings['mail_smtpssl'] == '1') {
        $mail->SMTPSecure = "ssl";
    }
    $mail->CharSet = 'UTF-8';
    $mail->From = $admin->settings['notify_fromaddress'];
    $mail->FromName = $admin->settings['notify_fromname'];
    $mail->ContentType = "text/html";
    //"text/plain"
    $mail->IsHTML(true);
    $mail->Subject = $subject;
    $mail->Body = $body;
    foreach ($tos as $name => $address) {
        $mail->AddAddress("{$address}", "{$name}");
    }
    if (!$mail->send()) {
        $GLOBALS['log']->info("sendSugarPHPMail - Mailer error: " . $mail->ErrorInfo);
        return false;
    } else {
        return true;
    }
}
 function SendEmail($emailsTo, $emailSubject, $emailBody)
 {
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = from_html($emailBody);
     $mail->prepForOutbound();
     foreach ($emailsTo as &$value) {
         $mail->AddAddress($value);
     }
     if (@$mail->Send()) {
     }
 }
Esempio n. 5
0
 function sendEmail($emailTo, $emailSubject, $emailBody, $altemailBody, SugarBean $relatedBean = null)
 {
     require_once 'modules/Emails/Email.php';
     require_once 'include/SugarPHPMailer.php';
     $emailObj = new Email();
     $emailSettings = getPortalEmailSettings();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $emailSettings['from_address'];
     $mail->FromName = $emailSettings['from_name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = $altemailBody;
     $mail->prepForOutbound();
     $mail->AddAddress($emailTo);
     //now create email
     if (@$mail->Send()) {
         $emailObj->to_addrs = '';
         $emailObj->type = 'archived';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->AltBody;
         $emailObj->description_html = $mail->Body;
         $emailObj->from_addr = $mail->From;
         if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) {
             $emailObj->parent_type = $relatedBean->module_dir;
             $emailObj->parent_id = $relatedBean->id;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
     }
 }
Esempio n. 6
0
 public static function enviarEmail($asunto, $mensaje, $direcciones, $from)
 {
     require_once "include/SugarPHPMailer.php";
     $mailer = new SugarPHPMailer();
     $mailer->Subject = $asunto;
     $mailer->From = $from['from'];
     $mailer->FromName = $from['from_name'];
     foreach ($direcciones as $email) {
         $mailer->AddAddress($email);
     }
     $mailer->Body = $mensaje;
     $mailer->prepForOutbound();
     $mailer->setMailerForSystem();
     $mailer->IsHTML(true);
     if ($mailer->Send()) {
         return true;
     } else {
         $GLOBALS['log']->info("No se ha podido enviar el correo electronico:  " . $mailer->ErrorInfo);
         return false;
     }
 }
Esempio n. 7
0
        $idx++;
        $emailbody[$idx]['email'] = "*****@*****.**";
        $emailbody[$idx]['subject'] = "CS All Unassigned Case Report";
        $emailbody[$idx]['body'] .= "The following cases are unassigned :<br /><br />";
        $emailbody[$idx]['body'] .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . "</a><br />";
        $prevemail = "*****@*****.**";
    } else {
        $emailbody[$idx]['body'] .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . "</a><br />";
        $prevemail = "*****@*****.**";
    }
}
/* Send out emails */
$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
foreach ($emailbody as $data) {
    $mail->ClearAllRecipients();
    $mail->ClearReplyTos();
    $mail->Subject = $data['subject'];
    $mail->IsHTML(true);
    $mail->Body = $data['body'];
    $mail->AltBody = $data['body'];
    $mail->prepForOutbound();
    $mail->AddAddress($data['email']);
    $mail->Send();
}
/* Clean up shop */
$mail->SMTPClose();
Esempio n. 8
0
    echo $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT'];
    $new_pwd = '4';
    return;
}
if ($mail->Mailer == 'smtp' && $mail->Host == '' && $current_user->is_admin) {
    echo $mod_strings['ERR_SERVER_SMTP_EMPTY'];
    $new_pwd = '4';
    return;
}
$mail->prepForOutbound();
$hasRecipients = false;
if (!empty($itemail)) {
    if ($hasRecipients) {
        $mail->AddBCC($itemail);
    } else {
        $mail->AddAddress($itemail);
    }
    $hasRecipients = true;
}
$success = false;
if ($hasRecipients) {
    $success = @$mail->Send();
}
//now create email
if ($success) {
    $emailObj->team_id = 1;
    $emailObj->to_addrs = '';
    $emailObj->type = 'archived';
    $emailObj->deleted = '0';
    $emailObj->name = $mail->Subject;
    $emailObj->description = $mail->Body;
 /**
  * Sends the users password to the email address or sends
  *
  * @param unknown_type $user_id
  * @param unknown_type $password
  */
 function sendEmailPassword($user_id, $password)
 {
     $result = $GLOBALS['db']->query("SELECT email1, email2, first_name, last_name FROM users WHERE id='{$user_id}'");
     $row = $GLOBALS['db']->fetchByAssoc($result);
     global $sugar_config;
     if (empty($row['email1']) && empty($row['email2'])) {
         $_SESSION['login_error'] = 'Please contact an administrator to setup up your email address associated to this account';
         return;
     }
     global $locale;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     $notify_mail = new SugarPHPMailer();
     $notify_mail->CharSet = $sugar_config['default_charset'];
     $notify_mail->AddAddress(!empty($row['email1']) ? $row['email1'] : $row['email2'], $locale->translateCharsetMIME(trim($row['first_name'] . ' ' . $row['last_name']), 'UTF-8', $OBCharset));
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $sugar_config['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     $notify_mail->Subject = 'Sugar Token';
     $notify_mail->Body = 'Your sugar session authentication token  is: ' . $password;
     $notify_mail->setMailerForSystem();
     $notify_mail->From = '*****@*****.**';
     $notify_mail->FromName = 'Sugar Authentication';
     if (!$notify_mail->Send()) {
         Log::warn("Notifications: error sending e-mail (method: {$notify_mail->Mailer}), (error: {$notify_mail->ErrorInfo})");
     } else {
         Log::info("Notifications: e-mail successfully sent");
     }
 }
Esempio n. 10
0
 function generate_email()
 {
     global $mod_strings;
     global $current_user;
     global $sugar_config;
     global $locale;
     require_once 'include/utils.php';
     $query = 'SELECT name';
     $query .= ' FROM emails';
     $query .= " WHERE deleted=0";
     $query .= " AND name='{$this->pnum}-Estimate'";
     $result = $this->db->query($query, true, " Error filling in additional detail fields: ");
     $n = $this->db->getRowCount($result);
     if ($n == 0) {
         $queryname = 'SELECT user_name';
         $queryname .= ' FROM users';
         $queryname .= " WHERE deleted=0";
         $queryname .= " AND id='{$this->assigned_user_id}'";
         $result_name = $this->db->query($queryname, true, " Error filling in additional detail fields: ");
         $username = $this->db->fetchByAssoc($result_name);
         $to_addrs_names = $username['user_name'];
         $queryemail = 'SELECT email1';
         $queryemail .= ' FROM users';
         $queryemail .= " WHERE deleted=0";
         $queryemail .= " AND id='{$this->assigned_user_id}'";
         $result_email = $this->db->query($queryemail, true, " Error filling in additional detail fields: ");
         $useremail = $this->db->fetchByAssoc($result_email);
         $to_addrs_emails = $useremail['email1'];
         $id = create_guid();
         $from_addr = $current_user->name;
         $from_name = $current_user->email1;
         $name = $this->pnum . '-Estimate';
         $description = $this->pnum . ' is waiting for estimate';
         $query2 = "INSERT into emails (id,  assigned_user_id, created_by, name, status,  to_addrs_names, to_addrs_emails, from_addr, from_name, description, deleted, type, intent) ";
         $query2 .= " VALUES ('{$id}', '{$this->assigned_user_id}', '{$current_user->id}', '{$name}', 'sent', '{$to_addrs_names}', '{$to_addrs_emails}', '{$from_addr}', '{$from_name}', '{$description}', '0', 'out', 'pick') ";
         $this->db->query($query2, true, " Error filling in additional detail fields: ");
         $mail = new SugarPHPMailer();
         $mail->AddAddress($to_addrs_emails, $to_addrs_names);
         $mail->Mailer = "sendmail";
         // FROM ADDRESS
         $mail->From = $from_addr;
         // FROM NAME
         $mail->FromName = $from_name;
         $mail->Sender = $mail->From;
         /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
         $mail->AddReplyTo($mail->From, $mail->FromName);
         $encoding = version_compare(phpversion(), '5.0', '>=') ? 'UTF-8' : 'ISO-8859-1';
         $mail->Subject = html_entity_decode($name, ENT_QUOTES, $encoding);
         ///////////////////////////////////////////////////////////////////////
         ////	HANDLE EMAIL FORMAT PREFERENCE
         // the if() below is HIGHLY dependent on the Javascript unchecking the Send HTML Email box
         // HTML email
         // plain text only
         $description_html = '';
         $mail->IsHTML(false);
         $mail->Body = wordwrap(from_html($description, 996));
         // wp: if plain text version has lines greater than 998, use base64 encoding
         foreach (explode("\n", $mail->ContentType == "text/html" ? $mail->AltBody : $mail->Body) as $line) {
             if (strlen($line) > 998) {
                 $mail->Encoding = 'base64';
                 break;
             }
         }
         ////	HANDLE EMAIL FORMAT PREFERENCE
         ///////////////////////////////////////////////////////////////////////
         ///////////////////////////////////////////////////////////////////////
         ////    SAVE RAW MESSAGE
         $mail->SetMessageType();
         $raw = $mail->CreateHeader();
         $raw .= $mail->CreateBody();
         $raw_source = urlencode($raw);
         ////    END SAVE RAW MESSAGE
         ///////////////////////////////////////////////////////////////////////
         $GLOBALS['log']->debug('Email sending --------------------- ');
         ///////////////////////////////////////////////////////////////////////
         ////	I18N TRANSLATION
         $mail->prepForOutbound();
         ////	END I18N TRANSLATION
         ///////////////////////////////////////////////////////////////////////
         $mail->Send();
     }
 }
Esempio n. 11
0
 public function sendEmail($emailTo, $emailSubject, $emailToname, $emailBody, $altemailBody, SugarBean $relatedBean = null, $attachments = array())
 {
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = $altemailBody;
     $mail->handleAttachments($attachments);
     $mail->prepForOutbound();
     $mail->AddAddress($emailTo);
     //now create email
     if (@$mail->Send()) {
         $emailObj->to_addrs = '';
         $emailObj->type = 'out';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->AltBody;
         $emailObj->description_html = $mail->Body;
         $emailObj->from_addr = $mail->From;
         if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) {
             $emailObj->parent_type = $relatedBean->module_dir;
             $emailObj->parent_id = $relatedBean->id;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
         return true;
     } else {
         return false;
     }
 }
Esempio n. 12
0
<?php

/* Test email script */
if (!defined('sugarEntry')) {
    define('sugarEntry', true);
}
require_once 'include/entryPoint.php';
require_once 'include/SugarPHPMailer.php';
require_once 'modules/Emails/Email.php';
$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->Subject = "Test Email Script";
$mail->IsHTML(true);
$mail->Body = "<i>Body Text</i>";
$mail->AltBody = "Body Text";
$mail->prepForOutbound();
$mail->AddAddress("*****@*****.**");
$mail->Send();
$mail->SMTPClose();
Esempio n. 13
0
/* Query database to get case aging */
$query = 'select c.case_number,c.name,concat("http://dcmaster.mydatacom.com/index.php?module=Cases&action=DetailView&record=",c.id) as link from cases as c where c.id not in (select distinct case_id from projects_cases) and c.account_id is null and c.status="New" and c.deleted=0;';
$db = DBManagerFactory::getInstance();
$result = $db->query($query, true, 'Case Unassigned Query Failed');
/* Create email bodies to send */
$linecount = 0;
$emailbody = "The following cases are currently unassigned:<br /><br />";
while (($row = $db->fetchByAssoc($result)) != null) {
    $emailbody .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . " </a><br />";
    $linecount++;
}
if ($linecount > 0) {
    /* Send out emails */
    $emailObj = new Email();
    $defaults = $emailObj->getSystemDefaultEmail();
    $mail = new SugarPHPMailer();
    $mail->setMailerForSystem();
    $mail->From = $defaults['email'];
    $mail->FromName = $defaults['name'];
    $mail->ClearAllRecipients();
    $mail->ClearReplyTos();
    $mail->Subject = "Unassigned Case Report";
    $mail->IsHTML(true);
    $mail->Body = $emailbody;
    $mail->AltBody = $emailbody;
    $mail->prepForOutbound();
    $mail->AddAddress('*****@*****.**');
    $mail->Send();
    /* Clean up shop */
    $mail->SMTPClose();
}
 /**
  * This function handles sending out email notifications when items are first assigned to users.
  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  * All Rights Reserved.
  * Contributor(s): ______________________________________..
  */
 function create_notification_email($notify_user)
 {
     global $sugar_version;
     global $sugar_config;
     global $app_list_strings;
     global $current_user;
     global $locale;
     require_once "XTemplate/xtpl.php";
     require_once "include/SugarPHPMailer.php";
     $notify_address = empty($notify_user->email1) ? from_html($notify_user->email2) : from_html($notify_user->email1);
     $notify_name = empty($notify_user->first_name) ? from_html($notify_user->user_name) : from_html($notify_user->first_name . " " . $notify_user->last_name);
     $GLOBALS['log']->debug("Notifications: user has e-mail defined");
     $notify_mail = new SugarPHPMailer();
     $notify_mail->AddAddress($notify_address, $notify_name);
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $sugar_config['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     $xtpl = new XTemplate("include/language/{$current_language}.notify_template.html");
     $template_name = $this->object_name;
     $this->current_notify_user = $notify_user;
     if (in_array('set_notification_body', get_class_methods($this))) {
         $xtpl = $this->set_notification_body($xtpl, $this);
     } else {
         $xtpl->assign("OBJECT", $this->object_name);
         $template_name = "Default";
     }
     $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
     $xtpl->assign("ASSIGNER", $current_user->name);
     $port = '';
     if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
         $port = $_SERVER['SERVER_PORT'];
     }
     $httpHost = $_SERVER['HTTP_HOST'];
     if ($colon = strpos($httpHost, ':')) {
         $httpHost = substr($httpHost, 0, $colon);
     }
     $parsedSiteUrl = parse_url($sugar_config['site_url']);
     $host = $parsedSiteUrl['host'] != $httpHost ? $httpHost : $parsedSiteUrl['host'];
     if (!isset($parsedSiteUrl['port'])) {
         $parsedSiteUrl['port'] = 80;
     }
     $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : '';
     $path = $parsedSiteUrl['path'];
     $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
     $xtpl->assign("URL", $cleanUrl . "/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
     $xtpl->assign("SUGAR", "Sugar Suite v{$sugar_version}");
     $xtpl->parse($template_name);
     $xtpl->parse($template_name . "_Subject");
     $notify_mail->Body = from_html(trim($xtpl->text($template_name)));
     $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
     // cn: bug 8568 encode notify email in User's outbound email encoding
     $notify_mail->prepForOutbound();
     return $notify_mail;
 }
 function _Send_Email($fromAddress, $fromName, $toAddresses, $subject, $module, $bean_id, $body, $attachedFiles = array(), $saveCopy = true)
 {
     global $current_user, $sugar_config;
     if ($sugar_config['dbconfig']['db_host_name'] != '10.2.1.20' && $sugar_config['dbconfig']['db_host_name'] != '127.0.0.1') {
         $send_ok = false;
     } else {
         $send_ok = true;
     }
     //Replace general variables for all email templates.
     $keys = array('$contact_name', '$contact_first_name', '$sales_full_name', '$sales_first_name');
     $vars_count = $this->substr_count_array($body, $keys);
     if (($module == 'Contacts' || $module == 'Leads') && $vars_count > 0) {
         $clientObj = BeanFactory::getBean($module, $bean_id);
         $sale_person = $this->_getSalesPerson($clientObj);
         $data = array($clientObj->first_name . ' ' . $clientObj->last_name, $clientObj->first_name, $sale_person['sales_full_name'], $sale_person['sales_first_name']);
         $body = str_replace($keys, $data, $body);
     }
     //if(!$send_ok) $GLOBALS['log']->error('Mail Service: not a Live Server, trashmail accounts service only. ');
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $fromAddress;
     $mail->FromName = $fromName;
     $mail->Subject = $subject;
     $mail->Body = $body;
     $mail->ContentType = "text/html";
     $mail->prepForOutbound();
     $test_addr = false;
     foreach ($toAddresses as $name => $email) {
         $mail->AddAddress($email, $name);
         if (substr_count($email, '@trashmail') > 0 || $email == '*****@*****.**') {
             $test_addr = true;
         }
     }
     if ($send_ok || $test_addr) {
         if (!empty($attachedFiles)) {
             foreach ($attachedFiles as $files) {
                 $mail->AddAttachment($files['file_location'] . $files['filename'], $files['filename'], 'base64');
             }
         }
         if (@$mail->Send()) {
             if ($saveCopy) {
                 $emailObj->from_addr = $fromAddress;
                 $emailObj->reply_to_addr = implode(',', $toAddresses);
                 $emailObj->to_addrs = implode(',', $toAddresses);
                 $emailObj->name = $subject;
                 $emailObj->type = 'out';
                 $emailObj->status = 'sent';
                 $emailObj->intent = 'pick';
                 $emailObj->parent_type = $module;
                 $emailObj->parent_id = $bean_id;
                 $emailObj->description_html = $body;
                 $emailObj->description = $body;
                 $emailObj->assigned_user_id = $current_user->id;
                 $emailObj->save();
                 if (!empty($attachedFiles)) {
                     foreach ($attachedFiles as $files) {
                         $Notes = BeanFactory::getBean('Notes');
                         $Notes->name = $files['filename'];
                         $Notes->file_mime_type = 'pdf';
                         $Notes->filename = $files['filename'];
                         $Notes->parent_type = 'Emails';
                         $Notes->parent_id = $emailObj->id;
                         $Notes->save();
                         $pdf = file_get_contents($files['file_location'] . $files['filename']);
                         file_put_contents('upload/' . $Notes->id, $pdf);
                     }
                 }
             }
             return true;
         } else {
             $GLOBALS['log']->info("Mailer error: " . $mail->ErrorInfo);
             return false;
         }
     } else {
         $GLOBALS['log']->error('Mail Service: not a Live Server(' . $sugar_config['dbconfig']['db_host_name'] . '), trashmail accounts service only. Cannot send mail to ' . print_r($toAddresses, true));
         $emailObj->from_addr = $fromAddress;
         $emailObj->reply_to_addr = implode(',', $toAddresses);
         $emailObj->to_addrs = implode(',', $toAddresses);
         $emailObj->name = 'TEST MODE, NOT SENT: ' . $subject;
         $emailObj->type = 'out';
         $emailObj->status = 'NOT sent';
         $emailObj->intent = 'pick';
         $emailObj->parent_type = $module;
         $emailObj->parent_id = $bean_id;
         $emailObj->description_html = $body;
         $emailObj->description = $body;
         $emailObj->assigned_user_id = $current_user->id;
         $emailObj->save();
         return false;
     }
 }
Esempio n. 16
0
     } else {
         $note->parent_type = $_REQUEST['parent_module'];
         $note->parent_id = $_REQUEST['parent_id'];
     }
     $note->save();
     $uf = new UploadFile("upload");
     $uf->set_for_soap($focus->report_result_name, file_get_contents($focus->report_result));
     $uf->stored_file_name = $uf->create_stored_filename();
     $uf->final_move($note->id);
     $note_url = "index.php?action=DetailView&module=Notes&record=" . $note->id . "&return_module=ZuckerReports&return_action=ReportOnDemand";
 }
 if (!empty($_REQUEST['send_email'])) {
     $mail = new SugarPHPMailer();
     $emails = split(",", $_REQUEST['send_email']);
     foreach ($emails as $email) {
         $mail->AddAddress($email);
     }
     $admin = new Administration();
     $admin->retrieveSettings();
     if ($admin->settings['mail_sendtype'] == "SMTP") {
         $mail->Mailer = "smtp";
         $mail->Host = $admin->settings['mail_smtpserver'];
         $mail->Port = $admin->settings['mail_smtpport'];
         if ($admin->settings['mail_smtpauth_req']) {
             $mail->SMTPAuth = TRUE;
             $mail->Username = $admin->settings['mail_smtpuser'];
             $mail->Password = $admin->settings['mail_smtppass'];
         }
     } else {
         $mail->Mailer = 'sendmail';
     }
Esempio n. 17
0
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
//$mail->From = $defaults['email'];
$mail->IsSMTP();
// telling the class to use SMTP
$mail->Host = "mail.vinksoftware.com";
// SMTP server
$mail->SMTPDebug = 2;
// enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true;
// enable SMTP authentication
//$mail->SMTPSecure = 'tls';
$mail->Port = 26;
// set the SMTP port for the GMAIL server
$mail->Username = "******";
// SMTP account username
$mail->Password = "******";
// SMTP account password
$mail->SetFrom('*****@*****.**', 'Vinay Hooloomann');
//$mail->AddReplyTo('*****@*****.**', 'Vinay Hooloomann');
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$address = "*****@*****.**";
$mail->AddAddress($address, "Vinay Hooloomann");
$mail->Body = 'Test';
//$mail->prepForOutbound();
//$mail->AddAddress($email);
$mail->Send();
echo "sent";
Esempio n. 18
0
 function sendEmail($emailTo, $emailSubject, $emailBody, $altemailBody, SugarBean $relatedBean = null, $emailCc = array(), $emailBcc = array(), $attachments = array())
 {
     require_once 'modules/Emails/Email.php';
     require_once 'include/SugarPHPMailer.php';
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailSubject);
     $mail->Body = $emailBody;
     $mail->AltBody = $altemailBody;
     $mail->handleAttachments($attachments);
     $mail->prepForOutbound();
     if (empty($emailTo)) {
         return false;
     }
     foreach ($emailTo as $to) {
         $mail->AddAddress($to);
     }
     if (!empty($emailCc)) {
         foreach ($emailCc as $email) {
             $mail->AddCC($email);
         }
     }
     if (!empty($emailBcc)) {
         foreach ($emailBcc as $email) {
             $mail->AddBCC($email);
         }
     }
     //now create email
     if (@$mail->Send()) {
         $emailObj->to_addrs = implode(',', $emailTo);
         $emailObj->cc_addrs = implode(',', $emailCc);
         $emailObj->bcc_addrs = implode(',', $emailBcc);
         $emailObj->type = 'out';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->AltBody;
         $emailObj->description_html = $mail->Body;
         $emailObj->from_addr = $mail->From;
         if ($relatedBean instanceof SugarBean && !empty($relatedBean->id)) {
             $emailObj->parent_type = $relatedBean->module_dir;
             $emailObj->parent_id = $relatedBean->id;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
         return true;
     }
     return false;
 }
Esempio n. 19
0
/* Create email bodies to send */
while (($row = $db->fetchByAssoc($result)) != null) {
    if ($row['email_address'] != $prevemail) {
        $emailbody[$row['email_address']] .= "You have the following outstanding cases which have aged more than 3 hours:<br /><br />";
        $emailbody[$row['email_address']] .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . " - " . $row['aging'] . " Hours</a><br />";
        $prevemail = $row['email_address'];
    } else {
        $emailbody[$row['email_address']] .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . " - " . $row['aging'] . " Hours</a><br />";
        $prevemail = $row['email_address'];
    }
}
/* Send out emails */
$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
foreach ($emailbody as $key => $data) {
    $mail->ClearAllRecipients();
    $mail->ClearReplyTos();
    $mail->Subject = "Case Aging Alert";
    $mail->IsHTML(true);
    $mail->Body = $data;
    $mail->AltBody = $data;
    $mail->prepForOutbound();
    $mail->AddAddress($key);
    $mail->Send();
}
/* Clean up shop */
$mail->SMTPClose();
Esempio n. 20
0
 private function sendEmail($emails, $template, $signature = array(), $caseId = null, $addDelimiter = true, $contactId = null)
 {
     $GLOBALS['log']->info("AOPCaseUpdates: sendEmail called");
     require_once "include/SugarPHPMailer.php";
     $mailer = new SugarPHPMailer();
     $admin = new Administration();
     $admin->retrieveSettings();
     $mailer->prepForOutbound();
     $mailer->setMailerForSystem();
     $signatureHTML = "";
     if ($signature && array_key_exists("signature_html", $signature)) {
         $signatureHTML = from_html($signature['signature_html']);
     }
     $signaturePlain = "";
     if ($signature && array_key_exists("signature", $signature)) {
         $signaturePlain = $signature['signature'];
     }
     $emailSettings = getPortalEmailSettings();
     $GLOBALS['log']->info("AOPCaseUpdates: sendEmail email portal settings are " . print_r($emailSettings, true));
     $text = $this->populateTemplate($template, $addDelimiter, $contactId);
     $mailer->Subject = $text['subject'];
     $mailer->Body = $text['body'] . $signatureHTML;
     $mailer->IsHTML(true);
     $mailer->AltBody = $text['body_alt'] . $signaturePlain;
     $mailer->From = $emailSettings['from_address'];
     $mailer->FromName = $emailSettings['from_name'];
     foreach ($emails as $email) {
         $mailer->AddAddress($email);
     }
     if ($mailer->Send()) {
         require_once 'modules/Emails/Email.php';
         $emailObj = new Email();
         $emailObj->to_addrs = implode(",", $emails);
         $emailObj->type = 'out';
         $emailObj->deleted = '0';
         $emailObj->name = $mailer->Subject;
         $emailObj->description = $mailer->AltBody;
         $emailObj->description_html = $mailer->Body;
         $emailObj->from_addr = $mailer->From;
         if ($caseId) {
             $emailObj->parent_type = "Cases";
             $emailObj->parent_id = $caseId;
         }
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
     } else {
         $GLOBALS['log']->info("AOPCaseUpdates: Could not send email:  " . $mailer->ErrorInfo);
         return false;
     }
     return true;
 }
Esempio n. 21
0
    public function run($data)
    {
        global $sugar_config, $timedate;
        $bean = BeanFactory::getBean('AOR_Scheduled_Reports', $data);
        $report = $bean->get_linked_beans('aor_report', 'AOR_Reports');
        if ($report) {
            $report = $report[0];
        } else {
            return false;
        }
        $html = "<h1>{$report->name}</h1>" . $report->build_group_report();
        $html .= <<<EOF
        <style>
        h1{
            color: black;
        }
        .list
        {
            font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;font-size: 12px;
            background: #fff;margin: 45px;width: 480px;border-collapse: collapse;text-align: left;
        }
        .list th
        {
            font-size: 14px;
            font-weight: normal;
            color: black;
            padding: 10px 8px;
            border-bottom: 2px solid black};
        }
        .list td
        {
            padding: 9px 8px 0px 8px;
        }
        </style>
EOF;
        $emailObj = new Email();
        $defaults = $emailObj->getSystemDefaultEmail();
        $mail = new SugarPHPMailer();
        /*$result = $report->db->query($report->build_report_query());
          $reportData = array();
          while($row = $report->db->fetchByAssoc($result, false))
          {
              $reportData[] = $row;
          }
          $fields = $report->getReportFields();
          foreach($report->get_linked_beans('aor_charts','AOR_Charts') as $chart){
              $image = $chart->buildChartImage($reportData,$fields,false);
              $mail->AddStringEmbeddedImage($image,$chart->id,$chart->name.".png",'base64','image/png');
              $html .= "<img src='cid:{$chart->id}'>";
          }*/
        $mail->setMailerForSystem();
        $mail->IsHTML(true);
        $mail->From = $defaults['email'];
        $mail->FromName = $defaults['name'];
        $mail->Subject = from_html($bean->name);
        $mail->Body = $html;
        $mail->prepForOutbound();
        $success = true;
        $emails = $bean->get_email_recipients();
        foreach ($emails as $email_address) {
            $mail->ClearAddresses();
            $mail->AddAddress($email_address);
            $success = $mail->Send() && $success;
        }
        $bean->last_run = $timedate->getNow()->asDb(false);
        $bean->save();
        return true;
    }
Esempio n. 22
0
require_once 'include/entryPoint.php';
require_once 'include/database/DBManagerFactory.php';
require_once 'include/SugarPHPMailer.php';
require_once 'modules/Emails/Email.php';
/* Query database to get case aging */
$query = 'select ca.date_created,c.case_number,c.name,concat("http://dcmaster.mydatacom.com/index.php?module=Cases&action=DetailView&record=",c.id) as link from cases_audit as ca, cases as c where ca.field_name="status" and ca.after_value_string="closed" and c.deleted=0 and timestampdiff(hour,date_created,now())<=24 and c.id=ca.parent_id;';
$db = DBManagerFactory::getInstance();
$result = $db->query($query, true, 'Case Closed Query Failed');
/* Create email bodies to send */
$emailbody = "The following cases were closed in the last 24 hours:<br /><br />";
while (($row = $db->fetchByAssoc($result)) != null) {
    $emailbody .= "<a href='" . $row['link'] . "'>" . $row['case_number'] . " - " . $row['name'] . " - " . $row['date_created'] . " </a><br />";
}
/* Send out emails */
$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->Subject = "Case Closed Report";
$mail->IsHTML(true);
$mail->Body = $emailbody;
$mail->AltBody = $emailbody;
$mail->prepForOutbound();
$mail->AddAddress('*****@*****.**');
$mail->Send();
/* Clean up shop */
$mail->SMTPClose();
Esempio n. 23
0
 private function sendCreationEmail(aCase $bean, $contact)
 {
     if (!isAOPEnabled()) {
         return;
     }
     require_once "include/SugarPHPMailer.php";
     $mailer = new SugarPHPMailer();
     $admin = new Administration();
     $admin->retrieveSettings();
     $mailer->prepForOutbound();
     $mailer->setMailerForSystem();
     $email_template = new EmailTemplate();
     $aop_config = $this->getAOPConfig();
     $email_template = $email_template->retrieve($aop_config['case_creation_email_template_id']);
     if (!$aop_config['case_creation_email_template_id'] || !$email_template) {
         $GLOBALS['log']->warn("CaseUpdatesHook: sendCreationEmail template is empty");
         return false;
     }
     $emailSettings = getPortalEmailSettings();
     $text = $this->populateTemplate($email_template, $bean, $contact);
     $mailer->Subject = $text['subject'];
     $mailer->Body = $text['body'];
     $mailer->IsHTML(true);
     $mailer->AltBody = $text['body_alt'];
     $mailer->From = $emailSettings['from_address'];
     $mailer->FromName = $emailSettings['from_name'];
     $email = $contact->emailAddress->getPrimaryAddress($contact);
     if (empty($email) && !empty($contact->email1)) {
         $email = $contact->email1;
     }
     $mailer->AddAddress($email);
     if (!$mailer->Send()) {
         $GLOBALS['log']->info("CaseUpdatesHook: Could not send email:  " . $mailer->ErrorInfo);
         return false;
     } else {
         $this->logEmail($email, $mailer, $bean->id);
         return true;
     }
 }
Esempio n. 24
0
 function send()
 {
     global $mod_strings;
     global $current_user;
     global $sugar_config;
     global $locale;
     $mail = new SugarPHPMailer();
     foreach ($this->to_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddAddress($addr_arr['email'], "");
         } else {
             $mail->AddAddress($addr_arr['email'], $addr_arr['display']);
         }
     }
     foreach ($this->cc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddCC($addr_arr['email'], "");
         } else {
             $mail->AddCC($addr_arr['email'], $addr_arr['display']);
         }
     }
     foreach ($this->bcc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddBCC($addr_arr['email'], "");
         } else {
             $mail->AddBCC($addr_arr['email'], $addr_arr['display']);
         }
     }
     if ($current_user->getPreference('mail_sendtype') == "SMTP") {
         $mail->Mailer = "smtp";
         $mail->Host = $current_user->getPreference('mail_smtpserver');
         $mail->Port = $current_user->getPreference('mail_smtpport');
         if ($current_user->getPreference('mail_smtpauth_req')) {
             $mail->SMTPAuth = TRUE;
             $mail->Username = $current_user->getPreference('mail_smtpuser');
             $mail->Password = $current_user->getPreference('mail_smtppass');
         }
     } else {
         // cn:no need to check since we default to it in any case!
         $mail->Mailer = "sendmail";
     }
     // FROM ADDRESS
     if (!empty($this->from_addr)) {
         $mail->From = $this->from_addr;
     } else {
         $mail->From = $current_user->getPreference('mail_fromaddress');
         $this->from_addr = $mail->From;
     }
     // FROM NAME
     if (!empty($this->from_name)) {
         $mail->FromName = $this->from_name;
     } else {
         $mail->FromName = $current_user->getPreference('mail_fromname');
         $this->from_name = $mail->FromName;
     }
     $mail->Sender = $mail->From;
     /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
     $mail->AddReplyTo($mail->From, $mail->FromName);
     $encoding = version_compare(phpversion(), '5.0', '>=') ? 'UTF-8' : 'ISO-8859-1';
     $mail->Subject = html_entity_decode($this->name, ENT_QUOTES, $encoding);
     ///////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS
     foreach ($this->saved_attachments as $note) {
         $mime_type = 'text/plain';
         if ($note->object_name == 'Note') {
             if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
                 // brandy-new file upload/attachment
                 $file_location = $sugar_config['upload_dir'] . $note->id;
                 $filename = $note->file->original_file_name;
                 $mime_type = $note->file->mime_type;
             } else {
                 // attachment coming from template/forward
                 $file_location = rawurldecode(UploadFile::get_file_path($note->filename, $note->id));
                 $filename = $note->name;
                 $mime_type = $note->file_mime_type;
             }
         } elseif ($note->object_name == 'DocumentRevision') {
             // from Documents
             $filename = $note->id;
             $file_location = getcwd() . '/cache/upload/' . $filename;
             $mime_type = $note->file_mime_type;
         }
         // strip out the "Email attachment label if exists
         $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename);
         // cn: bug 9233 attachment filenames need to be translated into the destination charset.
         $filename = $locale->translateCharset($filename, 'UTF-8', $locale->getPrecedentPreference('default_email_charset'));
         //is attachment in our list of bad files extensions?  If so, append .txt to file location
         //get position of last "." in file name
         $file_ext_beg = strrpos($file_location, ".");
         $file_ext = "";
         //get file extension
         if ($file_ext_beg > 0) {
             $file_ext = substr($file_location, $file_ext_beg + 1);
         }
         //check to see if this is a file with extension located in "badext"
         foreach ($sugar_config['upload_badext'] as $badExt) {
             if (strtolower($file_ext) == strtolower($badExt)) {
                 //if found, then append with .txt to filename and break out of lookup
                 //this will make sure that the file goes out with right extension, but is stored
                 //as a text in db.
                 $file_location = $file_location . ".txt";
                 break;
                 // no need to look for more
             }
         }
         $mail->AddAttachment($file_location, $filename, 'base64', $mime_type);
     }
     ////	END ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////
     ////	HANDLE EMAIL FORMAT PREFERENCE
     // the if() below is HIGHLY dependent on the Javascript unchecking the Send HTML Email box
     // HTML email
     if (isset($_REQUEST['setEditor']) && $_REQUEST['setEditor'] == 1 && trim($_REQUEST['description_html']) != '' || trim($this->description_html) != '') {
         // wp: if body is html, then insert new lines at 996 characters. no effect on client side
         // due to RFC 2822 which limits email lines to 998
         $mail->IsHTML(true);
         $body = from_html(wordwrap($this->description_html, 996));
         $mail->Body = $body;
         // if alternative body is defined, use that, else, striptags the HTML part
         if (trim($this->description) == '') {
             $plainText = from_html($this->description_html);
             $plainText = strip_tags(br2nl($plainText));
             //$plainText = $locale->translateCharset($plainText, 'UTF-8', $locale->getPrecedentPreference('default_email_charset'));
             $mail->AltBody = $plainText;
             $this->description = $plainText;
         } else {
             $mail->AltBody = wordwrap(from_html($this->description), 996);
         }
         // cn: bug 9709 - html email sent accidentally
         // handle signatures fubar'ing the type
         $sigs = $current_user->getDefaultSignature();
         $htmlSig = trim(str_replace(" ", "", strip_tags(from_html($sigs['signature_html']))));
         $htmlBody = trim(str_replace(" ", "", strip_tags(from_html($this->description_html))));
         if ($htmlSig == $htmlBody) {
             // found just a sig. ignore it.
             $this->description_html = '';
             $mail->IsHTML(false);
             $mail->Body = wordwrap(from_html($this->description, 996));
         }
     } else {
         // plain text only
         $this->description_html = '';
         $mail->IsHTML(false);
         $mail->Body = wordwrap(from_html($this->description, 996));
     }
     // wp: if plain text version has lines greater than 998, use base64 encoding
     foreach (explode("\n", $mail->ContentType == "text/html" ? $mail->AltBody : $mail->Body) as $line) {
         if (strlen($line) > 998) {
             $mail->Encoding = 'base64';
             break;
         }
     }
     ////	HANDLE EMAIL FORMAT PREFERENCE
     ///////////////////////////////////////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////
     ////    SAVE RAW MESSAGE
     $mail->SetMessageType();
     $raw = $mail->CreateHeader();
     $raw .= $mail->CreateBody();
     $this->raw_source = urlencode($raw);
     ////    END SAVE RAW MESSAGE
     ///////////////////////////////////////////////////////////////////////
     $GLOBALS['log']->debug('Email sending --------------------- ');
     ///////////////////////////////////////////////////////////////////////
     ////	I18N TRANSLATION
     $mail->prepForOutbound();
     ////	END I18N TRANSLATION
     ///////////////////////////////////////////////////////////////////////
     if ($mail->Send()) {
         ///////////////////////////////////////////////////////////////////
         ////	INBOUND EMAIL HANDLING
         // mark replied
         if (!empty($_REQUEST['inbound_email_id'])) {
             $ieMail = new Email();
             $ieMail->retrieve($_REQUEST['inbound_email_id']);
             $ieMail->status = 'replied';
             $ieMail->save();
         }
         $GLOBALS['log']->debug(' --------------------- buh bye -- sent successful');
         ////	END INBOUND EMAIL HANDLING
         ///////////////////////////////////////////////////////////////////
         return true;
     }
     $GLOBALS['log']->fatal("Error emailing:" . $mail->ErrorInfo);
     return false;
 }
Esempio n. 25
0
 /**
  * Sends Email
  * @return bool True on success
  */
 function send()
 {
     global $mod_strings, $app_strings;
     global $current_user;
     global $sugar_config;
     global $locale;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     $mail = new SugarPHPMailer();
     foreach ($this->to_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddAddress($addr_arr['email'], "");
         } else {
             $mail->AddAddress($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     foreach ($this->cc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddCC($addr_arr['email'], "");
         } else {
             $mail->AddCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     foreach ($this->bcc_addrs_arr as $addr_arr) {
         if (empty($addr_arr['display'])) {
             $mail->AddBCC($addr_arr['email'], "");
         } else {
             $mail->AddBCC($addr_arr['email'], $locale->translateCharsetMIME(trim($addr_arr['display']), 'UTF-8', $OBCharset));
         }
     }
     $mail = $this->setMailer($mail);
     // FROM ADDRESS
     if (!empty($this->from_addr)) {
         $mail->From = $this->from_addr;
     } else {
         $mail->From = $current_user->getPreference('mail_fromaddress');
         $this->from_addr = $mail->From;
     }
     // FROM NAME
     if (!empty($this->from_name)) {
         $mail->FromName = $this->from_name;
     } else {
         $mail->FromName = $current_user->getPreference('mail_fromname');
         $this->from_name = $mail->FromName;
     }
     //Reply to information for case create and autoreply.
     if (!empty($this->reply_to_name)) {
         $ReplyToName = $this->reply_to_name;
     } else {
         $ReplyToName = $mail->FromName;
     }
     if (!empty($this->reply_to_addr)) {
         $ReplyToAddr = $this->reply_to_addr;
     } else {
         $ReplyToAddr = $mail->From;
     }
     $mail->Sender = $mail->From;
     /* set Return-Path field in header to reduce spam score in emails sent via Sugar's Email module */
     $mail->AddReplyTo($ReplyToAddr, $locale->translateCharsetMIME(trim($ReplyToName), 'UTF-8', $OBCharset));
     //$mail->Subject = html_entity_decode($this->name, ENT_QUOTES, 'UTF-8');
     $mail->Subject = $this->name;
     ///////////////////////////////////////////////////////////////////////
     ////	ATTACHMENTS
     foreach ($this->saved_attachments as $note) {
         $mime_type = 'text/plain';
         if ($note->object_name == 'Note') {
             if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
                 // brandy-new file upload/attachment
                 $file_location = $sugar_config['upload_dir'] . $note->id;
                 $filename = $note->file->original_file_name;
                 $mime_type = $note->file->mime_type;
             } else {
                 // attachment coming from template/forward
                 $file_location = rawurldecode(UploadFile::get_file_path($note->filename, $note->id));
                 // cn: bug 9723 - documents from EmailTemplates sent with Doc Name, not file name.
                 $filename = !empty($note->filename) ? $note->filename : $note->name;
                 $mime_type = $note->file_mime_type;
             }
         } elseif ($note->object_name == 'DocumentRevision') {
             // from Documents
             $filePathName = $note->id;
             // cn: bug 9723 - Emails with documents send GUID instead of Doc name
             $filename = $note->getDocumentRevisionNameForDisplay();
             $file_location = getcwd() . '/' . $GLOBALS['sugar_config']['upload_dir'] . $filePathName;
             $mime_type = $note->file_mime_type;
         }
         // strip out the "Email attachment label if exists
         $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename);
         //is attachment in our list of bad files extensions?  If so, append .txt to file location
         //get position of last "." in file name
         $file_ext_beg = strrpos($file_location, ".");
         $file_ext = "";
         //get file extension
         if ($file_ext_beg > 0) {
             $file_ext = substr($file_location, $file_ext_beg + 1);
         }
         //check to see if this is a file with extension located in "badext"
         foreach ($sugar_config['upload_badext'] as $badExt) {
             if (strtolower($file_ext) == strtolower($badExt)) {
                 //if found, then append with .txt to filename and break out of lookup
                 //this will make sure that the file goes out with right extension, but is stored
                 //as a text in db.
                 $file_location = $file_location . ".txt";
                 break;
                 // no need to look for more
             }
         }
         $mail->AddAttachment($file_location, $locale->translateCharsetMIME(trim($filename), 'UTF-8', $OBCharset), 'base64', $mime_type);
         // embedded Images
         if ($note->embed_flag == true) {
             $cid = $filename;
             $mail->AddEmbeddedImage($file_location, $cid, $filename, 'base64', $mime_type);
         }
     }
     ////	END ATTACHMENTS
     ///////////////////////////////////////////////////////////////////////
     $mail = $this->handleBody($mail);
     $GLOBALS['log']->debug('Email sending --------------------- ');
     ///////////////////////////////////////////////////////////////////////
     ////	I18N TRANSLATION
     $mail->prepForOutbound();
     ////	END I18N TRANSLATION
     ///////////////////////////////////////////////////////////////////////
     if ($mail->Send()) {
         ///////////////////////////////////////////////////////////////////
         ////	INBOUND EMAIL HANDLING
         // mark replied
         if (!empty($_REQUEST['inbound_email_id'])) {
             $ieMail = new Email();
             $ieMail->retrieve($_REQUEST['inbound_email_id']);
             $ieMail->status = 'replied';
             $ieMail->save();
         }
         $GLOBALS['log']->debug(' --------------------- buh bye -- sent successful');
         ////	END INBOUND EMAIL HANDLING
         ///////////////////////////////////////////////////////////////////
         return true;
     }
     $GLOBALS['log']->debug($app_strings['LBL_EMAIL_ERROR_PREPEND'] . $mail->ErrorInfo);
     return false;
 }
Esempio n. 26
0
 /**
  * send reminders
  * @param SugarBean $bean
  * @param Administration $admin
  * @param array $recipients
  * @return boolean
  */
 protected function sendReminders(SugarBean $bean, Administration $admin, $recipients)
 {
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $GLOBALS['sugar_config']['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     if (!empty($bean->created_by)) {
         $user_id = $bean->created_by;
     } else {
         if (!empty($bean->assigned_user_id)) {
             $user_id = $bean->assigned_user_id;
         } else {
             $user_id = $GLOBALS['current_user']->id;
         }
     }
     $user = new User();
     $user->retrieve($bean->created_by);
     $OBCharset = $GLOBALS['locale']->getPrecedentPreference('default_email_charset');
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     if (empty($admin->settings['notify_send_from_assigning_user'])) {
         $from_address = $admin->settings['notify_fromaddress'];
         $from_name = $admin->settings['notify_fromname'] ? "" : $admin->settings['notify_fromname'];
     } else {
         $from_address = $user->emailAddress->getReplyToAddress($user);
         $from_name = $user->full_name;
     }
     $mail->From = $from_address;
     $mail->FromName = $from_name;
     $xtpl = new XTemplate(get_notify_template_file($current_language));
     $xtpl = $this->setReminderBody($xtpl, $bean, $user);
     $template_name = $GLOBALS['beanList'][$bean->module_dir] . 'Reminder';
     $xtpl->parse($template_name);
     $xtpl->parse($template_name . "_Subject");
     $mail->Body = from_html(trim($xtpl->text($template_name)));
     $mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
     $oe = new OutboundEmail();
     $oe = $oe->getSystemMailerSettings();
     if (empty($oe->mail_smtpserver)) {
         Log::fatal("Email Reminder: error sending email, system smtp server is not set");
         return;
     }
     foreach ($recipients as $r) {
         $mail->ClearAddresses();
         $mail->AddAddress($r['email'], $GLOBALS['locale']->translateCharsetMIME(trim($r['name']), 'UTF-8', $OBCharset));
         $mail->prepForOutbound();
         if (!$mail->Send()) {
             Log::fatal("Email Reminder: error sending e-mail (method: {$mail->Mailer}), (error: {$mail->ErrorInfo})");
         }
     }
     return true;
 }
Esempio n. 27
0
 /**
  * This function handles create the email notifications email.
  * @param string $notify_user the user to send the notification email to
  */
 function create_notification_email($notify_user)
 {
     global $sugar_version;
     global $sugar_config;
     global $app_list_strings;
     global $current_user;
     global $locale;
     global $beanList;
     $OBCharset = $locale->getPrecedentPreference('default_email_charset');
     require_once "include/SugarPHPMailer.php";
     $notify_address = $notify_user->emailAddress->getPrimaryAddress($notify_user);
     $notify_name = $notify_user->full_name;
     $GLOBALS['log']->debug("Notifications: user has e-mail defined");
     $notify_mail = new SugarPHPMailer();
     $notify_mail->AddAddress($notify_address, $locale->translateCharsetMIME(trim($notify_name), 'UTF-8', $OBCharset));
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $sugar_config['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     $xtpl = new XTemplate(get_notify_template_file($current_language));
     if ($this->module_dir == "Cases") {
         $template_name = "Case";
         //we should use Case, you can refer to the en_us.notify_template.html.
     } else {
         $template_name = $beanList[$this->module_dir];
         //bug 20637, in workflow this->object_name = strange chars.
     }
     $this->current_notify_user = $notify_user;
     if (in_array('set_notification_body', get_class_methods($this))) {
         $xtpl = $this->set_notification_body($xtpl, $this);
     } else {
         $xtpl->assign("OBJECT", $this->object_name);
         $template_name = "Default";
     }
     if (!empty($_SESSION["special_notification"]) && $_SESSION["special_notification"]) {
         $template_name = $beanList[$this->module_dir] . 'Special';
     }
     if ($this->special_notification) {
         $template_name = $beanList[$this->module_dir] . 'Special';
     }
     $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name);
     $xtpl->assign("ASSIGNER", $current_user->name);
     $port = '';
     if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
         $port = $_SERVER['SERVER_PORT'];
     }
     if (!isset($_SERVER['HTTP_HOST'])) {
         $_SERVER['HTTP_HOST'] = '';
     }
     $httpHost = $_SERVER['HTTP_HOST'];
     if ($colon = strpos($httpHost, ':')) {
         $httpHost = substr($httpHost, 0, $colon);
     }
     $parsedSiteUrl = parse_url($sugar_config['site_url']);
     $host = $parsedSiteUrl['host'];
     if (!isset($parsedSiteUrl['port'])) {
         $parsedSiteUrl['port'] = 80;
     }
     $port = $parsedSiteUrl['port'] != 80 ? ":" . $parsedSiteUrl['port'] : '';
     $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : "";
     $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}";
     $xtpl->assign("URL", $cleanUrl . "/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}");
     $xtpl->assign("SUGAR", "Sugar v{$sugar_version}");
     $xtpl->parse($template_name);
     $xtpl->parse($template_name . "_Subject");
     $notify_mail->Body = from_html(trim($xtpl->text($template_name)));
     $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject"));
     // cn: bug 8568 encode notify email in User's outbound email encoding
     $notify_mail->prepForOutbound();
     return $notify_mail;
 }
 /**
  * Sends the users password to the email address or sends 
  *
  * @param unknown_type $user_id
  * @param unknown_type $password
  */
 function sendEmailPassword($user_id, $password)
 {
     $result = $GLOBALS['db']->query("SELECT email1, email2, first_name, last_name FROM users WHERE id='{$user_id}'");
     $row = $GLOBALS['db']->fetchByAssoc($result);
     global $sugar_config;
     if (empty($row['email1']) && empty($row['email2'])) {
         $_SESSION['login_error'] = 'Please contact an administrator to setup up your email address associated to this account';
         return;
     }
     require_once "include/SugarPHPMailer.php";
     $notify_mail = new SugarPHPMailer();
     $notify_mail->CharSet = $sugar_config['default_charset'];
     $notify_mail->AddAddress(!empty($row['email1']) ? $row['email1'] : $row['email2'], $row['first_name'] . ' ' . $row['last_name']);
     if (empty($_SESSION['authenticated_user_language'])) {
         $current_language = $sugar_config['default_language'];
     } else {
         $current_language = $_SESSION['authenticated_user_language'];
     }
     $mail_settings = new Administration();
     $mail_settings->retrieveSettings('mail');
     $notify_mail->Subject = 'Sugar Token';
     $notify_mail->Body = 'Your sugar session authentication token  is: ' . $password;
     if ($mail_settings->settings['mail_sendtype'] == "SMTP") {
         $notify_mail->Mailer = "smtp";
         $notify_mail->Host = $mail_settings->settings['mail_smtpserver'];
         $notify_mail->Port = $mail_settings->settings['mail_smtpport'];
         if ($mail_settings->settings['mail_smtpauth_req']) {
             $notify_mail->SMTPAuth = TRUE;
             $notify_mail->Username = $mail_settings->settings['mail_smtpuser'];
             $notify_mail->Password = $mail_settings->settings['mail_smtppass'];
         }
     }
     $notify_mail->From = '*****@*****.**';
     $notify_mail->FromName = 'Sugar Authentication';
     if (!$notify_mail->Send()) {
         $GLOBALS['log']->warn("Notifications: error sending e-mail (method: {$notify_mail->Mailer}), (error: {$notify_mail->ErrorInfo})");
     } else {
         $GLOBALS['log']->info("Notifications: e-mail successfully sent");
     }
 }
Esempio n. 29
0
 /**
  * Send new password or link to user
  *
  * @param string $templateId Id of email template
  * @param array $additionalData additional params: link, url, password
  * @return array status: true|false, message: error message, if status = false and message = '' it means that send method has returned false
  */
 public function sendEmailForPassword($templateId, array $additionalData = array())
 {
     global $sugar_config, $current_user;
     $mod_strings = return_module_language('', 'Users');
     $result = array('status' => false, 'message' => '');
     $emailTemp = new EmailTemplate();
     $emailTemp->disable_row_level_security = true;
     if ($emailTemp->retrieve($templateId) == '') {
         $result['message'] = $mod_strings['LBL_EMAIL_TEMPLATE_MISSING'];
         return $result;
     }
     //replace instance variables in email templates
     $htmlBody = $emailTemp->body_html;
     $body = $emailTemp->body;
     if (isset($additionalData['link']) && $additionalData['link'] == true) {
         $htmlBody = str_replace('$contact_user_link_guid', $additionalData['url'], $htmlBody);
         $body = str_replace('$contact_user_link_guid', $additionalData['url'], $body);
     } else {
         $htmlBody = str_replace('$contact_user_user_hash', $additionalData['password'], $htmlBody);
         $body = str_replace('$contact_user_user_hash', $additionalData['password'], $body);
     }
     // Bug 36833 - Add replacing of special value $instance_url
     $htmlBody = str_replace('$config_site_url', $sugar_config['site_url'], $htmlBody);
     $body = str_replace('$config_site_url', $sugar_config['site_url'], $body);
     $htmlBody = str_replace('$contact_user_user_name', $this->user_name, $htmlBody);
     $htmlBody = str_replace('$contact_user_pwd_last_changed', TimeDate::getInstance()->nowDb(), $htmlBody);
     $body = str_replace('$contact_user_user_name', $this->user_name, $body);
     $body = str_replace('$contact_user_pwd_last_changed', TimeDate::getInstance()->nowDb(), $body);
     $emailTemp->body_html = $htmlBody;
     $emailTemp->body = $body;
     $itemail = $this->emailAddress->getPrimaryAddress($this);
     //retrieve IT Admin Email
     //_ppd( $emailTemp->body_html);
     //retrieve email defaults
     $emailObj = new Email();
     $defaults = $emailObj->getSystemDefaultEmail();
     require_once 'include/SugarPHPMailer.php';
     $mail = new SugarPHPMailer();
     $mail->setMailerForSystem();
     //$mail->IsHTML(true);
     $mail->From = $defaults['email'];
     $mail->FromName = $defaults['name'];
     $mail->ClearAllRecipients();
     $mail->ClearReplyTos();
     $mail->Subject = from_html($emailTemp->subject);
     if ($emailTemp->text_only != 1) {
         $mail->IsHTML(true);
         $mail->Body = from_html($emailTemp->body_html);
         $mail->AltBody = from_html($emailTemp->body);
     } else {
         $mail->Body_html = from_html($emailTemp->body_html);
         $mail->Body = from_html($emailTemp->body);
     }
     if ($mail->Body == '' && $current_user->is_admin) {
         global $app_strings;
         $result['message'] = $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT'];
         return $result;
     }
     if ($mail->Mailer == 'smtp' && $mail->Host == '' && $current_user->is_admin) {
         $result['message'] = $mod_strings['ERR_SERVER_SMTP_EMPTY'];
         return $result;
     }
     $mail->prepForOutbound();
     $hasRecipients = false;
     if (!empty($itemail)) {
         if ($hasRecipients) {
             $mail->AddBCC($itemail);
         } else {
             $mail->AddAddress($itemail);
         }
         $hasRecipients = true;
     }
     if ($hasRecipients) {
         $result['status'] = @$mail->Send();
     }
     if ($result['status'] == true) {
         $emailObj->team_id = 1;
         $emailObj->to_addrs = '';
         $emailObj->type = 'archived';
         $emailObj->deleted = '0';
         $emailObj->name = $mail->Subject;
         $emailObj->description = $mail->Body;
         $emailObj->description_html = null;
         $emailObj->from_addr = $mail->From;
         $emailObj->parent_type = 'User';
         $emailObj->date_sent = TimeDate::getInstance()->nowDb();
         $emailObj->modified_user_id = '1';
         $emailObj->created_by = '1';
         $emailObj->status = 'sent';
         $emailObj->save();
         if (!isset($additionalData['link']) || $additionalData['link'] == false) {
             $user_hash = strtolower(md5($additionalData['password']));
             $this->setPreference('loginexpiration', '0');
             $this->setPreference('lockout', '');
             $this->setPreference('loginfailed', '0');
             $this->savePreferencesToDB();
             //set new password
             $now = TimeDate::getInstance()->nowDb();
             $query = "UPDATE {$this->table_name} SET user_hash='{$user_hash}', system_generated_password='******', pwd_last_changed='{$now}' where id='{$this->id}'";
             $this->db->query($query, true, "Error setting new password for {$this->user_name}: ");
         }
     }
     return $result;
 }
Esempio n. 30
0
$excelreport->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$excelreport->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$excelreport->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$excelreport->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$excelreport->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
/* Set Formatting on Sheet */
$excelreport->getActiveSheet()->getStyle('A1:G2')->getFont()->setBold(true);
$excelreport->getActiveSheet()->getStyle('A2:G2')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
/* Write it out to a temp file */
$objWriter = PHPExcel_IOFactory::createWriter($excelreport, 'Excel2007');
$objWriter->save('/tmp/Tetra-Monthly-Report.xlsx');
/* Send out emails */
$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->Subject = "Tetra Monthly Report Draft";
$mail->IsHTML(true);
$mail->Body = $emailbody;
$mail->AltBody = $emailbody;
$mail->AddAttachment('/tmp/Tetra-Monthly-Report.xlsx');
$mail->prepForOutbound();
$mail->AddAddress('*****@*****.**');
$mail->Send();
/* Clean up shop */
$mail->SMTPClose();
unlink('/tmp/Tetra-Monthly-Report.xlsx');