I am trying to get a QR Code image to display in an email. I have tried to apply solutions from similar questions here at SO but have not been able to get any variation of them to work. I don’t want to download it from the site.
in my user_mailer.rb:
def email_qrcode(from_whom, to_addy)
@from_whom = from_whom
@to_addy = to_addy
attachments["qrcode.png"] = File.read(Rails.root + "public/images/qrcode.png")
mail( :to => to_addy, :from => @from_whom.email, :subject => "QR Code" )
end
in my email_qrcode.html.erb:
<body>
<p>Here is the QR Code:</p>
<p><img src="cid:qrcode.png"></p>
</body>
The email content that is displayed:
Here is the QR Code: (followed by the little blue question mark indicating no image)
It is also included as an attachment, but having to double click it to open it defeats the convenience factor.
Thanks for your help.
UPDATE:
Good marketing is about removing every obstacle that you can to make it easier for the potential customer. The more times the QR code is displayed without having to find and click another link, the better the results will be. So, to be clear…
- The attachment is there. In some email clients web mail servers it will even display as an attachment below the email. However, many (maybe most… not sure) email clients and web mail servers will not display an attachment unless you click on them to open them… another click (obstacle).
- In addition, many clients and web mail servers will prevent the download and display of images without clicking on a link to approve display of the image. However, many of those clients and servers will NOT block an image that is embedded in the email. In other words putting in a link to download the image increases the likelihood of the display being blocked requiring a click (obstacle to potential customer) to open the image.
ANOTHER UPDATE: solution
user_mailer.rb:
attachments.inline["qrcode"] = {
:data => File.read("#{Rails.root.to_s + '/public/images/qrcode.png'}"),
:mime_type => "image/png",
:encoding => "base64"
}
email_qrcode.html.erb:
<%= image_tag( attachments['qrcode'].url, :id => 'qrcode' ) %>
In your
email_qrcodemethod, try changing:attachments.["qrcode.png"]to
attachments.inline["qrcode.png"].This should get you moving in the right direction.