Sugar 11.0.2: Email to case causes formatting to be incorrect

Hi,

An onpremise customer of ours got updated from 9.0.2 to 11.0.2 recently. One of the key features they use is the capability of importing e-mails and creating a case from it. We noticed a difference in how Sugar used to handle the creation of the case and how it is working since the upgrade. 

When we open the e-mail the body of the mail (description_html) seems to be fine and looks ok. When we open the created case on the other hand all seems to be scrambled and the HTML is not correctly converted as how it was in 9.0.2. The HTML contains a lot of tables. (it is a form submission converted to a table like structure to show it correctly in e-mail). As said, in the email it looks al correct because HTML is disabled. 

Did anyone notice this behaviour as well and if so how can we fix it? We already thought about a temporary solution by adding a description_html field in the cases module and copy the html from the email to the case when it is created and show the description / description_html field based on a checkbox. But that has its drawbacks also. 

Parents
  • I have had issues with html encoding in the Case description since v7.0 and it keeps coming back like a bad penny...

    The latest recurrence was Defect #(81812) which was fixed in 11.3  which, of course, is not available OnSite. 
    I asked for a hot fix but they could not give me one, and told me to wait for the upgrade to v12. 

    I've not upgraded to v12 yet for a series of reasons, not the least of which is I have to convert to Enterprise first and review all the customizations I did to add the features that Enterprise now has out of the box...

    I hope your customer's transition to v12 is easier than mine :)

  • Dear Francesca,

    I am facing issue that my description contains formatted html data and while sending email to user programmatically,

    description field not formatted.

    My code:

    "

    $oTemplate = new EmailTemplate();
    $oMail = new SugarPHPMailer();
    $oEmailObj = new Email();
    $oTemplate->retrieve_by_string_fields(array('name' => "Template Name", 'type' => 'email'));
    $defaults = $oEmailObj->getSystemDefaultEmail();
    $oMail->From = $defaults['email'];
    $oMail->FromName = $defaults['name'];
    $oMail->ClearAllRecipients();
    $oMail->ClearReplyTos();
    $oMail->AddAddress($oUser->email1, $oUser->full_name);
    $test = $oUser->full_name;
    $oMail->Subject = parse_alert_template($oTask, $oTemplate->subject);
    $body = parse_alert_template($oTask, $oTemplate->body_html);
    $description = strip_tags($oTask->description);
    $body = str_replace('$task_description',$description,$body);
    $oMail->Body_html = from_html($body);
    $oMail->Body = wordwrap($body, 900);
    $oMail->Body = $body;
    $oMail->IsHTML(true);
    $oMail->prepForOutbound();
    $oMail->setMailerForSystem();

    "

    but this was working previously.

    Your help is appreciated.

    Thanks,

    Shreya

Reply
  • Dear Francesca,

    I am facing issue that my description contains formatted html data and while sending email to user programmatically,

    description field not formatted.

    My code:

    "

    $oTemplate = new EmailTemplate();
    $oMail = new SugarPHPMailer();
    $oEmailObj = new Email();
    $oTemplate->retrieve_by_string_fields(array('name' => "Template Name", 'type' => 'email'));
    $defaults = $oEmailObj->getSystemDefaultEmail();
    $oMail->From = $defaults['email'];
    $oMail->FromName = $defaults['name'];
    $oMail->ClearAllRecipients();
    $oMail->ClearReplyTos();
    $oMail->AddAddress($oUser->email1, $oUser->full_name);
    $test = $oUser->full_name;
    $oMail->Subject = parse_alert_template($oTask, $oTemplate->subject);
    $body = parse_alert_template($oTask, $oTemplate->body_html);
    $description = strip_tags($oTask->description);
    $body = str_replace('$task_description',$description,$body);
    $oMail->Body_html = from_html($body);
    $oMail->Body = wordwrap($body, 900);
    $oMail->Body = $body;
    $oMail->IsHTML(true);
    $oMail->prepForOutbound();
    $oMail->setMailerForSystem();

    "

    but this was working previously.

    Your help is appreciated.

    Thanks,

    Shreya

Children
  • I use Mailer Factory to send emails, I think it's better than using the Email bean directly.

    support.sugarcrm.com/.../

    I built a small utility function that I reuse in various parts of my code and it seems to work fine. The $EmailBody is strictly HTML in my case.

    Per the manual you can set the Text Body and/or the HTML body:

    $mailer->setTextBody("This is a text body message");
    
    // HTML Body
    $mailer->setHtmlBody("This is an <b>HTML</b> body message. <br> You can use html tags.");

    This is my Utility function, which can probably be improved (I wrote it several years ago), but it still works on the v11, I have not tested it in v12 yet but see no reason it should stop working, at least for now.

    <?php
      //Function to send Email message
      //one email per recipient
    
    function sendEmail($ToEmailAdd, $FromEmailAdd, $FromEmailName, $EmailSubject, $EmailBody) {
      global $sugar_config;
      require_once ('modules/Emails/Email.php');
      if(is_array($ToEmailAdd)){
        $To = $ToEmailAdd;
      }else{
        $To = explode(';',$ToEmailAdd);
      }
      foreach ($To as $to_addr){
        if (filter_var($to_addr, FILTER_VALIDATE_EMAIL)){
          try{
            $phpMailer = MailerFactory::getSystemDefaultMailer();
            $mailTransmissionProtocol = $phpMailer->getMailTransmissionProtocol();
            $FromEmailIdentity = new EmailIdentity($FromEmailAdd, $FromEmailName);
            $header_array = array(
              'From'=>$FromEmailIdentity,
              'ReplyTo'=>'',
              'Sender'=>$FromEmailIdentity, //mandatory
              'Subject'=>$EmailSubject,
            );
            $phpMailer->constructHeaders($header_array);
            $phpMailer->addRecipientsTo(new EmailIdentity($to_addr, $to_addr));
            $phpMailer->setHtmlBody($EmailBody);
            $phpMailer->send();
          }catch(MailerException $me) {
            $message = $me->getMessage();
            $GLOBALS["log"]->fatal(
              "SendEmail: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})"
            );
            return($message);
          }
        }else{
          $message = 'BAD EMAIL ADDRESS To: ' . $to_addr;
          return($message);
        }
      }
      return;
    }
    ?>
    

    Francesca