salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.53k stars 2.09k forks source link

Campain Emails with embeded pictures #5662

Closed Lehnerr closed 5 years ago

Lehnerr commented 6 years ago

Issue

When I create Emailtemplates with Mozaik-Editor and load the images to the system. The pictures are not displayed in the sent email. grafik

Expected Behavior

The Pictures should be displayed.

Actual Behavior

Pictures are not displayed

Possible Fix

The problem is in the parsing of the Template. modules\EmailTemplates\EmailTemplate.php public function addDomainToRelativeImagesSrc() { global $sugar_config; $domain = $sugar_config['site_url'] . '/'; $ret = $this->body_html = preg_replace('/(<img src=")(public\/[^.]*.(jpg|jpeg|png|gif|bmp))(")/', "$1" . $domain . "$2$4", $this->body_html); return $ret; }

This is looking for <img src=" But in the template it is stored in following format: f; font-size: 14px;" alt="" src="public/d09e3294-aba0-ed22-a101-5ac37a64eada.jpg" data-mce-s

I changed th function to following and now it works: public function addDomainToRelativeImagesSrc() { global $sugar_config; $domain = $sugar_config['site_url'] . '/'; $ret = $this->body_html = preg_replace('/(<img src=")(public\/[^.].(jpg|jpeg|png|gif|bmp))(")/', "$1" . $domain . "$2$4", $this->body_html); $ret = $this->body_html = preg_replace('/( src=")(public\/[^.].(jpg|jpeg|png|gif|bmp))(")/', "$1" . $domain . "$2$4", $ret); return $ret; }

Pls fix it in Source

Steps to Reproduce

  1. Create Campaign 2.In the EmailTemplate upload a png file 3.Send the Test-Email

Context

Your Environment

ebogaard commented 6 years ago

I can confirm this is still happening in 7.8.17. We fixed it by changing the preg_replace to:

$ret = $this->body_html = preg_replace('/( src=&quot)(public\/.*(jpg|jpeg|png|gif|bmp))(&quot)/', "$1" . $domain . "$2$4", $this->body_html);

Quotes are html encoded in the source, so using an escaped quote in the regex won't do anything.

We found another strange 'functionality' with EmailTemplates: when adding/uploading images this way, the image is attached to the template as well. As in the EmailTemplate the image is referred to with it's URL, it seems to me attaching the image to the mail is a bit redundant.

pstevens71 commented 6 years ago

As a work around until this is fixed, what I've been doing is just adding a full url in the image source (it has to be different from the installation, or it will remove the site address and make it relational). So if your site is: https://mysite.com/public/...etc, edit the image in your editor and add http://mysite.com/ before the relational URL (notice its http, otherwise on save it will remove it and make it relational again). That way the images work with the full URL.

pstevens71 commented 6 years ago

I have a discussion going about this issue in the SuiteCRM forum.... here's what I've learned so far:

  1. The proposed fixes on Github don't work. (I tried them both).
  2. It's not a security issue or a site URL issue, I know this because .PNG files work. (and my permissions and site url are good).
  3. If you upload a .PNG file works no problem and sends email with proper embedded image.
  4. If you usea .JPG it shows in editor, but when you save it disappears and also does not send it in the email.
  5. .GIF files will not upload at all.
lazka commented 5 years ago

I've opened a PR for this: #7046

jfd118 commented 5 years ago

Hello SuiteCRM Developers,

According to the release notes of 7.11.3, the problem this thread discusses was fixed. github.com/salesagility/SuiteCRM/issues/5662

I just upgraded to 7.11.3 and conducted a test that seems to have failed. My process was:

1) Create a new email template using the Moziak email editor 2) Insert an image to into the template. Save the template. NOTE: when I upload the image I can resize the image amongst the text and the image appears while resizing. 3) I selected my email address from the "targets" list and the email editor pops up. 4) I select the template I just created containing the image. The template has a place holder for the image but image is not there. 5) Send the email to myself. 6) Receive email. Only a placeholder for the image is in the message. The image itself is not.

First off, my set up is: Debian 9 Package contents Apache 2.4.33 MySQL 5.7.22 OpenSSL 1.0.2o PHP 7.0.30 phpMyAdmin 4.8.1 SQLite 3.18.0 SuiteCRM 7.11.3

Thanks for your consideration,

jfd118

jfd118 commented 5 years ago

It turns out a colleague did substantial investigative work on our end to try to figure out why this is occurring. The problem is likely resolved (I have not tested it yet but he has) and his explanation to me is below.

"The original images were not being displayed because the https image URLs were using the host ip address rather than the fqdn (e.g. customer.mycompany.com). The SSL certificate was only valid for customer.mycompany.com, so the https image links were blocked by outlook, thunderbird, etc due to an invalid SSL certificate. In the past I have updated the site_url php variable with the fqdn, but it was reverting back to the ip address on any restart, update, etc. I did some searches on this issue and discovered that it is due to the bitnami startup configuration tool, which was overwriting our config.php with what IP address was currently being used by google for the VM. Since we are using a static IP and domain name, this can be disabled. Now that it is disabled I can set the site_url to the correct https://customer.mycompany.com and the images links will all be prefixed with the correct domain name and since these URLs have valid certificates, the images now show up as expected. Thinking back to my previous debugging of this issue, I am pretty sure I resolved this by setting the site_url to the fqdn, but I was unaware that it would be overwritten by bitnami. So we are now using a full HTTPS setup with redirection."

So, it appears the problem is with the behavior of the bitnami deployment rather than the software itself. I will test this next week and suspect that https://github.com/salesagility/SuiteCRM/issues/6968 will also be resolved.

SuiteBot commented 2 years ago

This issue has been mentioned on SuiteCRM. There might be relevant details there:

https://community.suitecrm.com/t/suite-crm-7-bild-in-email-template-einfugen-funktioniert-nicht-richtig/83735/2