How to embed image in HTML email template?

泪湿孤枕 提交于 2020-12-08 04:05:51

问题


I have created an Email template using HTML and inline style from scratch. Now I need to add some images, at this point it's not possible to use url because it is not hosted. I tried using base64 encoding, it worked in Apple mail client, but the images are not rendering in Gmail. Is there any way to embed image in html supported by all email clients?


回答1:


Host the Image publicly in Google Drive by sharing the link 'public on the Web' or 'anyone with the link'. Then use this link http://drive.google.com/uc?export=view&id=FILE_ID to get direct access to the image. You should replace the FILE_ID with actual id from Google Drive link.

Example :

Google Drive Link : https://drive.google.com/open?id=0B7RYx63s2PFqam9PWVFrcXc1RU

Generated Link : http://drive.google.com/uc?export=view&id=0B7RYx63s2PFqam9PWVFrcXc1RU

Now you can use this link in your template.




回答2:


Base64 has very limited support. Generally speaking it is not advised to use it. You can find information about base64 encoding support in this tutorial. It may help to decide if the supported client list is enough or not in your case.

Embedding images in the email is possible by sending them along with the email and reference the sent images with the img tag. A good starter reading for this method is Campaignmonitor’s “Embedding images revisited“ blog post.

The best solution is to host the images with a service provider, which is fast and maintained. If you use Github, you can also serve images (or any other content) from the GH-Pages branch of a repository.



来源:https://stackoverflow.com/questions/43245813/how-to-embed-image-in-html-email-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!