6

When I attempt to install postfix on my home desktop system, I get a configuration dialog with the following options1:

  1. No configuration: Should be chosen to leave the current configuration unchanged.
  2. Internet site: Mail is sent and received directly using SMTP.
  3. Internet with smarthost: Mail is received directly using SMTP or by running a utility such as fetchmail. Outgoing mail is sent using a smarthost.
  4. Satellite system: All mail is sent to another machine, called a 'smarthost', for delivery.
  5. Local only: The only delivered mail is the mail for local users. There is no network.

My primary interest is to have a way for non-interactive programs running on my desktop (mostly daemons and cron jobs) to send notifications to my mobile phone (either to my current email address or to the SMS client on my mobile phone).

It would be very convenient if such notifications could also be sent locally to the root user, but this is a seconary requirement.

My desktop system connects to the internet through an ISP (Xfinity).


I suppose that option 1 is ruled out from the start.

The requirement to be able to send mail to my current (i.e. non-"local") email address rules out option 5.

This leaves options 2, 3 and 4, but I can't figure out from the descriptions above which I should pick.


EDIT: There's a typo (which, unfortunately, I can no longer fix) in the bounty description; where it says

...what exactly is the "internet site" referred to in option (1),...

should be

...what exactly is the "internet site" referred to in option (2),...


EDIT 2: After reading the first answer to my question, I realized that the bounty description I wrote is not explicit enough. In this description I give (fictitious but realistic) values for my email address, my ISP, and my hostname. I also request to avoid placeholder values like www.example.org. I put all these stipulations in the bounty description because I would like the answer to include a postfix config file for the use-case specified in the original question. I am sorry that I did not say this explicitly in the bounty description (though it is what I meant by "detailed instructions").


1 The descriptions of the various options are copied verbatim from the dialog.

14
  • 2
    Despite what the options are called, to send email from the local machine to the internet, you have to choose option 2. Both option 3 and 4 rely on another SMTP server to send. So there is only option 2 to be able to send mail using this postfix server. I'm using my postfix server exactly as you (only to send mail) and I chose option 2. Apr 15, 2021 at 11:59
  • 2
    The official Ubuntu server guide for installing postfix (which I also followed) says option 2. Apr 15, 2021 at 12:16
  • 3
    "The domain for which to accept email" should be set to the same domain to send email. Trust me, I don't want to accept email either, but you still have to choose option 2 to send email. Apr 15, 2021 at 14:54
  • 2
    Of course you should decide the best fit for you. I'm just saying what works for me, as a postfix user not receiving mail either. ;-) Apr 15, 2021 at 16:12
  • 3
    Use nullmailer if you just want to relay messages, it's orders of magnitude easier to set up than postfix. askubuntu.com/a/1124624/243321 Apr 17, 2021 at 12:50

4 Answers 4

7

Main options explained

Internet site: Mail is sent and received directly using SMTP.

This option requires you have a fully qualified domain name and full access to modify DNS records for this domain name as this method requires adding a MX record and a reverse DNS for it to send and receive emails.

Internet with smarthost: Mail is received directly using SMTP or by running a utility such as fetchmail. Outgoing mail is sent using a smarthost.

This option requires you have a fully qualified domain name but not necessarily full access to modify DNS records for this domain name. You pay for mail service providers or smarthosts to send emails on your behalf and provide a rout / method to delver incoming emails to your machine either by handling the MX and other DNS records for your domain name or by receiving them on their servers and provide you with mail server address, port and credentials so that you can periodically fetch incoming email using different protocols like POP and IMAP.

Satellite system: All mail is sent to another machine, called a 'smarthost', for delivery.

This option does not require you to have a fully qualified domain name nor access to modify DNS records. This is what serves your purpose as described in your question.

Setting up an email relay

1. General settings

You can reconfigure postfix and choose the correct option like so:

sudo dpkg-reconfigure postfix

In the configuration screens, you will see:

  • General type of mail configuration: From this choose Satellite system.

  • System mail name: Inter your machine's hostname which will most likely be displayed by default.

  • SMTP relay host (blank for none): Doesn't matter at this stage as you will set it again when you modify /etc/postfix/main.cf so leave the default.

  • Root and postmaster mail recipient: Leave it blank to have local emails to postmaster which is defined in /etc/aliases delivered to /var/mail/nobody or set the system user to receive it instead... This has nothing to do with relaying emails. This is to handle emails sent locally to for example root@localhost or other local users accounts that might be in /etc/aliases which will have something like this:

    # See man 5 aliases for format
    postmaster:    root
    
  • Other destinations to accept mail for (blank for none): These are hostnames that your postfix installation will accept emails for them... So leave this at the default which will be all possible hostnames for your current machine only.

  • Force synchronous updates on mail queue?: This tells postfix to implement some sort of internal journaling system which will slow it down but only needed when your file system is not a journaled filesystem which is not the case with Ubuntu's ext4 filesystem... So choose No.

  • Local networks: Similar to "Other destinations to accept mail for" above... This is a security feature so that other hosts on your network or outside it cannot send emails through your postfix instance... So leave it at default.

  • Mailbox size limit (bytes): Self explanatory... I recommend you leave it on default i.e. unlimited.

  • Local address extension character: Leave it on default as email providers will base their specific instructions for postfix integration on this being default.

  • Internet protocols to use: Leave it on all unless you know what you are doing... all should work fine.

