Example #1
0
function canSendPassword()
{
    global $mod_strings, $current_user, $app_strings;
    require_once "modules/OutboundEmailConfiguration/OutboundEmailConfigurationPeer.php";
    if ($current_user->is_admin) {
        $emailTemplate = new EmailTemplate();
        $emailTemplate->disable_row_level_security = true;
        if ($emailTemplate->retrieve($GLOBALS['sugar_config']['passwordsetting']['generatepasswordtmpl']) == '') {
            return $mod_strings['LBL_EMAIL_TEMPLATE_MISSING'];
        }
        if (empty($emailTemplate->body) && empty($emailTemplate->body_html)) {
            return $app_strings['LBL_EMAIL_TEMPLATE_EDIT_PLAIN_TEXT'];
        }
        if (!OutboundEmailConfigurationPeer::validSystemMailConfigurationExists($current_user)) {
            return $mod_strings['ERR_SERVER_SMTP_EMPTY'];
        }
        $emailErrors = $mod_strings['ERR_EMAIL_NOT_SENT_ADMIN'];
        try {
            $config = OutboundEmailConfigurationPeer::getSystemDefaultMailConfiguration();
            if ($config instanceof OutboundSmtpEmailConfiguration) {
                $emailErrors .= "<br>-{$mod_strings['ERR_SMTP_URL_SMTP_PORT']}";
                if ($config->isAuthenticationRequired()) {
                    $emailErrors .= "<br>-{$mod_strings['ERR_SMTP_USERNAME_SMTP_PASSWORD']}";
                }
            }
        } catch (MailerException $me) {
            // might want to report the error
        }
        $emailErrors .= "<br>-{$mod_strings['ERR_RECIPIENT_EMAIL']}";
        $emailErrors .= "<br>-{$mod_strings['ERR_SERVER_STATUS']}";
        return $emailErrors;
    }
    return $mod_strings['LBL_EMAIL_NOT_SENT'];
}
 /**
  * @access public
  * @param User $user required
  * @return bool
  */
 public static function validSystemMailConfigurationExists(User $user)
 {
     $configExists = false;
     try {
         $config = OutboundEmailConfigurationPeer::getSystemMailConfiguration($user);
         $configExists = self::isMailConfigurationValid($config);
     } catch (MailerException $me) {
         $GLOBALS["log"]->warn("An error occurred while searching for a valid system mail configuration: " . $me->getMessage());
     }
     return $configExists;
 }
 /**
  * @param $api
  * @param $args
  * @return array
  */
 public function listConfigurations($api, $args)
 {
     $list = array();
     $configs = OutboundEmailConfigurationPeer::listValidMailConfigurations($GLOBALS["current_user"]);
     foreach ($configs as $config) {
         $inboxId = $config->getInboxId();
         $configType = $config->getConfigType();
         $list[] = array("id" => is_null($inboxId) ? $config->getConfigId() : $inboxId, "display" => $config->getDisplayName(), "type" => $configType, "default" => $configType == "system");
     }
     return $list;
 }
 /**
  * Run the Upgrade Task
  *
  * Set the user preference for email link type to 'mailto' if the system configuration is not properly set
  */
 public function run()
 {
     if (!version_compare($this->from_version, '7.2.0', "<")) {
         return;
     }
     $user = BeanFactory::getBean('Users');
     $users = get_user_array(false);
     foreach ($users as $userId => $userName) {
         $user->retrieve($userId);
         $emailClientPreference = $user->getPreference('email_link_type');
         if ($emailClientPreference == 'sugar') {
             $mailerPreferenceStatus = OutboundEmailConfigurationPeer::getMailConfigurationStatusForUser($user, 'sugar');
             if ($mailerPreferenceStatus != OutboundEmailConfigurationPeer::STATUS_VALID_CONFIG) {
                 $user->setPreference('email_link_type', 'mailto');
             }
             $user->savePreferencesToDB();
         }
     }
 }
