Tokenized mailto link in landing page? | Community
Skip to main content
Level 3
March 27, 2025
Solved

Tokenized mailto link in landing page?

  • March 27, 2025
  • 2 replies
  • 1014 views

Hi - not sure if this is possible, but I'd like to have a mailto link open up from a landing page and have that link populate the send to email address from the {{lead.Lead Owner Email Address}}. 

 

Basically the call to action is contact your rep, and by clicking the link it opens an email addressed to the record owner. 

 

Is this possible?

Best answer by SanfordWhiteman

Of course. But you have to use the proper encoding, so don’t put the token directly into the href.  Use the function from here to output into a <datalist> first and read it out:

<datalist class="mktoTokens"> <option label="lead.Email Address">{{lead.Lead Owner Email Address}}</option> </datalist> <a id="contact-rep">Contact your rep</a> <script> function getExportedMktoTokens(tokenLabels){ const stor = "datalist.mktoTokens option[label]"; const options = Array.from(document.querySelectorAll(stor)); const ignoreCaseComparator = Intl.Collator(undefined, { sensitivity: "accent" }); let results = []; for( const name of [tokenLabels].flat() ){ const value = options.find( option => ignoreCaseComparator.compare(option.label, name) === 0 )?.value; results.push(value ?? null); } return Array.isArray(tokenLabels) ? results : results[0]; } let leadEmailAddress = getExportedMktoTokens("lead.Email Address"); let contactRepLink = document.querySelector("#contact-rep"); contactRepLink.href = "mailto:" + encodeURIComponent(leadEmailAddress); </script>

 

2 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
March 27, 2025

Of course. But you have to use the proper encoding, so don’t put the token directly into the href.  Use the function from here to output into a <datalist> first and read it out:

<datalist class="mktoTokens"> <option label="lead.Email Address">{{lead.Lead Owner Email Address}}</option> </datalist> <a id="contact-rep">Contact your rep</a> <script> function getExportedMktoTokens(tokenLabels){ const stor = "datalist.mktoTokens option[label]"; const options = Array.from(document.querySelectorAll(stor)); const ignoreCaseComparator = Intl.Collator(undefined, { sensitivity: "accent" }); let results = []; for( const name of [tokenLabels].flat() ){ const value = options.find( option => ignoreCaseComparator.compare(option.label, name) === 0 )?.value; results.push(value ?? null); } return Array.isArray(tokenLabels) ? results : results[0]; } let leadEmailAddress = getExportedMktoTokens("lead.Email Address"); let contactRepLink = document.querySelector("#contact-rep"); contactRepLink.href = "mailto:" + encodeURIComponent(leadEmailAddress); </script>

 

Jroscoe-3Author
Level 3
April 4, 2025

Thanks for the suggestion. Turns out since we use Knak, I was just able to add the token to the button link and it worked. 

Great point on needing to send the email through Marketo as that wasn't originally planned. 

 

SanfordWhiteman
Level 10
April 4, 2025

Nope, that’s still wrong. Again, because the token isn’t URL-encoded, there are cases where the link will not behave as expected. This is the case for all links in Marketo, whether written by Knak or not.

Level 2
March 28, 2025

Yes, this is possible—as long as the person viewing the landing page is a known lead.

 

You can use a mailto: link like this:

mailto:{{lead.Lead Owner Email Address}}?subject=Let’s%20Connect&body=Hi%20there,%20I’d%20like%20to%20get%20in%20touch...

 

This will open the user’s email client and pre-fill the “To” field with the lead owner’s email, as long as Marketo can resolve the token at the time of page load.

 

Important:

This only works if the lead is known—meaning they’ve previously filled out a form or clicked through from a Marketo email, so their cookie is associated. If the lead is anonymous or the Lead Owner Email Address field is empty, the token won’t resolve, and the link will break or appear blank.

 

If you’re worried about unknown visitors, consider linking to a general contact form or rep directory as a fallback.

SanfordWhiteman
Level 10
March 28, 2025

@justinmc10 you can’t output the raw token like that, as I mentioned.

 

You must use the method in my post (output in <datalist>, read it from there, and URL-encode), because lead tokens are not URL-encoded and the mailto: may include characters that require URL-encoding.