Sometimes we want to send a small bunk mail from VPS. But unluckly most VPS's IPs are in blacklist of the big providers, such as google, MS, Yahoo etc.
How to test if you have got a clean IP for sending mail? Follows are the simple guide.
First you want to install Postfix which will act as the MTA to communicate to the providers' MTAs.
On ubuntu it's quite easy to install Postfix, just do:
$ sudo apt install postfix
Then change two lines of your postfix config file, which is /etc/postfix/main.cf.
inet_protocols = ipv4
myhostname = mail.myhost.name
The first line makes postfix to listen on IPv4 only, otherwise you will have troubles in sending mail to gmail.
The second line specifies the valid hostname for your VPS, it must be a FQDN. That's to say, your VPS should have setup that hostname correctly, and the hostname must be resolved. For example, the following commands should work.
$ dig mail.myhost.name +short
After then, you should contact your host provider to add a rDNS for VPS's IP. And, the rDNS hostname should point to your hostname mentioned above.
For instance, this command should work for the IP:
$ dig -x 179.61.xx.xx +short
Well, myhostname in Postfix is used for HELO command of SMTP session. rDNS and its name are used for IP resolution in the connection stage of SMTP. Though they are different stuff, but you would best to keep them consistent.
For now you have installed postfix, setup hostname and rDNS. The next step is to install a perl module for testing sendmail.
$ sudo apt install cpanminus
$ sudo cpanm Email::Send::YYClouds
Write the script as follows:
my $msg = Email::Send::YYClouds->new();
$msg->send(recepient => ['[email protected]','[email protected]','[email protected]','[email protected]','[email protected]'], # the email you want to test
sender => '[email protected]',
smtprelay => 'localhost',
subject => 'slip between fiction and reality', # test subject
body => 'This slip between fiction and reality seems to speak more broadly to the role of law enforcement itself', # test body
Now run this perl script which will send test mail to the email addresses you specified for those big providers.
Check your inboxes to verify if they have arrived to you.
If not arrive, you should check /var/log/mail.log to find out the reasons such as IP is blocked. And contact your VPS provider to fix up IP reputation though it's generally useless.
Good luck with it!