Example #5
0
 protected function setupEmailSettings()
 {
     global $current_user, $app_list_strings;
     $this->ss->assign("MAIL_SENDTYPE", get_select_options_with_id($app_list_strings['notifymail_sendtype'], $this->bean->getPreference('mail_sendtype')));
     ///////////////////////////////////////////////////////////////////////////////
     ////	EMAIL OPTIONS
     // We need to turn off the requiredness of emails if it is a group or portal user
     if ($this->usertype == 'GROUP' || $this->usertype == 'PORTAL_ONLY') {
         global $dictionary;
         $dictionary['User']['fields']['email1']['required'] = false;
     }
     // hack to disable email field being required if it shouldn't be required
     if ($this->ss->get_template_vars("REQUIRED_EMAIL_ADDRESS") == '0') {
         $GLOBALS['dictionary']['User']['fields']['email1']['required'] = false;
     }
     $this->ss->assign("NEW_EMAIL", '<span id="email_span">' . getEmailAddressWidget($this->bean, "email1", $this->bean->email1, $this->viewType) . '</span>');
     // hack to undo that previous hack
     if ($this->ss->get_template_vars("REQUIRED_EMAIL_ADDRESS") == '0') {
         $GLOBALS['dictionary']['User']['fields']['email1']['required'] = true;
     }
     $raw_email_link_type = $this->bean->getPreference('email_link_type');
     $mailerPreferenceStatus = OutboundEmailConfigurationPeer::getMailConfigurationStatusForUser($current_user);
     $options = $app_list_strings['dom_email_link_type'];
     if ($this->viewType == 'EditView') {
         if ($mailerPreferenceStatus === OutboundEmailConfigurationPeer::STATUS_INVALID_SYSTEM_CONFIG) {
             $raw_email_link_type = 'mailto';
         }
         $this->ss->assign('EMAIL_LINK_TYPE', get_select_options_with_id($options, $raw_email_link_type));
     } else {
         $this->ss->assign('EMAIL_LINK_TYPE', $options[$raw_email_link_type]);
     }
     /////	END EMAIL OPTIONS
     ///////////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////
     /// Handle email account selections for users
     /////////////////////////////////////////////
     $hide_if_can_use_default = true;
     $disableSugarClient = false;
     if (!($this->usertype == 'GROUP' || $this->usertype == 'PORTAL_ONLY')) {
         // email smtp
         $systemOutboundEmail = new OutboundEmail();
         $systemOutboundEmail = $systemOutboundEmail->getSystemMailerSettings();
         $mail_smtpserver = $systemOutboundEmail->mail_smtpserver;
         $mail_smtptype = $systemOutboundEmail->mail_smtptype;
         $mail_smtpport = $systemOutboundEmail->mail_smtpport;
         $mail_smtpssl = $systemOutboundEmail->mail_smtpssl;
         $mail_smtpuser = "";
         $mail_smtppass = "";
         $mail_smtpdisplay = $systemOutboundEmail->mail_smtpdisplay;
         $mail_smtpauth_req = true;
         $mail_haspass = empty($systemOutboundEmail->mail_smtppass) ? 0 : 1;
         if (!$systemOutboundEmail->isAllowUserAccessToSystemDefaultOutbound()) {
             $mail_smtpauth_req = $systemOutboundEmail->mail_smtpauth_req;
             $userOverrideOE = $systemOutboundEmail->getUsersMailerForSystemOverride($this->bean->id);
             if ($userOverrideOE != null) {
                 $mail_smtpuser = $userOverrideOE->mail_smtpuser;
                 $mail_smtppass = $userOverrideOE->mail_smtppass;
                 $mail_haspass = empty($userOverrideOE->mail_smtppass) ? 0 : 1;
             }
             if (!$mail_smtpauth_req && (empty($systemOutboundEmail->mail_smtpserver) || empty($systemOutboundEmail->mail_smtpuser) || empty($systemOutboundEmail->mail_smtppass))) {
                 $hide_if_can_use_default = true;
             } else {
                 $hide_if_can_use_default = false;
             }
         }
         $this->ss->assign("mail_smtpdisplay", $mail_smtpdisplay);
         $this->ss->assign("mail_smtpserver", $mail_smtpserver);
         $this->ss->assign("mail_smtpuser", $mail_smtpuser);
         $this->ss->assign("mail_smtppass", "");
         $this->ss->assign("mail_haspass", $mail_haspass);
         $this->ss->assign("mail_smtpauth_req", $mail_smtpauth_req);
         $this->ss->assign('MAIL_SMTPPORT', $mail_smtpport);
         $this->ss->assign('MAIL_SMTPSSL', $mail_smtpssl);
     }
     if ($mailerPreferenceStatus === OutboundEmailConfigurationPeer::STATUS_INVALID_SYSTEM_CONFIG) {
         $disableSugarClient = true;
         $hide_if_can_use_default = true;
         //to hide the username/password fields
     }
     $this->ss->assign('DISABLE_SUGAR_CLIENT', $disableSugarClient);
     $this->ss->assign('HIDE_IF_CAN_USE_DEFAULT_OUTBOUND', $hide_if_can_use_default);
 }
