Answers.Body: <p>I figured this out.</p>
  <p>We use the Drupal Require Login plugin.  Require Login protects all URLs and forces a user login if there is no session, except for URLs that you specifically exclude.</p>
  <p>I guess Drupal's /sites/default/files/ path must be excluded from requiring a login by default, because we don't have that path listed as excluded, but yet images load fine from there with no login required.</p>
  <p>However, all CiviCRM paths need to be explicitly stated.  So that's why the  /civicrm/mosaico/img path was breaking.</p>
  <p>Further, it worked for me when I tested the URL directly, but I had a logged in session in that browser.  When I tried on a private browser window, it failed.  That's why Google's image retriever wasn't able to get the image.</p>
  <p>Hopefully this helps someone else!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-20T17:03:46.260Z
Answers.LastActivityDate: 2024-08-20T17:03:46.260Z
Answers.UserDisplayName: richardsplayground
Body: <p>I'm wondering if anyone has seen this behaviour before.</p>
  <p>If I compose a message in Mosaico that has images in the message...</p>
  <ul>
  <li>When I send that email via CiviMail it displays fine.</li>
  <li>When I send the email using the Chasse plugin as part of a drip campaign, it displays fine.</li>
  <li>When I send the email using a CiviRule, the images do not display and just show broken image.</li>
  <li>When I send the email using &quot;Contacts -&gt; Send an email&quot; (to a single test contact), the images display well.</li>
  </ul>
  <p>So the ONLY use case where the images are not displaying is when using CiviRule to trigger the sending of the email.</p>
  <p>Inspecting the message source, what I find is that in the cases where the images are displayed, a static image path is used in the img src tag. But when a Mosaico-generated message is sent via CiviRules, a path with a query is used instead.  Yet the very same message sent via other mechanisms uses the static image path.</p>
  <h2>Message sent via CiviMail or Chasse or Send Email to Contact</h2>
  <p>Here is what the image source URL looks like:</p>
  <pre><code>https://ci3.googleusercontent.com/meips/ADKq_NZKIttdMfiIYzHB1AXasUB6QoFqq1Tc-4aP1vF-hp1y1yTM_lQatQuc5BPA8nP6Lu78znIY3DLAzNhlUW-3XsU-rBtDm89KVijefHnjiHc82xT24sSyofz2RE6KpP2Iu4A_dquQezLZ-94yyabD2YoWwDypW_pDtsxgXVbvLKqX7MxzKaqfgd5BxZn6ilIm2NAC8MrKt2huZ3dMUQ0Rbjqe4R_51SCV_HDAiBoDkbCcYnRV4CogovsIUoPYagzNMqxo=s0-d-e1-ft#https://home.societyoftheguardiansoftheflame.com/sites/default/files/civicrm/persist/contribute/images/uploads/static/raphael_header_3_de7832e383993ea19f7fb9ab715b2328.jpg
  </code></pre>
  <p>Ignoring the Google bits, what we see is the URL is rendered as:</p>
  <pre><code>https://home.societyoftheguardiansoftheflame.com/sites/default/files/civicrm/persist/contribute/images/uploads/static/raphael_header_3_de7832e383993ea19f7fb9ab715b2328.jpg
  </code></pre>
  <h2>Sent with CiviRules</h2>
  <p>But when sent with CiviRules, the URL looks like this:</p>
  <pre><code>https://ci3.googleusercontent.com/meips/ADKq_NbGcjkFq1FodHytsuVPPm3NZl6DQj50fSqmVn141ZvfbGUlx6fb_8T0hIhzQyUX9ZHL40Ba_jfC6MjJO_RZVKaIx99TP96BYYxGUA5etEnLtwBLzl1ibtaaHydWyDhQoBHEFepa_XEj0JUPIMCepZk4D8iftlsJkOfwmS9wB78ZCnXE_Zteaj-27s2-3XdVUsgb-99NY82aWtRWGgvaSXTBng4rmt5Bx9_N-WjdZ20qK3lT5yAOn1axPvy9zsPlxDZoSgtXvRPQPhyDc5kx-5ySUIt3ufJVpBwuHsvfQpYSTL3JKczWdNEM5KvXEzkACRu5OMIPpiE0KeX7Yk1xqTAl-gBtmUsTM0U7V4BNx3RxlX9HfB4kcj-OJUHe9Y-Fr_NVxlqtWOOEv3aP3_-QdoIbTAJ1RuURcQBd_g=s0-d-e1-ft#https://home.societyoftheguardiansoftheflame.com/civicrm/mosaico/img?src=https%3A%2F%2Fhome.societyoftheguardiansoftheflame.com%2Fsites%2Fdefault%2Ffiles%2Fcivicrm%2Fpersist%2Fcontribute%2Fimages%2Fuploads%2Fkb_email_header_c33635df2dd05033d3e8b5b293dade5d.png&amp;method=resize&amp;params=570%2Cnull
  </code></pre>
  <p>and again stripping out the Google bits, we get this URL:</p>
  <pre><code>https://home.societyoftheguardiansoftheflame.com/civicrm/mosaico/img?src=https%3A%2F%2Fhome.societyoftheguardiansoftheflame.com%2Fsites%2Fdefault%2Ffiles%2Fcivicrm%2Fpersist%2Fcontribute%2Fimages%2Fuploads%2Fkb_email_header_c33635df2dd05033d3e8b5b293dade5d.png&amp;method=resize&amp;params=570%2Cnull
  </code></pre>
  <h2>Observations</h2>
  <p>When sent via CiviRules, the img src tag becomes</p>
  <pre><code>/civicrm/mosaico/img?src=URL-ENCODED-PATH 
  </code></pre>
  <p>rather than the static image path.  Even though the very same message sent via CiviMail or Send E-mail to Contact just encodes the static path.</p>
  <p>When I try to access the URL /civicrm/mosaico/image?src=PATH, I do actually get the image.</p>
  <p>But when I try to access the Google-ified URL, I get a 404 error.</p>
  <p>Has anyone else run into this?  Options to solve?</p>
  <p>This seems super specific to CiviRules and I suppose the email send API but beyond that I'm lost.</p>
  <p>We have</p>
  <ul>
  <li>CiviCRM 5.76</li>
  <li>Drupal 7.101</li>
  <li>Mosaico 3.5.1709296836</li>
  <li>Mosaico Message Template plugin 0.2</li>
  </ul>
  
