Create email content in Apex in Salesforce, but send through Marketo

Anonymous
Not applicable

Create email content in Apex in Salesforce, but send through Marketo

We are looking to run some automation to send emails for our renewal orders. These objects are way too deep for Marketo so see confidently and there's several checks and balances that should be done prior to sending the emails.

What I'd like to do is have a Salesforce Batch job create the email content, a PDF attachment blob and ask marketo to email that to a number of people at the same time. All via the API. 

This would be very similar to the approach found here, but I'd need multiple recipients on the same email and also be able to include attachments. 

Anyone done this? Anyone have an Apex class started that can serve as a framework for getting started with the Marketo REST API?
Tags (1)
5 REPLIES 5
Anonymous
Not applicable

Re: Create email content in Apex in Salesforce, but send through Marketo

I am not sure if this will help since you are looking for REST API code, but I found this Apex class code for the Marketo SOAP API:
https://github.com/abhinavguptas/apex-marketo-soap-api-helper/blob/master/classes/MarketoClient.cls
Anonymous
Not applicable

Re: Create email content in Apex in Salesforce, but send through Marketo

This blog post might help too:
http://www.tgerm.com/2011/08/apex-marketo-soap-api-wsdl.html
Edward_Unthank_
Level 10

Re: Create email content in Apex in Salesforce, but send through Marketo

Hey Scott!

A few complications here, but not dealbreakers:
  • Multiple recipients on the same email (i.e., CCing) isn't possible through Marketo. 
  • Native attachments in Marketo aren't possible. 

The way you'd be able to edit Marketo emails is through editing program tokens (that example link) or lead tokens (any SFDC custom fields). These tokens show up in the actual body of the email (not the head), so adding additional encoding in the head or headers won't work (aka what you'd need to encode actual attachments). 

The normal workaround for attachments is to upload the files and then just provide a link within the email to the attachment. I'd say that's a generally-acceptable workaround, so long as your URLs uploaded aren't possible to be backward-engineered—so people can't go from arrowpointe.com/etumos-invoice.pdf to arrowpointe.com/google-invoice.pdf. 

Workaround to Do This

Instead of program tokens, this kind of specificity might work better with SFDC custom fields that have the email content within them. This is because you're looking at content specific to individuals, not specific to programs. You can have a Marketo email which contains {{lead.Dev - Temporary: Email Content}} as the body, and keep HTML (including the link to the attachment) within that field. SFDC can update that custom field as applicable, and then run a Request Campaign API call to fire off the email through Marketo based on whatever workflow rules you design.

If you're using tokens like this, with HTML inside them, be prepared for the Text-Only version of the email to be rather ugly—Marketo doesn't strip Text Tokens of their HTML when sending them as Text-Only, so people on bad internet connections get a bunch of plain-text HTML code in their email.

(Also, for whichever SFDC custom field you use for this approach, I'd throw a filter on the API-requestable smart campaign to say "Dev - Temporary: Email Content" is not empty as a safety.)

Another option would be to have a Custom Object with this content, and use that Custom Object content in the email (e.g., through Velocity scripting). Warning, though: the only way to get SFDC Custom Objects accessible within Marketo is to have Marketo's Professional Services custom-code it up for you. I haven't done it before, but I would be surprised if you could get this done for less than $1k.

Cheers,

Edward Unthank | Founder, Etumos

Anonymous
Not applicable

Re: Create email content in Apex in Salesforce, but send through Marketo

I can workaround the attachments limitations, but that's a bummer about the CCs. For this use case, it's a renewal email and it's nice for all the recipients to know whose on it. I'm really trying to use Marketo as a transactional email system in this use case, like Mandrill or similar. Apparently, it's not really meant for that. The benefits of email tracking and deliverability will likely outweigh the negatives, though. 

I'm going to work with the Request Campaign via tokens for my testing. My email template is almost entirely in Marketo and I am trying to just use tokens to throw in text values like Expiration Date and a URL to click for the order. 

Suppose I have a number of contact records in Salesforce, I want to send an email to. Sounds like I'd..
  1. Get the Marketo lead IDs using this method and filter by sfdcContactID since the Marketo Lead IDs are not synched to Salesforce by default.
  2. Request Campaign using this method passing in the lead IDs and tokens
  3. Validate
As for the marketo class that was posted earlier, that's a SOAP API one, not a REST API one. I actually was able to communicate with the Marketo REST API pretty easily so am all good with that side of it.
Edward_Unthank_
Level 10

Re: Create email content in Apex in Salesforce, but send through Marketo

If you were looking to instill some mutual-visibility and mutual-accountability, you could have a lead token or program token with the recipients' names concatenated. That'd give you the psychological benefits of accountability while everyone else might assume BCCing. Something like: "Dear {{lead.Dev - Temporary_Recipients:default=Bob Smith/Scott H/Edward Unthank}},". That's very possibly overkill, but it'd be an interesting test to see if that increases renewal rate or the appropriate conversion rate (responses per account, for example). 


- Edward