We take email for granted. It seems so easy. Just click the send button. But spam has made sending and receiving email a lot more complicated. This is especially true for people who like to run their own networks at home. If you are like me, you might have 1 or more physical machines running multiple virtual machines, not to mention multiple containers as well. All this network infrastructure needs to communicate with you somehow. After all, how do you keep tabs on whether or not your CRON jobs are successful? Email is the way. But sending email out from a home network without it being blocked at various points along the way can get complicated. We can go through the cost of buying a domain and email service, but who wants the cost? So how do we get the email through? This post explains how to configure Postfix to relay email through a Yahoo! account over SSL.Disclaimer
This post is solely informative. Critically think before using any information presented. Learn from it but ultimately make your own decisions at your own risk.Requirements
I did all of the work for this post using the following major technologies. You may be able to do the same thing with different technologies or versions, but no guarantees.A Yahoo! account Ubuntu 18.04.1 LTS Postfix 3.3.0 Install Postfix
I’m not going to go into a lot of explanation. I’m simply going to state the steps and configuration I did which got everything working.
First thing you need to do is install Postfix.$ sudo apt-get update $ sudo apt-get install postfix mailutils
NOTEFor the Postfix installation, when it asks for the “System mail name” value, it should be the same as the name of the server.Configure Yahoo! Account
The Yahoo! Account’s security setting must be set to allow password authentication. By default, it is not enabled. Go to the Yahoo! Account Security page and make sure “Password is enabled” is set as showing in Figure 1.
Figure 1 Yahoo! Account SecurityConfigure Postfix Authentication for Yahoo!
Configure Postfix to login to Yahoo!’s SMTP server. This configures the server name, port, account id, and clear text password.# Create the password file $ cd /etc/postfix/sasl $ touch sasl_passwd_yahoo $ chmod 600 sasl_passwd_yahoo
Now edit the sasl_passwd_yahoo file using your favorite editor. Make it look like Listing 1, replacing ACCOUNT_NAME and CLEAR_TEXT_PASSWD appropriately.Listing 1 sasl_passwd_yahoo [smtp.mail.yahoo.com]:465 ACCOUNT_NAME@yahoo.com:CLEAR_TEXT_PASSWD
Now hash the sasl_passwd_yahoo file into a Postfix .db file$ postmap sasl_passwd_yahoo Configure Postfix Email Mapping for Yahoo!
If user mike attempts to send an email from a server with the name bluegreensky , the default Postfix FROM address will be mike@bluegreensky . This is not good because if you try to relay this email through Yahoo!, it will be blocked since the FROM address does not match the Yahoo! account. To get around this, configure a regular expression mapping file that will change all local email addresses (like mike@bluegreensky ) to the Yahoo! account email address.
First, create a generic map file that’s empty$ mkdir /etc/postfix/map $ cd /etc/postfix/map $ touch generic_map $ chmod 600 generic_map # Hash the file into a *.db file $ postmap /etc/postfix/map/generic_map
Next, create a yahoo map file that will change local email address to the Yahoo! account email address.$ mkdir /etc/postfix/map $ cd /etc/postfix/map $ touch regex_map_yahoo $ chmod 600 regex_map_yahoo
Now edit the regex_map_yahoo file using your favorite editor. Make it look like Listing 2, replacing HOSTNAME just HOSTNAME , not @HOSTNAME …don’t lose the @ character and ACCOUNT_NAME appropriately.Listing 2 regex_map_yahoo /.+@HOSTNAME/ ACCOUNT_NAME@yahoo.com
Now hash the regex_map_yahoo file into a Postfix .db file$ postmap regex_map_yahoo Configure Postfix SSL for Yahoo!
SSL must be used to connect to Yahoo! SMTP servers. During Postfix installation, a main.cf is created. It must be edited$ cd /etc/postfix
Now edit the main.cf file using your favorite editor. In Listing 3 are the values you must add or update in main.cf . For each of the name/value pairs below, search main.cf to see if it already exists. If so, use my value below. If not, add my value to the end of main.cf .Listing 3 main.cf # Yahoo! relayhost = [smtp.mail.yahoo.com]:465 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_security_options = smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd_yahoo smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt smtp_tls_wrappermode = yes smtp_tls_security_level = encrypt smtp_generic_maps = hash:/etc/postfix/map/generic_map, regexp:/etc/postfix/map/regex_map_yahoo Restart Postfix
Restart Postfix so it picks up all the new configuration.
bash $ service postfix restartTesting Postfix
If all goes well, Postfix restarted without any errors and is now configured to relay email from the server through the Yahoo! account. I typically test this with both mail and at .# Test sending mail directly $ echo "test email message" | mail -s "test email from server" firstname.lastname@example.org # Test sending mail through scheduler at $ echo "echo \"gosh golly, it is AT\"" | at now Summary
This post shows how to configure Postfix to relay email through a Yahoo! account over SSL. Sending email from a home network and have it not be blocked is tough. This configuration got me working. I hope it works for you.Published on Web Code Geeks with permission by Michael Remijan, partner at ourWCG program. See the original article here: Postfix relay through Yahoo! (SSL)
Opinions expressed by Web Code Geeks contributors are their own.