Tags: <civirules>
Title: Images break when sending message template via CiviRule but works when sending via CiviMail
ThreadText: # Images break when sending message template via CiviRule but works when sending via CiviMail
  
  (Asked by: username_0 on 2024-08-19)
  
  I'm wondering if anyone has seen this behaviour before.
  If I compose a message in Mosaico that has images in the message...
  
  When I send that email via CiviMail it displays fine.
  When I send the email using the Chasse plugin as part of a drip campaign, it displays fine.
  When I send the email using a CiviRule, the images do not display and just show broken image.
  When I send the email using "Contacts -> Send an email" (to a single test contact), the images display well.
  
  So the ONLY use case where the images are not displaying is when using CiviRule to trigger the sending of the email.
  Inspecting the message source, what I find is that in the cases where the images are displayed, a static image path is used in the img src tag. But when a Mosaico-generated message is sent via CiviRules, a path with a query is used instead.  Yet the very same message sent via other mechanisms uses the static image path.
  Message sent via CiviMail or Chasse or Send Email to Contact
  Here is what the image source URL looks like:
  https://ci3.googleusercontent.com/meips/ADKq_NZKIttdMfiIYzHB1AXasUB6QoFqq1Tc-4aP1vF-hp1y1yTM_lQatQuc5BPA8nP6Lu78znIY3DLAzNhlUW-3XsU-rBtDm89KVijefHnjiHc82xT24sSyofz2RE6KpP2Iu4A_dquQezLZ-94yyabD2YoWwDypW_pDtsxgXVbvLKqX7MxzKaqfgd5BxZn6ilIm2NAC8MrKt2huZ3dMUQ0Rbjqe4R_51SCV_HDAiBoDkbCcYnRV4CogovsIUoPYagzNMqxo=s0-d-e1-ft#https://home.societyoftheguardiansoftheflame.com/sites/default/files/civicrm/persist/contribute/images/uploads/static/raphael_header_3_de7832e383993ea19f7fb9ab715b2328.jpg
  
  Ignoring the Google bits, what we see is the URL is rendered as:
  https://home.societyoftheguardiansoftheflame.com/sites/default/files/civicrm/persist/contribute/images/uploads/static/raphael_header_3_de7832e383993ea19f7fb9ab715b2328.jpg
  
  Sent with CiviRules
  But when sent with CiviRules, the URL looks like this:
  https://ci3.googleusercontent.com/meips/ADKq_NbGcjkFq1FodHytsuVPPm3NZl6DQj50fSqmVn141ZvfbGUlx6fb_8T0hIhzQyUX9ZHL40Ba_jfC6MjJO_RZVKaIx99TP96BYYxGUA5etEnLtwBLzl1ibtaaHydWyDhQoBHEFepa_XEj0JUPIMCepZk4D8iftlsJkOfwmS9wB78ZCnXE_Zteaj-27s2-3XdVUsgb-99NY82aWtRWGgvaSXTBng4rmt5Bx9_N-WjdZ20qK3lT5yAOn1axPvy9zsPlxDZoSgtXvRPQPhyDc5kx-5ySUIt3ufJVpBwuHsvfQpYSTL3JKczWdNEM5KvXEzkACRu5OMIPpiE0KeX7Yk1xqTAl-gBtmUsTM0U7V4BNx3RxlX9HfB4kcj-OJUHe9Y-Fr_NVxlqtWOOEv3aP3_-QdoIbTAJ1RuURcQBd_g=s0-d-e1-ft#https://home.societyoftheguardiansoftheflame.com/civicrm/mosaico/img?src=https%3A%2F%2Fhome.societyoftheguardiansoftheflame.com%2Fsites%2Fdefault%2Ffiles%2Fcivicrm%2Fpersist%2Fcontribute%2Fimages%2Fuploads%2Fkb_email_header_c33635df2dd05033d3e8b5b293dade5d.png&method=resize&params=570%2Cnull
  
  and again stripping out the Google bits, we get this URL:
  https://home.societyoftheguardiansoftheflame.com/civicrm/mosaico/img?src=https%3A%2F%2Fhome.societyoftheguardiansoftheflame.com%2Fsites%2Fdefault%2Ffiles%2Fcivicrm%2Fpersist%2Fcontribute%2Fimages%2Fuploads%2Fkb_email_header_c33635df2dd05033d3e8b5b293dade5d.png&method=resize&params=570%2Cnull
  
  Observations
  When sent via CiviRules, the img src tag becomes
  /civicrm/mosaico/img?src=URL-ENCODED-PATH 
  
  rather than the static image path.  Even though the very same message sent via CiviMail or Send E-mail to Contact just encodes the static path.
  When I try to access the URL /civicrm/mosaico/image?src=PATH, I do actually get the image.
  But when I try to access the Google-ified URL, I get a 404 error.
  Has anyone else run into this?  Options to solve?
  This seems super specific to CiviRules and I suppose the email send API but beyond that I'm lost.
  We have
  
  CiviCRM 5.76
  Drupal 7.101
  Mosaico 3.5.1709296836
  Mosaico Message Template plugin 0.2
  
  **Tags:** civirules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-08-20. Score: 3
  
  I figured this out.
  
  We use the Drupal Require Login plugin. Require Login protects all URLs and forces a user login if there is no session, except for URLs that you specifically exclude.
  
  I guess Drupal's /sites/default/files/ path must be excluded from requiring a login by default, because we don't have that path listed as excluded, but yet images load fine from there with no login required.
  
  However, all CiviCRM paths need to be explicitly stated. So that's why the /civicrm/mosaico/img path was breaking.
  
  Further, it worked for me when I tested the URL directly, but I had a logged in session in that browser. When I tried on a private browser window, it failed. That's why Google's image retriever wasn't able to get the image.
  
  Hopefully this helps someone else!
  
  
  ---
  
  