Skip to content

Instantly share code, notes, and snippets.

@jrallison jrallison/attachments.markdown Secret
Last active Aug 1, 2019

Embed
What would you like to do?
How to send attachments with Customer.io transactional emails using our Ruby gem.

Assuming you have a transactional campaign with send_test as the trigger event:

$ customerio.track(2, "send_test", attachments: { "hello.txt" => "Hello world" })

This will attach a plain text document named hello.txt with a body of Hello world. You can also Base64 encode the body (if your sending a binary attachment or something a bit more complex than Hello world):

$ customerio.track(2, "send_test", attachments: { "hello.txt" => Base64.strict_encode64("Hello world") })

That's it, same end result. Note: strict encoding is important here.

This works great for .ics files as well:

$ invite_body = <<-BODY
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
METHOD:PUBLISH
BEGIN:VEVENT
ORGANIZER;CN=Handybook Team:MAILTO:team@handybook.com
UID:u2coh5g3bppo2d2o3t@google.com
CLASS:PUBLIC
SEQUENCE:0
STATUS:CONFIRMED
LOCATION;LANGUAGE=en-US:500 E 63rd st. Apt 17C  New York, NY 1006510065
DTSTAMP:20130416T190739Z
CREATED:20130416T190739Z
DTSTART:20130417T020000Z
DURATION:PT2H0M0S
SUMMARY:Handybook-Home Cleaning
DESCRIPTION:Home Cleaning
LAST-MODIFIED:20130416T190739Z
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
BODY
=> "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN\nMETHOD:PUBLISH\nBEGIN:VEVENT\nORGANIZER;CN=Handybook Team:MAILTO:team@handybook.com\nUID:u2coh5g3bppo2d2o3t@google.com\nCLASS:PUBLIC\nSEQUENCE:0\nSTATUS:CONFIRMED\nLOCATION;LANGUAGE=en-US:500 E 63rd st. Apt 17C  New York, NY 1006510065\nDTSTAMP:20130416T190739Z\nCREATED:20130416T190739Z\nDTSTART:20130417T020000Z\nDURATION:PT2H0M0S\nSUMMARY:Handybook-Home Cleaning\nDESCRIPTION:Home Cleaning\nLAST-MODIFIED:20130416T190739Z\nTRANSP:TRANSPARENT\nEND:VEVENT\nEND:VCALENDAR\n"

$ client.track(2, "send_test", attachments: { "invite.ics" => Base64.strict_encode64(invite_body) })

That call resulted in this in gmail:

gmail calendar invite

@helpcheck-zebba

This comment has been minimized.

Copy link

commented Aug 1, 2019

If you are curious: you can only posts events with a size of < 56,000 bytes.

@jrallison

This comment has been minimized.

Copy link
Owner Author

commented Aug 1, 2019

👋 @helpcheck-zebba

We've recently released the ability to support events up to 16MB in size!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.