Skip to content

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:

  1. Recipients granted access with bulk processing: When calling grantAccess on the Data Protector SDK, recipients must set allowBulk: true

  2. Prepared the campaign: Use prepareEmailCampaign to create the bulk request that will be passed to this method

Usage

ts
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...',
});
ts
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

ts
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.

ts
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.

ts
const { 
tasks
} = await
web3mail
.
sendEmailCampaign
({
campaignRequest
:
emailCampaign
.
campaignRequest
,
workerpoolAddressOrEns
: '0xa5de76...',
});

Return Value

ts
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 network
  • dealId: The deal ID associated with the task
  • bulkIndex: The index of the task in the bulk request

Each task may process multiple protected data items depending on the bulk request configuration.

ts
const { 
tasks
} = await
web3mail
.
sendEmailCampaign
({
campaignRequest
:
emailCampaign
.
campaignRequest
,
});