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.
$ hostname
mail.myhost.name
$ dig mail.myhost.name +short
179.61.xx.xx
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
mail.myhost.name.
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:
use strict;
use Email::Send::YYClouds;
my $msg = Email::Send::YYClouds->new();
$msg->send(recepient => ['xx@yahoo.com','yy@gmail.com','zz@icloud.com','aa@hotmail.com','bb@gmx.com'], # the email you want to test
sender => 'your_id@mail.myhost.name',
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!
Return to home | Generated on 11/06/22