Skip to content

Instantly share code, notes, and snippets.

@MyKEms
Created November 14, 2023 08:46
Show Gist options
  • Save MyKEms/74b2873b906708c140cfe1881385cfbc to your computer and use it in GitHub Desktop.
Save MyKEms/74b2873b906708c140cfe1881385cfbc to your computer and use it in GitHub Desktop.
SimpleLogin.io Bulk Email Alias Creation Script
# Documentation: https://github.com/simple-login/app/blob/master/docs/api.md#post-apiv3aliascustomnew
# This script facilitates the bulk creation of email aliases on SimpleLogin.io by automating the API calls needed for each alias. It ensures compliance with rate limits and handles the retrieval of domain-specific signed_suffixes for each alias creation request.
# Author: https://github.com/MyKEms
#!/bin/bash
# Adjust variables
api_key="API_TOKEN"
domain="contoso.com"
# Set your mailbox ID below. Retain the square brackets even if it's a single ID.
mailbox_ids="[123456]" # You can find this ID in the SimpleLogin dashboard: navigate to 'Mailboxes', click 'Edit', and then copy the number from the URL.
# Alias names you want to create
declare -a aliases=("alias_name_1" "alias_name_2" "alias_name_3") # Add the alias prefixes you need
# Loop through each alias and create them using the SimpleLogin API
for alias in "${aliases[@]}"; do
# Get the signed_suffix for the domain using the SimpleLogin API
response=$(curl -X GET "https://api.simplelogin.io/api/v4/alias/options" \
-H "Content-Type: application/json" \
-H "Authentication: $api_key")
# Parse the signed_suffix for the specific domain
signed_suffix=$(echo $response | jq -r --arg domain "@$domain" '.suffixes[] | select(.[0]==$domain) | .[1]')
# Create the new alias using the signed_suffix
create_response=$(curl -s -o /dev/null -w "%{http_code}" -X POST "https://api.simplelogin.io/api/v3/alias/custom/new" \
-H "Content-Type: application/json" \
-H "Authentication: $api_key" \
-d "{\"alias_prefix\": \"$alias\", \"signed_suffix\": \"$signed_suffix\", \"mailbox_ids\": $mailbox_ids}")
# Check if the creation was successful
if [ "$create_response" -eq 201 ]; then
echo "Created alias: $alias${signed_suffix} for domain: $domain"
else
echo "Failed to create alias: $alias${signed_suffix} for domain: $domain. Error code: $create_response"
fi
# Wait for 30 seconds to respect the API rate limit (or we could receive '429 - Whoa, slow down there, pardner!')
echo "Sleeping for 30 seconds to respect the API rate limit"
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment