Simple imap Sync script

black and gray digital device

This script helps importing emails

yum install imapsync

Here is the script

#!/bin/bash

# Define the IMAP parameters for the Source and Destination mail servers

source_server=""
source_username=""
source_password=""

destination_server=""
destination_username=""
destination_password=""

# Test connection to Source Mail Server using IMAP

echo "Testing connection to Source Mail Server..."
if [[ $(curl -v -u $source_username:$source_password 'imaps://'$source_server':993/INBOX' 2>&1) == *"OK"* ]]; then
    echo "Connection to Source Mail Server established successfully"
else
    echo "Failed to connect to Source Mail Server"
    exit 1
fi

# Test connection to Destination Mail Server using IMAP

echo "Testing connection to Destination Mail Server..."
if [[ $(curl -v -u $destination_username:$destination_password 'imaps://'$destination_server':993/INBOX' 2>&1) == *"OK"* ]]; then
    echo "Connection to Destination Mail Server established successfully"
else
    echo "Failed to connect to Destination Mail Server"
    exit 1
fi

# Execute email migration process using imapsync
echo "Executing email migration using imapsync..."

imapsync --ssl1 --ssl2 --noauthmd5 --host1 $source_server --user1 $source_username --password1 $source_password --host2 $destination_server --user2 $destination_username --password2 $destination_password --automap

exit 0