Years ago, I was usually using my own SMTP server, but after some time my IP addresses were constantly on some spamming black-list or gray-list, because email was coming from an IP range of the provider with some dynamically allocated public IPs and a lot of other users has some viruses or spam bots, so I was almost constantly banned from sending emails.
The solution in this case is to use some 3rd party SMTP server which will not have problems described above. This example is mainly for sending emails with Python script, but you can also setup your own MTA (Mail Transfer Agent, e.g. postfix) to use those servers as relay host.
Warning: Google or Amazon usually has no problem with delivery, however you cannot set random From: field, only verified email addresses can be used!
Setup Google is little bit faster because Amazon needs special permission to remove from sandbox. Limits are described here, it should be around 2000 emails a day.
To be able to use Google SMTP, you need to setup 2-step verification. Without it, it is not possible to use your credentials directly with SMTP. With 2-step verification you will have your original credentials for accessing your Google account and you will generate additional password just to access SMTP.
Now you can use your account login and this password to access SMTP server.
Amazon SES runs in sandbox mode and only verified emails can be use as sender and receiver. It can be useful when you need to send and receive some email notification just yourself, but to send email also to other "non-verified" address you need to remove your account from sandbox. Once removed from sandbox, they will give you about 50000 emails a day and 14 emails per second.
If you have your own domain, you can also create email accounts for it (after adding MX record to the DNS). However email reception is quite tricky here, you need to setup SNS (Simple Notification Service) to deliver received email to AWS Lambda function and then use the code of the function to initiate delivery of the email to you (there is SES API for it). This may be handy in some situations, but for the email forwarding it is completely useless. You need still to use verified domain in From: emails and not the original From: to handle those email forwards easily in your 3rd party mailbox. There is some option using X-Origin headers, but I have no idea if there is any support in emails clients for it. More info about AWS Lambdas for SES for example here.
You need to set credentials and SMTP server hostname and port and the rest is quite straightforward thanks to smtplib module:
#!/usr/bin/env python3 import sys import smtplib # Google: USER='yourlogin@gmail.com' PASS='google-will-provide-this' SMTP_HOST='smtp.gmail.com' SMTP_PORT=587 # Amazon SES USER='AKIA................' PASS='amazon-ses-will-generate-password-for-you' SMTP_HOST='email-smtp.us-east-1.amazonaws.com' SMTP_PORT=587 # Send email sent_from = 'Only verified email here' to = [ 'recipient@somedomain.com' ] subject = 'Hello, test email' body = "Thist is test!" email_text = """From: %s To: %s Subject: %s %s """ % (sent_from, ", ".join(to), subject, body) def main(argv): try: server = smtplib.SMTP(SMTP_HOST, SMTP_PORT) server.ehlo() server.starttls() server.login(USER, PASS) server.sendmail(sent_from, to, email_text) server.close() print('Email sent!') except Exception as e: print('Something with SMTP went wrong...') print(e) if __name__ == "__main__": main(sys.argv)