Email Address Blocklists

Allow your user to block specific email addresses from being able to send messages to any of their Sudo email addresses

When a user blocks a sender's email address through the Email SDK, that sender is prevented from sending messages to any of the user's email addresses.

Blocking Email Addresses

Email addresses can be blocked in batches and are blocked for all email addresses that the user owns. Blocking addresses can be done through the blockEmailAddresses method by passing in an array of the addresses to be blocked. The addresses should be in the format foo-bar@domain.com.

The method will respond with a BatchOperationResult type which contains the status of the batch operation. Three possible statuses can be returned:

StatusDefinition

Success

All of the email addresses were successfully to blocked.

Partial

Only a subset of the email addresses could be blocked successfully. The return object will include a list of addresses which failed to be blocked and a list of those which succeeded.

Failure

All of the email addresses failed to be blocked.

// Obtain the email addresses to be blocked
const addressesToBlock = arrayOf('email-address-1@domain.com', 'email-address-2@domain.com')
try {
    const blockingResult = await emailClient.blockEmailAddresses({
        addressesToBlock
    })
    switch (blockingResult.status){
        case UpdateEmailMessagesStatus.Success:
          // All addresses were blocked successfully
          break
        case UpdateEmailMessagesStatus.Failed:
          // None of the addresses were blocked successfully
          break
        case UpdateEmailMessagesStatus.Partial:
          // `blockingResult.successItems` contains an array of all the addresses
          // blocked successfully.
          // `blockingResult.failureItems` cotains an array of all the addresses
          // that failed to be blocked successfully.
          break
      }
} catch (e) {
    // Handle/notify user of errors
}  

Unblocking Email Addresses

Unblocking email addresses works much the same way as blocking them does. It can be achieved by passing an array of the addresses to be unblocked to the unblockEmailAddresses method. They should also be in the format foo-bar@domain.com.

The method will respond with the same BatchOperationResult type with the same possible statuses.

// Obtain the email addresses to be unblocked
const addressesToUnblock = arrayOf('email-address-1@domain.com', 'email-address-2@domain.com')
try {
    const unblockingResult = await emailClient.unblockEmailAddresses({
        addressesToUnblock
    })
    switch (unblockingResult.status){
        case UpdateEmailMessagesStatus.Success:
          // All addresses were unblocked successfully
          break
        case UpdateEmailMessagesStatus.Failed:
          // None of the addresses were unblocked successfully
          break
        case UpdateEmailMessagesStatus.Partial:
          // `unblockingResult.successItems` contains an array of all the addresses
          // unblocked successfully.
          // `unblockingResult.failureItems` cotains an array of all the addresses
          // that failed to be unblocked successfully.
          break
      }
} catch (e) {
    // Handle/notify user of errors
}

Alternatively, you can also unblock email addresses by the hashedValue (returned from the getEmailAddressBlocklist endpoint below). This can be useful if the user has lost their cryptographic key and is unable to unseal the plaintext address. The unblockEmailAddressesByHashedValue method works the same way, except it accepts an array of hashedValues instead of plaintext addresses.

// Obtain the hashedValues from the getEmailAddressBlocklist endpoint
const hashedValues = arrayOf('hashedValue1', 'hashedValue2')
try {
    const unblockingResult = await emailClient.unblockEmailAddressesByHashedValue({
        hashedValues
    })
    switch (unblockingResult.status){
        case UpdateEmailMessagesStatus.Success:
          // All addresses were unblocked successfully
          break
        case UpdateEmailMessagesStatus.Failed:
          // None of the addresses were unblocked successfully
          break
        case UpdateEmailMessagesStatus.Partial:
          // `unblockingResult.successItems` contains an array of all the addresses
          // unblocked successfully.
          // `unblockingResult.failureItems` cotains an array of all the addresses
          // that failed to be unblocked successfully.
          break
      }
} catch (e) {
    // Handle/notify user of errors
}

Listing Blocked Email Addresses

To obtain a list of blocked email addresses for a user, call the getEmailAddressBlocklist method. It will return an array of UnsealedBlockedAddress objects. They will have three properties:

PropertyDescription

status

The status of the unsealing operation to access the plaintext address. Possible values are Completed or Failed. If it is Failed there will be an error type indicating the reason for the failure and the address property will contain an empty string.

address

The plaintext version of the blocked address. This will be an empty string if the unsealing process fails.

hashedValue

The unique hash value representing the blocked address. This can be used for unblocking in the event that the plaintext address cannot be unsealed.

try {
    const blockedAddresses = await emailClient.getEmailAddressBlocklist()
    // `blockedAddresses` is an array of UnsealedBlockedAddress objects
} catch (e) {
    // Handle/notify user of errors
}

Last updated