It is worth mentioning that if you edit /etc/postfix/main.cf afterwords then it does not matter what option you chose during the initial configuration above and many guides advise choosing different options... compare this and this... Those guides however do not explain this point clearly and it might cause some confusion.For example one guide tells you to choose Internet Site then afterwords tells you to modify /etc/postfix/main.cf and set relayhost which will change postfix from standalone mail server to a relay mail server i.e. as if changing the option to Satellite System!

For the relay option /etc/postfix/main.cf will contain something with relayhost set to an e-mail provider like this:

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

2. Email provider's specific settings

After that follow your email provider's specific instructions for postfix integration like:

The process should be similar for other email providers if they offer this feature. If your e-mail account is with another provider, please refer to their documentations regarding relayhost address, port, security and authentication.

Please, pay attention to specific relay e-mail provider requirements like for example enabling less secure apps for Gmail or otherwise postfix will be denied access and connection to Gmail.

Extra resources

4
  • Thank you for your answer. Please the section labeled EDIT 2 that I just appended to the question.
    – kjo
    Apr 18, 2021 at 11:39
  • @sancho.sReinstateMonicaCellio "What would that be, then? " ... That would be your machine's hostname. It will have no effect as email providers like google filter e-mail headers... so you will most likely not see it even in the headers... You will see the relay e-mail in the from: field no matter what you want it or set it to be . I have updated the link with a better one.
    – Raffa
    Apr 18, 2021 at 18:16
  • @kjo "I would like the answer to include a postfix config file for the use-case specified"...I would if I could :) but it depends on your environment / machine and your e-mail provider's settings. I tried my best to explain and also updated the linked guide with a clearer and easier to follow one.
    – Raffa
    Apr 18, 2021 at 18:21
  • @sancho.sReinstateMonicaCellio "I am still puzzled. The new link you provided states "choose Internet Site", opposite what you instruct."... Please see the paragraph in italics in my answer for explanation. I updated the answer with more details... I hope it is clear now.
    – Raffa
    Apr 18, 2021 at 23:23
5
+500

A step-by-step guide to send email with postfix via Yahoo mail.

I am posting the (hopefully) complete guide to send email from Yahoo mail, as requested. This guide is slightly different from what you need if using Gmail, as shown here, and possibly other servers as well, but this specificity is crucial to make it work.

Note: I have actually tested it, and successfully received email in my destination address. It also works well with local (outgoing, incoming) addresses.

The two answers by Raffa (1, 2) and further comments helped me a lot. But there was still significant reading and tinkering needed to make it work.

  1. Install postfix and other packages.

    $ sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
    
  2. The configuration post-install will show up. If not, use $ sudo dpkg-reconfigure postfix. For the successive screens, use: 1. Satellite system (but perhaps irrelevant since you will modify the postfix configuration file later), 2. myubuntubox, 3. [smtp.mail.yahoo.com]:465, 4. root, 5 and following: leave the defaults.

  3. Enable your Yahoo account to interact with postfix, with an App password. This is a one-time password, which avoids leaving the Yahoo mail password in your PC. Go to https://login.yahoo.com/account/security , Account Security -> App Password and generate a password. You will have to use it later on. This works for sure if not using 2-step verification, and possibly with 2SV as well.
    Note that in Gmail "App Passwords can only be used with accounts that have 2-Step Verification turned on." (source). In this case, you will use the App password since postfix, as many other apps, is a "less secure app".

  4. Add the following lines to /etc/postfix/main.cf

    relayhost = [smtp.mail.yahoo.com]:465
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd_yahoo
    smtp_sasl_security_options = noanonymous
    smtp_sasl_auth_enable = yes
    smtp_use_tls = yes
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
    smtp_tls_wrappermode = yes
    smtp_tls_security_level = encrypt
    smtp_generic_maps = regexp:/etc/postfix/regex_map_yahoo
    

    If present in /etc/postfix/main.cf, comment line

    smtp_tls_security_level=may
    

    with an initial hash mark # to avoid a warning message. I am not posting the complete file. If you find issues with these instructions, please post feedback.

  5. Create/edit /etc/postfix/sasl_passwd_yahoo so it contains

    [smtp.mail.yahoo.com]:465    nosuch0000@yahoo.com:<password>
    

    <password> should be replaced by the generated App password.

  6. Use the following commands

    $ sudo chmod 0600 /etc/postfix/sasl_passwd_yahoo
    $ sudo postmap /etc/postfix/sasl_passwd_yahoo
    $ sudo touch /etc/postfix/regex_map_yahoo
    $ sudo chmod 0600 /etc/postfix/regex_map_yahoo
    $ sudo nano /etc/postfix/regex_map_yahoo
    <---- Creating/editing the file ---->
    $ sudo postmap /etc/postfix/regex_map_yahoo
    $ sudo systemctl restart postfix.service
    

    When creating/editing /etc/postfix/regex_map_yahoo, its contents should be

    /.+@myubuntubox/   nosuch0000@yahoo.com
    
  7. Send email with, e.g.

    $ echo "This is the body of an encrypted email" | mail -s "This is the subject line" emaildest@gmail.com
    
