4

My situation:
I'm sending html emails successfully. Styles, fonts and most of the images are shown as planned.

But some images from product previews became broken by google mail proxy scripts. There are around 6 images per email with 100x100px size each. Around 10% of them become broken - as no image at all at source (because + symbol appear in the address).

Checking code is helping me to only guess the reason, but not to fully fix it for me.

My src, that I send in email:

<img src="http://www.example.com/for_email/products_images/690/690xxxxxxx.jpg">

Google Mail changes it when showing to user to:

<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_email/products_images/690/690xxxxxxx.jpg">

And all works good, but in 10% I have these broken links:

<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_e+mail/products_images/690/690xxxxxxx.jpg">
<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_email/products_images/690/690xxx+xxxx.jpg">
<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_email/products_images/690/690xxxxxxx.j+pg">

Look at these pluses:

/for_e+mail/products_images/690/690xxxxxxx.jpg
/for_email/products_images/690/690xxx+xxxx.jpg
/for_email/products_images/690/690xxxxxxx.j+pg

What I try to fix it:

  1. Redirect. In adresses like this /for_email/products_images/690/690xxxxxxx.j+pg I just redirect to /for_email/products_images/690/690xxxxxxx.jpg after removing +. But it is not the solution for errors like /for_email/products_images/690/690xxx+xxxx.jpg because nginx work with such files and I will not change it for such minor reason.

  2. Less length. To fix this I also change images of names. Previously it was md5 hash like this.

    7c6a78c6ac5a6c56ac56a5c67ac5a6c57a65c67ac567a.jpg
    

    And now it is

    6657435previmg.jpg
    

    It helps to lower percentage of broken link to half, but not completely.

I have this problem for pretty much long time ago: around half year and occasionally try to solve it when have some spare time. Googling is still not helping me, I hope you do so.

I send it via PHP on 1C-Bitrix, but I don't think it matters (but not totally sure).

Felix Edelmann
  • 4,959
  • 3
  • 28
  • 34
A. Denis
  • 562
  • 7
  • 15
  • Have you tried to give the images shorter names to see if Gmail still appends it with a `+`? Am not sure but I feel Gmail might be trying to fight off spammers and others are getting affected as well. – Syfer Mar 19 '18 at 01:21
  • I make file with less length from md5 string to id of product. It helps but little. But I also can make path shorter with **/for_email/products_images/** to something like that: **/prdimgs/** – A. Denis Mar 19 '18 at 06:19
  • I meant the file name for the images. Gmail might be thinking its spam or has a limit to how much it can read in the proxy url – Syfer Mar 19 '18 at 06:22
  • Have you looked at the encoded mail that your mail server sends out? In other words that what GMail actually receives? Simply send the same mail, using exactly the same method, to one of your own mailboxes, and use a tool to inspect the complete mail source. The reason I say this is because GMail usually inserts plus-signs when there's a space in the URL. You have to be absolutely sure it's not your end inserting them. Just looking at what you intent to send is not enough in this case. – KIKO Software Mar 19 '18 at 08:32
  • @kiko-software, you are right. In other mail servers also spaces, just in different places. Thank you. Please make your comment as answer, so I will be able to accept it and close. – A. Denis Mar 19 '18 at 13:10
  • @A.Denis: It was a guess, that's why I made it a comment, but luckily it was actually what the problem was. I've turned my comment into a real answer. – KIKO Software Mar 19 '18 at 13:19

2 Answers2

1

Have you looked at the encoded mail that your mail server sends out?

In other words that what GMail actually receives? Simply send the same mail, using exactly the same method, to one of your own mailboxes, and use a tool to inspect the complete mail source.

The reason I say this is because GMail usually inserts plus-signs when there's a space in the URL.

You have to be absolutely sure it's not your end inserting them. Just looking at what you intent to send is not enough in this case.

I can only guess why spaces would appear in your output. It all depends on how you send emails. Usually it is caused by a conversion or encoding/decoding.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
0

Thanks to @KIKO Software and his answer I found what was the problem!

Table of products was added in one long HTML string.

And my email server split this string with \n symbols before sending. This spliting can be anywhere: in the middle of any word (word will be broken); any style (styles are broken); and even urls to src images (broken images).

Solution is simple: I just add "\n\r" everywhere in this table of products and all is fine now.

A. Denis
  • 562
  • 7
  • 15
  • Adding "\n\r" in your HTML code will work, but you've got to think about this every time you create a new HTML email. Other people have struggled with this and the solution is to encode the HTML part of the message in Base64. Then it doesn't matter what the HTML looks like. See: https://ctrlq.org/code/19840-base64-encoded-email Be careful with MIME encoding, it's easy to get it wrong. Alternatively, use something like PHPMailer, it encodes the mail for you: https://github.com/PHPMailer/PHPMailer – KIKO Software Mar 22 '18 at 08:43
  • Thanks, I will checki it. – A. Denis Mar 22 '18 at 10:55