Example #6
0
 /**
  * Returns the system outbound email configuration associated with the specified user.
  *
  * @access protected
  * @param User $user required The user from which the mail configuration is retrieved.
  * @return OutboundEmailConfiguration An OutboundEmailConfiguration object or one that derives from it.
  * @throws MailerException Allows MailerExceptions to bubble up.
  */
 protected static function getOutboundEmailConfiguration(User $user)
 {
     return OutboundEmailConfigurationPeer::getSystemMailConfiguration($user);
 }
Example #7
0
 /**
  * Helper function to get the email link type user pref
  * @param User $user Current User object
  * @return array
  */
 protected function getUserPrefEmail_link_type($user)
 {
     $emailClientPreference = $user->getEmailClientPreference();
     $preferences = array('type' => $emailClientPreference);
     if ($emailClientPreference === 'sugar') {
         $statusCode = OutboundEmailConfigurationPeer::getMailConfigurationStatusForUser($user);
         if ($statusCode != OutboundEmailConfigurationPeer::STATUS_VALID_CONFIG) {
             $preferences['error'] = array('code' => $statusCode, 'message' => OutboundEmailConfigurationPeer::$configurationStatusMessageMappings[$statusCode]);
         }
     }
     return array('email_client_preference' => $preferences);
 }
 /**
  * @param null|string $mode
  * @throws MailerException
  */
 public function setMode($mode = null)
 {
     if (empty($mode)) {
         $mode = OutboundEmailConfigurationPeer::MODE_DEFAULT;
     }
     $mode = strtolower($mode);
     // make sure it's lower case
     if (!OutboundEmailConfigurationPeer::isValidMode($mode)) {
         throw new MailerException("Invalid Mailer: '{$mode}' is an invalid mode", MailerException::InvalidMailer);
     }
     $this->mode = $mode;
 }
