简体   繁体   中英

Emails from rails with image on AWS's in paperclip, a very strange thing is happening

I am sending out emails from rails, in the emails are images. Those images are stored on AWS S3 via paperclip. The email gets built in the view and sent dynamically...

Are you with me so far? Great!

When the emails are received I would say approx one out of ten of the images have a slightly incorrect src="" tag which means the images arn't showing.

The problem with src attribute of the img tag is it has a "+" sign randomly inserted in it somewhere. This is about one out of ten images that don't work by the way. So the src attribute will look something like this in the source of the email...

http://s3.ama+zonaws.com/bucketname/attachments/ect...
http://s3.amazonaws.com/bu+cketname/attachments/ect...
http://s3.amazonaws.com/bucketname/attachm+ents/ect...

You see! Randome +'s. What could possibly be causing this to happen to the src string?

Cheers!

Edit:

His a sample of the code that's outputting the image,

<%= image_tag xxxxx.image.url(:thumb), :style => "display:block; padding:0; line-height:0;" %>

Pretty standard if you ask me.

Also to note I've checked the output html in the console and that doesn't have the +'s in the src.

...and I've tried it sending several different email providers (gmail, hotmail, me.com ect) and clients, the problem occurs on all of them.

I've encountered something similar before when sending email from a .NET application. I can't vouch this is the same issue since I don't know anything about the internal magic occurring here, but hope this helps.

SMTP has a line length limitation in the message stream, so if your message is too long, the SMTP server may break the line. I think the limitation is 1000 characters, but not all servers might implement the protocol correctly.

In some cases the server also inserts a character at the line break, most commonly ! or blank . If the blank character is inserted inside the image URL, the client software would likely encode it to + .

Try inserting cr+lf line breaks after each image, and see if the issue improves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM