For HTML Emails, How to embed images so users don't get a download prompt

杀马特。学长 韩版系。学妹 提交于 2020-01-04 11:06:09

问题


I'm working to create an HTML email which includes 2 images. Currently, I'm using tags to place the image in the email. Problem is when users get the email, it's asking the user to "click to download" for security reasons.

Is there a way to embed the image in the email, to avoid this issue?

I'm using Coldfusion to send the email.

Thanks


回答1:


I haven't tested if this works in e-mail clients, but if you encode the image as Base64 you can include it in the HTML, which avoids the issue of connecting to a remote server.

Here's how you can do this with CFML:

<cfset ImageFile = "/path/to/image.png" />
<cfset ImageInfo = "image/png;charset=utf-8;base64" />
<cfset ImageData = ToBase64( FileReadBinary( ImageFile ) , 'utf-8' ) />

<cfoutput>
    <img src="data:#ImageInfo#,#ImageData#" alt="my picture" />
</cfoutput>



回答2:


You can embed the image as an attachment using cfmailparam and link to the attachement instead of an external file.

http://www.bennadel.com/blog/61-CFMail-CFMAILPARAM-Used-to-Embed-Images-in-Email.htm




回答3:


I am fairly certain that is an email client issue and not the email/HTML you are putting together. I am unaware (and a quick Google didn't show) of any ways to get around this with HTML.

One possible solution may be to create a rich text email instead and embed the image in the RTF, not sure if that will get you around your issue or not.

Other thought is do you have to have the images in the email? You might be better of crafting the email format to not rely on the images for formatting/aesthetics but allow them to be included if the client displays them. Not sure who your target audience is but in my job we have to deal with users that are restricted to plain text email quite often.



来源:https://stackoverflow.com/questions/2828212/for-html-emails-how-to-embed-images-so-users-dont-get-a-download-prompt

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