SESWatcher : how to prevent Amazon SES account from being suspended

Introdution

At this moment, AWS SES service is the best affordable price and high-quality service to sending (and receiving) programmatic emails. But, one day your account could be suspended without notice, and that takes a big effort of requesting support to get it back to work.

So it’s good to prevent that siatuation happens by watching your Bounces Rate and Complaints Rate. One way to resolve problem when your rates being too-high than allowance, is send a big amount of dummy emails to your blackhole email address.

Example

These is your send statistics :

  • Deliveries : 2000
  • Bounces : 180 ==> Bounces Rate : 180 / 2000 = 9%
  • Complaints : 30 ==> Complaints Rate : 30 / 2000 = 1.5%

Meaning :

  • Bounces : when your email didn’t send to existed email address (maybe your user type wrong or input fake one), we can pre-validate email before sending by using some email validator library or services like fast-email-validator
  • Complaints : when your receiver mark your email as SPAM :( Poor you !!!

Solution

AWS SES rules :

  • Bounces Rate : 5% => So you have to send more (180 / 4%) - 2000 = 2500 emails to reduce Bounces Rate to 4%
  • Complaints Rate : 0.1% => So you have to send more (30 / 0.07%) - 2000 = 40857 emails to reduce Complaints Rate to 0.07%

==> Number emails send = max(2500, 40857) = 40857 emails

SPAM YOURSELF 40857 EMAILS !!! 😂

SESWatcher - Your SES watchman

It’s open source software at https://github.com/khanhicetea/seswatcher (My first PyPi package :D)

Installation

1
$ pip install seswatcher

Usage

  1. Step 1 : Get AWS Credential User within AmazonSESFullAccess policy
  2. Step 2 : Verify sender email in AWS SES
  3. Step 3 : Get a blackhole email address which receives un-important emails.
  4. Step 4 : Create a hourly cronjob that runs seswatcher
1
$ seswatcher [OPTIONS] ACCESS_KEY SECRET_KEY FROM_EMAIL TO_EMAIL

Get help :

1
2
3
4
5
6
7
$ seswatcher --help
Usage: seswatcher [OPTIONS] ACCESS_KEY SECRET_KEY FROM_EMAIL TO_EMAIL

Options:
--region TEXT AWS SES Region (default is us-east-1)
--interval INTEGER Timer interval
--help Show this message and exit.

#TIL : Using watch command to tracking changes in period time

watch to a good command to run a command every N seconds.

And like its name, means you can watch something, its output changes with flag -d

It’s a great tool to help you learn a new language without hitting compile and run everytime you save a file.

1
$ watch -n 1 -d go run learn.go

This command will compile and run learn.go every 1 second

More flags :

  • -t : no title
  • -b : beep on non-zero exit code
  • -e : stop loop on error and exit on a keypress
  • -g : exit on change
  • -c : support colors
  • -h : you know ! ;)

#TIL : Using netcat as tiny TCP debug tool

You can use netcat or nc as a debugging TCP tool. It can be a TCP sender and receiver with a short session (auto close when connection is closed)

Examples :

Scan ports

1
$ nc -zv 127.0.0.1 20-80

Check redis status

1
$ echo 'info' | nc 127.0.0.1 6379

Retrieve http response

1
$ printf "GET /xinchao HTTP/1.1\r\n\r\n" | nc 127.0.0.1 8000 | tee xinchao.txt

Change to IPv6 : nc -6

Want more ??

1
$ nc -h

#TIL : zcat : decompressing pipe tool

zcat is a tool that creates a pipe from gz file. It makes command cleaner and faster (maybe). You don’t have to decompress gz file before using next tool.

Examples :

Finding string in gzip text file

1
$ zcat secret.gz | grep '42'

Importing SQL backup file

1
2
$ mysqldump -u root -p db_name1 | gzip > db_name.sql.gz
$ zcat db_name.sql.gz | mysql -u root -p db_name_2