sendEmailCampaign
This method sends a bulk email campaign using a prepared campaign request. It processes a bulk request that has been created using the prepareEmailCampaign method.
Prerequisites
Before using this method, make sure you have:
Recipients granted access with bulk processing: When calling
grantAccesson the Data Protector SDK, recipients must setallowBulk: truePrepared the campaign: Use
prepareEmailCampaignto create the bulk request that will be passed to this method
Usage
import { IExecWeb3mail } from '@iexec/web3mail';
import { type PrepareEmailCampaignResponse } from '@iexec/web3mail';
import { type SendEmailCampaignResponse } from '@iexec/web3mail';
const web3Provider = window.ethereum;
const web3mail = new IExecWeb3mail(web3Provider);
// Step 1: Fetch contacts and prepare the campaign
const contacts = await web3mail.fetchMyContacts({ bulkOnly: true });
const grantedAccessArray = contacts.map((contact) => contact.grantedAccess);
const emailCampaign: PrepareEmailCampaignResponse =
await web3mail.prepareEmailCampaign({
grantedAccesses: grantedAccessArray,
emailSubject: 'My email subject',
emailContent: 'My email content',
});
// Step 2: Send the campaign
const { tasks }: SendEmailCampaignResponse = await web3mail.sendEmailCampaign({
campaignRequest: emailCampaign.campaignRequest,
workerpoolAddressOrEns: '0xa5de76...',
});import { IExecWeb3mail, getWeb3Provider } from '@iexec/web3mail';
import { type PrepareEmailCampaignResponse } from '@iexec/web3mail';
import { type SendEmailCampaignResponse } from '@iexec/web3mail';
const web3Provider = getWeb3Provider('PRIVATE_KEY');
const web3mail = new IExecWeb3mail(web3Provider);
// Step 1: Fetch contacts and prepare the campaign
const contacts = await web3mail.fetchMyContacts({ bulkOnly: true });
const grantedAccessArray = contacts.map((contact) => contact.grantedAccess);
const emailCampaign: PrepareEmailCampaignResponse =
await web3mail.prepareEmailCampaign({
grantedAccesses: grantedAccessArray,
emailSubject: 'My email subject',
emailContent: 'My email content',
});
// Step 2: Send the campaign
const { tasks }: SendEmailCampaignResponse = await web3mail.sendEmailCampaign({
campaignRequest: emailCampaign.campaignRequest,
workerpoolAddressOrEns: '0xa5de76...',
});Parameters
import { type SendEmailCampaignParams } from '@iexec/web3mail';campaignRequest Required *
Type: BulkRequest
The bulk request object returned from prepareEmailCampaign. This contains all the necessary information to process the bulk campaign, including the grouped protected data and campaign metadata.
const { tasks } = await web3mail.sendEmailCampaign({
campaignRequest: emailCampaign.campaignRequest,
});workerpoolAddressOrEns Optional
Type: AddressOrENS | undefined
Default: Default workerpool from chain configuration
The workerpool address or ENS name that will execute the bulk campaign tasks.
const { tasks } = await web3mail.sendEmailCampaign({
campaignRequest: emailCampaign.campaignRequest,
workerpoolAddressOrEns: '0xa5de76...',
});Return Value
import { type SendEmailCampaignResponse } from '@iexec/web3mail';tasks
Type: Array<{ taskId: string; dealId: string; bulkIndex: number }>
An array of task objects created for the bulk processing campaign. Each task object contains:
taskId: The task ID created on the iExec networkdealId: The deal ID associated with the taskbulkIndex: The index of the task in the bulk request
Each task may process multiple protected data items depending on the bulk request configuration.
const { tasks } = await web3mail.sendEmailCampaign({
campaignRequest: emailCampaign.campaignRequest,
});Related Documentation
- grantAccess Method - Grant access to protected data (recipients must set
allowBulk: trueto enable bulk processing) - fetchMyContacts Method - Fetch your contacts (use
bulkOnly: truefor bulk campaigns) - fetchUserContacts Method - Fetch contacts for a user (use
bulkOnly: truefor bulk campaigns)
