> For the complete documentation index, see [llms.txt](https://docs.thewalletcrew.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.thewalletcrew.io/connectors/email-provider/salesforce-marketing-cloud.md).

# Salesforce Marketing Cloud as email sender

Configure The Wallet Crew to send its transactional emails through Salesforce Marketing Cloud, with a tenant script, instead of the default email provider.

Use this page to have The Wallet Crew send **transactional emails** through **Salesforce Marketing Cloud**, while Salesforce Marketing Cloud remains the place where the brand manages email assets, tracking, and reporting.

This is a reference script for the **script email provider**, not a native provider type. The Wallet Crew triggers the send. The tenant script forwards the event to Salesforce Marketing Cloud.

{% hint style="info" %}
**Which page do I need?** Use this page when The Wallet Crew sends the email through Salesforce Marketing Cloud. To send pass links from Email Studio or to update passes from Journey Builder, see [Salesforce Marketing Cloud in Marketing automation](https://docs.thewalletcrew.io/connectors/marketing-automation/salesforce-marketing-cloud.md).
{% endhint %}

## How it works

The Wallet Crew calls the tenant implementation of `runtime.scriptable.emailEngine.SendEmail`. That script then calls the Salesforce Marketing Cloud REST API to fire an event (using an `EventDefinitionKey`). Salesforce Marketing Cloud uses that event payload to render and send the email.

This model avoids duplicating templates. Salesforce Marketing Cloud owns the template and the email HTML, so the marketing team can iterate on it without shipping The Wallet Crew changes. The Wallet Crew only sends the variables Salesforce Marketing Cloud needs, like the title, the pass download URL and the localized CTA label.

When the script provider is not set up yet, start with [EmailSender extensibility](https://docs.thewalletcrew.io/connectors/custom-connector/emailsender-extensibility.md).

## Setup required in Salesforce Marketing Cloud

In Salesforce Marketing Cloud, create an API-triggered entry point and the associated email content.

1. Create an **Installed Package** that can call REST APIs, and keep the **Client Id** and **Client Secret**.
2. Create the send asset to trigger by API (typically a journey entry event or an API event), then copy its `EventDefinitionKey`.
3. Make sure the Salesforce Marketing Cloud email template expects the same variable names sent in `Data`.
4. Have a stable identifier in The Wallet Crew email payload (example: `id.customerId`) to generate the pass URL.

{% hint style="info" %}
Salesforce Marketing Cloud setup varies by account configuration and feature set. Keep the payload contract stable: the field names in `Data` should match what the Salesforce Marketing Cloud asset expects.
{% endhint %}

## Enable Salesforce Marketing Cloud in The Wallet Crew

Select **Custom** in **Settings → General → Email provider**, as described in [EmailSender extensibility](https://docs.thewalletcrew.io/connectors/custom-connector/emailsender-extensibility.md#enable-the-script-email-provider).

## Script example (trigger a Salesforce Marketing Cloud event)

This example triggers a Salesforce Marketing Cloud event using the REST endpoint `interaction/v1/events`. It sends a localized title, a localized CTA label, and a pass URL of The Wallet Crew built from a customer identifier. Store the credentials as tenant secrets and load them at runtime with `getSecret`. Do not hardcode credentials in scripts.

{% hint style="warning" %}
This implementation delegates rendering to Salesforce Marketing Cloud. The Wallet Crew `buildEmail()` callback is intentionally not used.
{% endhint %}

The sample builds an unsigned pass URL: see [Pass links in emails](https://docs.thewalletcrew.io/connectors/custom-connector/emailsender-extensibility.md#pass-links-in-emails).

{% code title="Salesforce Marketing Cloud example (SendEmail implementation)" %}

```javascript
import { getSecret } from "twc/secrets";

const CUSTOM_DOMAIN = "wallet.brand.com";
const TENANTID = "brand";
const SFMC_SUBDOMAIN = "<your-subdomain>";

async function sendEmail(recipient, emailTemplate, data, cultures, buildEmail){

  const customerId = data["id.customerId"];
  const url = `https://${CUSTOM_DOMAIN}/${TENANTID}/pass?id.customerId=${encodeURIComponent(customerId)}`;

  const locales = {
    "en": {
      title: "Your account is ready: add your pass to Wallet",
      label: "Add to Wallet"
    },
    "fr": {
      title: "Votre compte est prêt : ajoutez votre pass au Wallet",
      label: "Ajouter au Wallet"
    }
  };

  const locale = locales[cultures[0]];

  const response = await fetch(`https://${SFMC_SUBDOMAIN}.rest.marketingcloudapis.com/interaction/v1/events`,  {
    Method : "POST", 
    Authentication : {
        mode : 'OAuth2.0', 
        grantType : 'clientCredentials',
        accessTokenUrl : `https://${SFMC_SUBDOMAIN}.auth.marketingcloudapis.com/v2/token`, 
        sendCredentialsAsFormParams: true,
        clientId: await getSecret('SFMC-CLIENTID'), 
        clientSecret : await getSecret('SFMC-CLIENTSECRET')
    }, 
    Headers: {
      "Content-Type": "application/json",
    },
    Body: {
      "ContactKey": recipient,
      "EventDefinitionKey": "<EVENT_DEFINITION_KEY>",
      "Data": {
          "SubscriberKey": recipient,
          "EmailAddress": recipient,
          "Title": locale.title,
          "Url": url,
          "LabelCTA": locale.label,
      }
    }
  });
  const responseData = JSON.parse(response.ResponseText); 
  if(!responseData?.eventInstanceId){
    throw new Error(`error while sending custom email status : ${response.StatusCode} - content : ${response.ResponseText}`)
  }
}

export default function(context) {
  context.register('runtime.scriptable.emailEngine', {
    SendEmail: sendEmail 
  })
}
```

{% endcode %}

## What to validate

Trigger a real transactional email, then validate end-to-end:

* The Wallet Crew calls the script without errors.
* The Salesforce Marketing Cloud API call returns an `eventInstanceId`.
* Salesforce Marketing Cloud renders the email with `Title`, `Url`, and `LabelCTA`.
* The CTA opens The Wallet Crew URL and the pass can be installed.

## Troubleshooting

If sends fail, isolate the problem in this order:

* **OAuth fails (401/403)**: client id/secret is wrong, revoked, or the installed package lacks API access.
* **No `eventInstanceId`**: the `EventDefinitionKey` is invalid, unpublished, or the payload schema is rejected.
* **Empty variables in the email**: the Salesforce Marketing Cloud template expects different field names than those sent in `Data`.
* **Wrong language**: `cultures[0]` does not match the locale map. Add a fallback (example: default to `en`).

## FAQ

<details>

<summary><strong>Can The Wallet Crew templates and <code>buildEmail()</code> still be used?</strong></summary>

Yes, but it becomes a different strategy. In that model, The Wallet Crew renders `Subject` and `Body`, and Salesforce Marketing Cloud is only used as a delivery gateway. In that case, align the Salesforce Marketing Cloud asset to accept rendered HTML and avoid double-templating.

</details>

<details>

<summary><strong>What should be used as <code>ContactKey</code>?</strong></summary>

Use a stable Salesforce Marketing Cloud contact identifier. Many brands use the email address, but a CRM id also works when it is the Salesforce Marketing Cloud contact key strategy. Keep it consistent with how the journey or asset resolves recipients.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.thewalletcrew.io/connectors/email-provider/salesforce-marketing-cloud.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
