I am inexperienced in configuring mail systems.
I am using Ubuntu #54~20.04.1-Ubuntu
.
How can I configure my computer to send emails using a gmail account, with postfix
?
I mean not to have any other paid mail server or domain involved (EDIT: I could configure my PC to work as a server, but I mean to avoid requiring paid registration in DNSs).
Is this is even possible?
I tried a few things, which I will describe below, citing the sources I used.
I have read other sources, but I could not figure out what to do.
As I understand, most of these other sources assume I have some other server or address I can use (typically exemplified as example.com
), which I don't have, and I guess I can dispense with.
I followed this basic guide, which seemed to be useful for many others. After issuing
echo "Test mail thingy" | mail -s "Test Postfix Subject" [email protected]
I did not get an email in
[email protected]
, and this is the relevant tail of/var/log/mail.log
(line numbers added for reference)1 Apr 18 08:55:03 MyComputer postfix/postfix-script[1092678]: refreshing the Postfix mail system 2 Apr 18 08:55:03 MyComputer postfix/master[3124]: reload -- version 3.4.13, configuration /etc/postfix 3 Apr 18 08:55:24 MyComputer postfix/pickup[1092682]: 06004443921: uid=1000 from=<MyUser@MyComputer> 4 Apr 18 08:55:24 MyComputer postfix/cleanup[1092704]: 06004443921: message-id=<[email protected]_URL> 5 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 06004443921: from=<MyUser@MyComputer>, size=391, nrcpt=1 (queue active) 6 Apr 18 08:55:24 MyComputer postfix/error[1092706]: 06004443921: to=<[email protected]>, relay=none, delay=0.03, delays=0.02/0/0/0.01, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587) 7 Apr 18 08:55:24 MyComputer postfix/cleanup[1092704]: 09DD4443938: message-id=<[email protected]_URL> 8 Apr 18 08:55:24 MyComputer postfix/bounce[1092707]: 06004443921: sender non-delivery notification: 09DD4443938 9 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 09DD4443938: from=<>, size=2359, nrcpt=1 (queue active) 10 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 06004443921: removed 11 Apr 18 08:55:24 MyComputer postfix/local[1092708]: 09DD4443938: to=<MyUser@MyComputer>, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox) 12 Apr 18 08:55:24 MyComputer postfix/qmgr[1092683]: 09DD4443938: removed
I don't know how to interpret this log. I note that line 11 states
status=sent
.I added
-a "From: [email protected]"
(ref). I did not get the mail either. Lines in/var/log/mail.log
that changed as compared to above are marked with*
. Now I havestatus=bounced
in line 11.3*Apr 18 09:54:43 MyComputer postfix/pickup[1098199]: 0353244348F: uid=1000 from=<[email protected]> <-- CHANGED 4 Apr 18 09:54:43 MyComputer postfix/cleanup[1098387]: 0353244348F: message-id=<[email protected]_URL> 5*Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 0353244348F: from=<[email protected]>, size=384, nrcpt=1 (queue active) <-- CHANGED 6 Apr 18 09:54:43 MyComputer postfix/error[1098389]: 0353244348F: to=<[email protected]>, relay=none, delay=0.03, delays=0.02/0/0/0, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587) 7 Apr 18 09:54:43 MyComputer postfix/cleanup[1098387]: 06E2F4436C3: message-id=<[email protected]_URL> 8 Apr 18 09:54:43 MyComputer postfix/bounce[1098390]: 0353244348F: sender non-delivery notification: 06E2F4436C3 9 Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 06E2F4436C3: from=<>, size=2364, nrcpt=1 (queue active) 10 Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 0353244348F: removed 11*Apr 18 09:54:43 MyComputer postfix/error[1098389]: 06E2F4436C3: to=<[email protected]>, relay=none, delay=0.01, delays=0/0/0/0, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587) <-- CHANGED 12 Apr 18 09:54:43 MyComputer postfix/qmgr[1098200]: 06E2F4436C3: removed
Notes:
Prior to my attempts today, I already had postfix installed. I do not recall when and why I installed it. I do not recall either going through the postfix configuration screen. I know I can do it with
sudo dpkg-reconfigure postfix
, but I don't know which is the proper option.This adds
smtp_tls_CAfile = /etc/postfix/cacert.pem
to/etc/postfix/main.cf
, instead ofsmtp_tls_CApath ...
, and latercat
s a specific.pem
tocacert.pem
. I don't havecacert.pem
. I guess both options can work if properly configured.I have lots of soft links in
/etc/ssl/certs/
. I am not sure I need to add anything.I used my actual source gmail and corresponding password in
/etc/postfix/sasl_passwd
.
Related:
- How can I configure postfix to send emails via gmail (2FA problems)?
- SETUP for sending Mail via postfix to GMAIL
to use
ssmtp
instead ofpostfix
. - Setting gmail as default for sending files via email using gnome-gmail or desktop-webmail.
- https://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/
- Sending email from Gmail account to local Ubuntu server
- Ubuntu 20.04 Mail Setup Setting the Default From Address
- https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-18-04
- https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-on-ubuntu-20-04
- https://www.linuxbabe.com/mail-server/setup-basic-postfix-mail-sever-ubuntu
- https://www.cyberciti.biz/faq/how-to-configure-postfix-relayhost-smarthost-to-send-email-using-an-external-smptd/
- https://ubuntu.com/server/docs/mail-postfix
- https://devops.ionos.com/tutorials/configure-a-postfix-relay-through-gmail-on-ubuntu/
A step-by-step guide to send email with
postfix
via Gmail.I finally managed to send email via Gmail. The two answers by Raffa (1, 2) and further comments helped me a lot. But there was still further research and tinkering needed.
Here, the (hopefully) complete guide.
Install
postfix
and other packages.The configuration post-install will show up. If not, use
$ sudo dpkg-reconfigure postfix
. For the successive screens, use: 1. Satellite system, 2.MyServer
(replace with the name of your server), 3.[smtp.gmail.com]:587
, 4.root
, 5 and following: leave the defaults.Enable you gmail account to interact with
postfix
. There are two options for this.4.1. (Preferred, more secure method) Activate 2-step verification in your Google account if not activated yet. Then generate an App password for Postfix. You will need this password later.
4.2. If not using 2-step verification, enable less secure apps.
Add the following lines to
/etc/postfix/main.cf
Create/edit
/etc/postfix/sasl_passwd
so it contains<password>
should be replaced by the account password if not using 2-step verification, or the generated App password otherwise.Use the following commands
Send email with
It appears that you are not using a relay email / host and you are trying to send email directly from your machine which as you explained has no qualified domain name... let alone the other requirements like reverse DNS record and MX record.
It is clear in your logs that no valid relay is used:
And you are wondering why your emails bounce back!
They will bounce back forever no matter what you do.
A domain name is a name with a common TLD like example.com, example.net... etc. that must be bound to the IP of your sending machine... you need this.
The sending IP of the machine must as well be bound to the sending domain name with something called a reverse DNS record that can only be added by your ISP (the company providing you with the IP address)
The MX record is another type of DNS records that tells e-mail servers / providers where to rout your e-mail messages... You need this as well.
These are the requirements for modern e-mail providers to accept e-mail messages from your machine... or otherwise these e-mails are bounced / rejected.
If you are willing to go this rout and be your own e-mail provider, now you know what to do.
Otherwise, use a relay... please refer to this answer for instructions.