4
  • Looks like you missed contents of the file /etc/postfix/generic_map
    – raj
    Apr 19, 2021 at 15:45
  • 1
    So why use it? It's not needed for anything.
    – raj
    Apr 19, 2021 at 17:14
  • You shouldn't comment out the entire line. You have to remove only /etc/postfix/generic_map from it, so the line will be like smtp_generic_maps = regexp:/etc/postfix/regex_map_yahoo. There's no need to include a file that you don't use in smtp_generic_maps.
    – raj
    Apr 19, 2021 at 18:51
  • @Raffa Rewriting the "From:" header in Postfix would be the solution, but as I suggested in my answer, one should get a working configuration first (when using Yahoo address as sender address), and then try to add header rewriting.
    – raj
    Apr 19, 2021 at 18:54
4

Actually, none of these configuration options can be directly used on a typical home end-user machine. Option 2 works well if you have a hosted server with it's own domain name on which you configure Postfix. Options 3 and 4 work well for example in a corporate LAN, where you have a "real" domain recognizable in the DNS that your client machines are part of (btw., I don't fully understand the difference between options 3 and 4 just from the description - I would need to see the actual config files generated by these options to know for sure what they actually mean).

Regardless of what you choose you will probably need to modify the Postfix configuration files manually after initial set-up. Actually, because you will have to modify configuration anyway, option 1 is also not ruled out, contrary to what you assumed.

Email is probably the most complicated to configure of all network services and I would therefore advise to never rely "blindly" on whatever defaults the automatic configuration provides, but instead learn about how the Postfix configuration works and make all necessary corrections to the configuration file(s) manually. And you need to test, test and once again test your configuration to be sure everything works as intended. Email configuration is not something you can just "copy and paste" without understanding how it works.

A good start is http://www.postfix.org/BASIC_CONFIGURATION_README.html - this document asks some basic questions you need to answer before you start configuring Postfix and explains the basic concepts of the configuration. After you read that, take a look at http://www.postfix.org/STANDARD_CONFIGURATION_README.html - it presents configurations for several typical scenarios. However, as with the configuration menu you asked about, none of those scenarios fully apply to your case.

