Postfix Send All Mail Via Relay
Configure Postfix to Send Mail Using an External SMTP Server Updated Tuesday, January 29, 2019 by Linode Contributed by Santiago Ti Use promo code DOCS10 for $10 credit on a new account. /var/log/mail.log SHOULD exist with Postfix. If it doesn't you'll need to check sudo tail -n 500 -f /var/log/syslog grep postfix when you are sending an email from the system to identify any errors if your syslog utility isn't creating mail.log (which postfix SHOULD be doing) –.
Setup Postfix to Relay Mail for Specific Domains or Users. May 30, 2016. I have been working with my mail server a lot lately and I ran into some problems of getting mail delivered to Outlook.com Mail Accounts (Hotmail.com, Outlook.com, Live.com, etc) but I will discuss that more in another article (In Short two months later and still can’t).
Postfix is an open-source Mail Transfer Agent (MTA) that acts as SMTP server or client for sending or receiving emails. There are so many reasons due to which users need to configure Postfix to send mail using Gmail and Google Apps. One of the main reason is to avoid getting your email flagged as spam if the current server IP has been added to the blacklist. Therefore, in this blog, we are going to discuss a step-by-step guide on how to connect Postfix to Gmail account in Ubuntu to send email through Gmail and Google Apps.
Before Getting Started
- Although not necessary, it is advised to update your system:
- Use your browser to check your email login credentials by logging into your Gmail account. This is required to check if the email account to be configured is a valid one.
Sequential Steps to Connect Postfix to Gmail Account
The process starts with installing of required packages to finally configuring the account in Postfix. Follow the guide in the below section for detailed instructions.
I. Install Postfix Mail Server
Now, you can install the Postfix or libsasl2, a package that helps to manage Simple Authentication and Security Layer (SASL).
- You can install Postfix and libsasl2-modules package too:
- During the installation of Postfix, a prompt will pop up asking for the General type of mail configuration. Then, choose Internet Site:
- Enter the totally qualified name of your specific domain.
- After completion of an installation process, confirm that the myhostname parameter is already configured with the server’s FQDN:
II. Create an App Password for Postfix
When you enable the two-Factor Authentication (2FA), Gmail is pre-configured to decline connections from different applications like Postfix which does not support the second step of authentication. Otherwise, this is a very important security measure that is developed to restrict any unauthorized user from accessing the account, it halts sending email through SMTP clients. Here are following steps to configure Gmail account to create the Postfix-specific password:
- Sign in to your email address, then you will need to Manage your account access and security settings. Move towards “Password & sign-in method” and click the 2-Step Verification. You might be asked for the password and verification code before continuing further. You may ensure that Two-Step Verification is enabled.
- Now, Generate the App password for Postfix:
- Go to Select app and, then choose Other (custom name) from drop-down menu. Enter the Postfix and click Generate.
- Now, you can see the newly generated password. Write it down or keep it somewhere secure that you will be able to find easily in the further steps, then press Done:
Postfix Send All Mail Via Relay Location
III. Add Gmail account Username & Password to Postfix
Username and password are saved in sasl_passwd inside the /etc/postfix/sasl/ directory. So, you will need to add your mail login credentials to this particular file and to Postfix. By doing this we will get one step closer to eventually connecting Postfix to Gmail account.
- You can open or create /etc/postfix/sasl/sasl_passwd file and then add SMTP Host, username, and password detail:
Note: Message submission can be done over 587(StartTLS) or 465(SSL) port. Whichever you choose, make sure to use the same port number throughout the procedure.
- Generate the hash DB file for Postfix by executing the postmap command:
If everything is going perfect, you will receive a new file named sasl_passwd.db in this /etc/postfix/sasl/ directory.
IV. Keep Postfix Hash Database and Email Password File Safe
These files /etc/postfix/sasl/sasl_passwd and /etc/postfix/sasl/sasl_passwd.db are created in the above steps that contain your SMTP credentials in a plain text.
Restricting access to files, change all the permissions so that only a root user can read from or write to specific files. Run the following cmdlets to change an ownership to root and update file permissions for two files:
V. Configure Postfix SMTP Relay Server
In this segment, you can configure the /etc/postfix/main.cf file to utilize the Gmail’s SMTP server.
- Search and modify relayhost in /etc/postfix/main.cf to match the example given below. Make sure that the port number suits what you defined in /etc/postfix/sasl/sasl_passwd above.
- At the end of a file, add the list of following parameters to enable authentication:
- Save all the changes and close that file.
- Finally, you can restart the Postfix:
User’s Problem
“I was unable to find any documentation on postfix stored emails. I don’t even know where these emails are stored and what is the file format? I need to move these emails from Postfix to Gmail. Currently, I am using Ubuntu Server 11. Can anyone suggest me a feasible solution for the same? Any help or suggestion would be highly appreciated!!”
The standard format, called “MBOX” that starts with “From” to specify the start of every message – this is the main reason why many email programs will change “From” in the body of the email message to “>From”. Also, you can configure it by using “Maildir”, in which /var/mail/[username] is a directory where each message is a certain file in that directory.
Alternate Solution to Migrate Postfix to Gmail Account
If the above-stated method does not work well, users can take help of a reliable third-party tool, i.e., MBOX to G Suite Migrator. It is designed in such a way to perform bulk conversion from MBOX to Google Apps without any data loss. The interface is simple and easy-to-use. It also helps to retain the on-disk folder hierarchy of MBOX after the conversion process. It is compatible with all latest versions of Windows operating system including 32-bit and 64 bit.
Final Words
Many users search for a reliable and efficient solution to migrate Postfix to Gmail. Therefore, in the above section, we have described a step-by-step procedure to move MBOX file to Google Apps. But, sometimes users may face various problems when performing the manual solution. Thus, we have suggested a trustworthy approach named as MBOX to G suite Migrator, which helps to export multiple .mbox files to Gmail at once without any hassle.
Leave a Reply
On my home Ubuntu box, postfix is configured to relay all outgoing email to outgoing.verizon.net
. Unfortunately this includes local user-to-user email (e.g., from local cron jobs to me, or from me to myself) which should not need to travel off-machine. Is there a way to tweak my configuration (below) so local email is delivered without leaving my machine?
Note: I don't run a mail server (on port 25) but rather run fetchmail every five minutes to download from an IMAP server.
main.cf:
1 Answer
Postfix will only relay non-local mails
to the host specified in the relayhost
. To consider a domain local; the domain has to be listed under mydestination
parameter. So listing example.com
under mydestination
should help you to fix this issue.
Ref: Postfix docs