Skip to main content

Sending E-mail Notifications

To help you stay informed on the status of the stake pool that you operate, the Postfix mail server allows you to send e-mail notifications securely using Bash scripts.

To install and configure Postfix:

  1. Using a terminal window, type:
    sudo apt-get update
    sudo apt-get install postfix mailutils libsasl2-modules
  2. When prompted to select the mail server configuration type, using the UP and DOWN arrow keys select the Internet With Smarthost option, then press the TAB key, and then press ENTER

    Note
    Note

    Selecting Internet with Smarthost simplifies configuring an e-mail account that you set up with a major service provider—such as Gmail, Microsoft Outlook or Yahoo Mail—to send notifications.

  3. When prompted for a mail name, press TAB to accept the default value, and then press ENTER
  4. When prompted for the SMTP relay host, type the default external host for Postfix to use when sending e-mail, then press TAB, and then press ENTER

    Note
    Note

    If you plan to configure an account that you set up with one of the following major service providers to send e-mail notifications using Postfix, then type the respective server name and port, for example:

    • Gmail—[smtp.gmail.com]:587
    • Microsoft Outlook—[smtp.office365.com]:587
    • Yahoo Mail—[smtp.mail.yahoo.com]:587

    In Postfix, enclosing a hostname in square brackets ( [ ... ] ) skips Domain Name System (DNS) MX record lookup and connects directly to the host using the A/AAAA record and specified port.

  5. When the installation completes, type the following commands to edit the main.cf configuration file:
    cd /etc/postfix
    sudo nano ./main.cf
  6. In the main.cf file, add or edit the following lines:
    ...

    # Set mail relay authorization
    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

    ...

    # Disable local mailbox delivery
    mydestination =

    ...

    # Limit relaying to the local computer
    mynetworks = 127.0.0.0/8 [::1]/128

    ...

    # Bind only to the local loopback network
    inet_interfaces = loopback-only

    ...

    # Set Internet protocol versions that the Postfix server uses
    inet_protocols = all

    ...

    # Enable SASL authentication
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_sasl_tls_security_options = noanonymous

    # Enable TLS encryption
    smtp_use_tls = yes
    smtp_tls_security_level = encrypt
    smtp_tls_note_starttls_offer = yes
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
  7. Save and close the main.cf file.
  8. If required by your e-mail service provider, create an app password for the e-mail account sending notifications.
  9. To set authentication credentials for the SMTP server, type:
    sudo nano /etc/postfix/sasl_passwd
  10. In the sasl_passwd file, add the following line where <SMTPRelayHost> is the SMTP relay host that you typed in step 4; <EmailAddress> is the e-mail address for the account sending e-mail notifications; and, <Password> is the password for acessing the account sending e-mail notifications or the app password that you generated in step 8
    <SMTPRelayHost> <EmailAddress>:<Password>

    Note
    Note

    For example:

    [smtp.gmail.com]:587 user@gmail.com:nxbnczhaocydwrsl

  11. Save and close the sasl_passwd file, and then type:
    sudo chmod 600 /etc/postfix/sasl_passwd
    sudo postmap /etc/postfix/sasl_passwd
  12. To prevent cron from e-mailing you standard output (STDOUT) and standard error (stderr) messages from cron jobs, type crontab -e and then add the following line at the beginning of the file:
    MAILTO=""
  13. Save and close the crontab file.
  14. To restart the Postfix service, type:
    sudo systemctl restart postfix.service

To send an e-mail using Postfix:

  • Using a terminal window, type the following command where <MessageBody> is the information that you want the e-mail to include; <SubjectLine> is a descriptive summary of the e-mail; and, <RecipientEmailAddress> is the e-mail address receiving the e-mail:
    echo "<MessageBody>" | mail -s "<SubjectLine>" <RecipientEmailAddress>