Example #9
0
    $sugar_smarty->assign("LDAP_ENC_KEY_DESC", $config_strings['LDAP_ENC_KEY_NO_FUNC_DESC']);
} else {
    $sugar_smarty->assign("LDAP_ENC_KEY_DESC", $config_strings['LBL_LDAP_ENC_KEY_DESC']);
}
$sugar_smarty->assign("settings", $focus->settings);
if ($valid_public_key) {
    if (!empty($focus->settings['captcha_on'])) {
        $sugar_smarty->assign("CAPTCHA_CONFIG_DISPLAY", 'inline');
    } else {
        $sugar_smarty->assign("CAPTCHA_CONFIG_DISPLAY", 'none');
    }
} else {
    $sugar_smarty->assign("CAPTCHA_CONFIG_DISPLAY", 'inline');
}
$sugar_smarty->assign("VALID_PUBLIC_KEY", $valid_public_key);
$res = $GLOBALS['sugar_config']['passwordsetting'];
$outboundMailConfig = OutboundEmailConfigurationPeer::getSystemDefaultMailConfiguration();
$smtpServerIsSet = OutboundEmailConfigurationPeer::isMailConfigurationValid($outboundMailConfig) ? "0" : "1";
$sugar_smarty->assign("SMTP_SERVER_NOT_SET", $smtpServerIsSet);
$focus = BeanFactory::getBean('InboundEmail');
$focus->checkImap();
$storedOptions = unserialize(base64_decode($focus->stored_options));
$email_templates_arr = get_bean_select_array(true, 'EmailTemplate', 'name', '', 'name', true);
$create_case_email_template = isset($storedOptions['create_case_email_template']) ? $storedOptions['create_case_email_template'] : "";
$TMPL_DRPDWN_LOST = get_select_options_with_id($email_templates_arr, $res['lostpasswordtmpl']);
$TMPL_DRPDWN_GENERATE = get_select_options_with_id($email_templates_arr, $res['generatepasswordtmpl']);
$sugar_smarty->assign("TMPL_DRPDWN_LOST", $TMPL_DRPDWN_LOST);
$sugar_smarty->assign("TMPL_DRPDWN_GENERATE", $TMPL_DRPDWN_GENERATE);
$LOGGED_OUT_DISPLAY = isset($res['lockoutexpiration']) && $res['lockoutexpiration'] == '0' ? 'none' : '';
$sugar_smarty->assign("LOGGED_OUT_DISPLAY_STATUS", $LOGGED_OUT_DISPLAY);
$sugar_smarty->display('modules/Administration/PasswordManager.tpl');
Example #10
0
 $out['emailTemplates'] = $email_templates_arr;
 $sigs = $current_user->getSignaturesArray();
 // clean "none"
 foreach ($sigs as $k => $v) {
     if ($k == "") {
         $sigs[$k] = $app_strings['LBL_NONE'];
     } else {
         if (is_array($v) && isset($v['name'])) {
             $sigs[$k] = $v['name'];
         } else {
             $sigs[$k] = $v;
         }
     }
 }
 $configArray = array();
 $configs = OutboundEmailConfigurationPeer::listMailConfigurations($current_user);
 foreach ($configs as $config) {
     $config_id = $config->getInboxId();
     if (empty($config_id)) {
         $config_id = $config->getConfigId();
     }
     $configItem = array("value" => $config_id, "text" => $config->getDisplayName());
     $configArray[] = $configItem;
 }
 $out['signatures'] = $sigs;
 // $out['fromAccounts']  = $email->et->getFromAccountsArray($ie);
 $out['fromAccounts'] = $configArray;
 $out['errorArray'] = array();
 $oe = new OutboundEmail();
 if ($oe->doesUserOverrideAccountRequireCredentials($current_user->id)) {
     $overideAccount = $oe->getUsersMailerForSystemOverride($current_user->id);
Example #11
0
 /**
  * Sends Email
  * @return bool True on success
  */
 function send()
 {
     global $mod_strings, $app_strings, $current_user, $sugar_config;
     try {
         $mailConfig = OutboundEmailConfigurationPeer::getSystemMailConfiguration($current_user);
         $mailerFactoryClass = $this->MockMailerFactoryClass;
         $mailer = $mailerFactoryClass::getMailer($mailConfig);
         if (is_array($this->to_addrs_arr)) {
             foreach ($this->to_addrs_arr as $addr_arr) {
                 try {
                     $mailer->addRecipientsTo(new EmailIdentity($addr_arr['email'], $addr_arr['display']));
                 } catch (MailerException $me) {
                     // eat the exception
                 }
             }
         }
         if (is_array($this->cc_addrs_arr)) {
             foreach ($this->cc_addrs_arr as $addr_arr) {
                 try {
                     $mailer->addRecipientsCc(new EmailIdentity($addr_arr['email'], $addr_arr['display']));
                 } catch (MailerException $me) {
                     // eat the exception
                 }
             }
         }
         if (is_array($this->bcc_addrs_arr)) {
             foreach ($this->bcc_addrs_arr as $addr_arr) {
                 try {
                     $mailer->addRecipientsBcc(new EmailIdentity($addr_arr['email'], $addr_arr['display']));
                 } catch (MailerException $me) {
                     // eat the exception
                 }
             }
         }
         // SENDER Info
         if (empty($this->from_addr)) {
             $this->from_addr = $current_user->getPreference('mail_fromaddress');
         }
         if (empty($this->from_name)) {
             $this->from_name = $current_user->getPreference('mail_fromname');
         }
         // REPLY-TO Info
         if (empty($this->reply_to_addr)) {
             $this->reply_to_addr = $this->from_addr;
             $this->reply_to_name = $this->from_name;
         }
         $mailer->setHeader(EmailHeaders::From, new EmailIdentity($this->from_addr, $this->from_name));
         $mailer->setHeader(EmailHeaders::ReplyTo, new EmailIdentity($this->reply_to_addr, $this->reply_to_name));
         $mailer->setSubject($this->name);
         ///////////////////////////////////////////////////////////////////////
         ////	ATTACHMENTS
         if (is_array($this->saved_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 = "upload://{$note->id}";
                         $filename = $note->file->original_file_name;
                         $mime_type = $note->file->mime_type;
                     } else {
                         // attachment coming from template/forward
                         $file_location = "upload://{$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 = "upload://{$note->id}";
                     $mime_type = $note->file_mime_type;
                 }
                 // strip out the "Email attachment label if exists
                 $filename = str_replace($mod_strings['LBL_EMAIL_ATTACHMENT'] . ': ', '', $filename);
                 $file_ext = pathinfo($filename, PATHINFO_EXTENSION);
                 //is attachment in our list of bad files extensions?  If so, append .txt to file location
                 //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
                     }
                 }
                 $attachment = null;
                 if ($note->embed_flag == true) {
                     $cid = $filename;
                     $attachment = AttachmentPeer::embeddedImageFromSugarBean($note, $cid);
                 } else {
                     $attachment = AttachmentPeer::attachmentFromSugarBean($note);
                 }
                 $mailer->addAttachment($attachment);
             }
         }
         ////	END ATTACHMENTS
         ///////////////////////////////////////////////////////////////////////
         if (isset($_REQUEST['description_html'])) {
             $this->description_html = $_REQUEST['description_html'];
         }
         $htmlBody = $this->description_html;
         $textBody = $this->description;
         //------------------- HANDLEBODY() ---------------------------------------------
         if (isset($_REQUEST['setEditor']) && $_REQUEST['setEditor'] == 1 && trim($this->description_html) != '' && $current_user->getPreference('email_editor_option', 'global') !== 'plain') {
             $htmlBody = $this->decodeDuringSend($htmlBody);
             $textBody = $this->decodeDuringSend($textBody);
         } else {
             $textBody = str_replace("&nbsp;", " ", $textBody);
             $textBody = str_replace("</p>", "</p><br />", $textBody);
             $textBody = strip_tags(br2nl($textBody));
             $textBody = str_replace("&amp;", "&", $textBody);
             $textBody = str_replace("&#39;", "'", $textBody);
             $textBody = $this->decodeDuringSend($textBody);
         }
         $mailer->setHtmlBody($htmlBody);
         $mailer->setTextBody($textBody);
         $mailer->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();
         }
         return true;
     } catch (MailerException $me) {
         $GLOBALS["log"]->error($me->getLogMessage());
     } catch (Exception $e) {
         $GLOBALS['log']->error($app_strings['LBL_EMAIL_ERROR_PREPEND'] . $e->getMessage());
     }
     return false;
 }