Probably closest to your needs is the scenario described as "Postfix on a null client", however there are two things that are not covered. A "null client" in this example is a machine that: a) does not receive any mail from network; b) does not deliver any mail locally - however if you need this, this can be changed (but I'm not covering this here as this answer is already very long); c) sends all outgoing mail to smarthost, ie. a server that processes all mail for the domain you are sending as - in your case it probably will be the Yahoo server, the same you use when sending mail from your mail client.

I will elaborate a bit later on why you need to use smarthost. The one important thing that is missing here is that in your case your Postfix will need to authenticate to the smarthost. This is covered here: http://www.postfix.org/SOHO_README.html

You need to combine all information from these documents that is relevant to your case to get a single, reasonable and usable config file.

Why is it so complicated? Generally, because your machine does not have a "proper" domain name that will be recognized in the Internet. You can use whatever option - 2,3 or 4 - in the initial configuration and your Postfix will be able to send mail, however being able to send mail is one thing; to get your mail actually delivered to the destination is a different thing. Various anti-spam measures commonly used in the Internet may cause your mail simply get rejected by the receiving server if you use the default configuration. That's why modifications are needed.

The source of the problem is that every e-mail you send needs to have some sender e-mail address. If your machine had a "legitimate" domain name assigned to it, you could just configure it using option 2, and send emails using user@domain as the email address, where user is whatever username on your machine sends the email and domain is the domain name assigned to your machine.

But you don't have a reliable domain. So the first thing to consider is what sender address do you want to use for your e-mails? Probably the safest option is to use your real e-mail address, nosuch0000@yahoo.com. Otherwise - if you don't set any sender address in the sending program - Postfix will make up some default domain name, and will send for example mail from your cron job as "root@myubuntubox.localdomain" ("localdomain" is verbatim here). Because the domain "myubuntubox.localdomain" does not exist in the Internet, the receiving server will probably not accept this message and you will see a reject in your Postfix log.

So you should ensure that every program that will send mail will provide a correct sender address. That thing is basically outside of scope of Postfix configuration. You need to configure it in every program or script that sends mail. It is possible to make Postfix rewrite whatever sender address is used to nosuch0000@yahoo.com, but it is a more complicated feature and you should already have a working configuration (and know something about configuring Postfix) before trying that. So it's better do it on the client side.

But sending with email address from yahoo.com domain is also problematic because IP address of your machine does not belong to the pool of addresses assigned to Yahoo. The receiving server may detect it and also reject your mail. And that's why you need to use a smarthost - that's what's happening in options 3 and 4. Your machine will pass all mail to smarthost, and smarthost will send it on further.

However, you cannot just pass the mail to Yahoo server as in the default configuration for "Postfix on a null client", because this example assumes that the smarthost "trusts" your machine and will accept mail from that machine with smarthost's domain in the sender address. But Yahoo server won't just trust your machine and let it send as yahoo.com. It will almost certainly reject such e-mail.

And here comes the third and most complicated part: you need to not send your mail to the smarthost, but submit it. Submission is what mail clients like Outlook or Thunderbird do. They don't connect to the default email port on the server (25), but to the special submission port (587 or 465, depending on the encryption method the client uses), authenticate to the server using your Yahoo login and password, and then proceed to send mail. After the client authenticates to the server, the server trusts it and will accept mail from it.

Similarly, your Postfix needs to authenticate to your smarthost, ie. Yahoo server. To achieve this, you need to install (besides Postfix) the authentication engine (Cyrus SASL) and configure Postfix as outlined in http://www.postfix.org/SOHO_README.html

3
  • In response to your question regarding the difference between options 3 and 4, if I install postfix with either option, and accept all the subsequent default values during the postfix configuration sequence, the only difference between the resulting /etc/postfix directories occurs in the /etc/postifix/main.cf files. In fact, only one line differs between these two files: option 3's main.cf file has inet_interfaces = all and option 4's has inet_interfaces = loopback-only.
    – kjo
    Apr 24, 2021 at 11:32
  • (Continued from my previous comment) I should add that, although I have some idea about internet interfaces, and about the loopback interface in particular, I cannot readily interpret the significance of this difference between these two main.cf. Any light you may be able to shed on what this difference means would be very helpful.
    – kjo
    Apr 24, 2021 at 11:34
  • 1
    @kjo With inet_interfaces = loopback_only, Postfix does not receive mail from network, so in effect you get "send only" configuration (probably equivalent to "null client" example from my answer). With inet_interfaces = all, Postfix can both send and receive.
    – raj
    Apr 24, 2021 at 17:47
0

The Issue

"My primary interest is to have a way for non-interactive programs running on my desktop (mostly daemons and cron jobs) to send notifications to my mobile phone (either to my current email address or to the SMS client on my mobile phone)."

The Alternative

In my answer for How do I set Cron to send emails? [duplicate] I used ssmtp. In the same thread you will find a solution using postfix which may interest you though.

As far as getting cell phone text messages I have another answer:

If you are keen on pursuing a postfix only solution here is a good tutorial:

4
  • Thank you for your suggestions. I was particularly interested in exploring the ssmtp idea, but unfortunately, ssmtp appears to be defunct (e.g. binfalse.de/2020/02/17/migrating-from-ssmtp-to-msmtp).
    – kjo
    Apr 25, 2021 at 18:25
  • 1
    @kjo My system does a daily backup every morning and uses ssmtp to email it to the cloud. Besides the link you just posted is a security threat so I won't open it. Here are instructions for Ubuntu 20.04 to setup ssmtp: havetheknowhow.com/Configure-the-server/Install-ssmtp.html Apr 25, 2021 at 19:41
  • Sorry about the problem with the link I posted. This Debian page says something similar: wiki.debian.org/sSMTP. (I figure that, since Ubuntu is based on Debian, the same applies to Ubuntu?)
    – kjo
    Apr 25, 2021 at 20:00
  • 1
    @kjo In that link it says "package is currently unmaintained". You could read that as "package is perfect and requires no new updates". If someone finds something broken I'd like to hear about that though. Apr 25, 2021 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.