2

I'm working on an app that creates customized images based on user inputs using canvas and I was wondering if it was possible to allow users to email themselves a copy of the final product in base64 or if I would have to convert it to .jpg or .png and then embed it as that.

Thanks.

4
  • 2
    What did you try and how did it turn out?
    – Dan Bracuk
    Mar 24, 2015 at 1:29
  • I tried using an <img> tag and it outputted the whole string ('<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOAAAAIiCAYAAAB...') and marked the email as spam. Mar 24, 2015 at 15:34
  • @JackPilowsky This link might be useful for you. sendgrid.com/blog/embedding-images-emails-facts
    – Pankaj
    Mar 25, 2015 at 5:33
  • @JackPilowsky - Code belongs in the question for better visibility. Not everyone reads the comments.
    – Leigh
    Apr 3, 2015 at 19:07

1 Answer 1

3

I'd suggest converting the Base64 to an image, writing to disk, and using cfmailparam to attach/inline it as well as automatically remove it from disk.

I have had nothing but issues trying to directly inline/attach base64 images to emails using cfmail. I have had partial success converting the base64 to an image object (using ImageReadBase64()) and then using the image object as the value of the cfmailparam content attribute and ommitting the file attribute, however the image comes through with inverted colors oddly enough.

On to some example code...

<cfsavecontent variable="mailContent">
...
<img src="cid:signature">
...
</cfsavecontent>

<cfset sigImage = ImageReadBase64(SIGNATURE_IMAGE_BASE64)> 
<cfimage source="#sigImage#" destination="tmpSigImage.png" action="write" overwrite="true">

<cfmail ...>
#mailContent#
<cfmailparam
    file="#ExpandPath('./tmpSigImage.png')#"
    contentid="signature"
    disposition="inline"
    remove="yes"
    />
</cfmail>
1
  • 1
    To whoever gave me an upvote and made my rep 666, well done :P. Now I just need to gain an up or down vote to free myself from this curse. Jan 30, 2018 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.