sSMTP

sSMTP is a program which delivers email from a local computer to a configured mailhost (mailhub). It is not a mail server (like feature-rich mail server sendmail) and does not receive mail, expand aliases or manage a queue. One of its primary uses is for forwarding automated email (like system alerts) off your machine and to an external email address.

Note: sSMTP is unmaintained. Consider using something like msmtp or OpenSMTPD instead.

Installation

Install the package ssmtpAUR.

Forward to a Gmail mail server

To configure sSMTP, you will have to edit its configuration file (/etc/ssmtp/ssmtp.conf) and enter your account settings.

  • If your Gmail account is secured with two-factor authentication, you need to generate a unique App Password to use in ssmtp.conf. You can do so on your App Passwords page. Use you Gmail username (not the App Name) in the AuthUser line and use the generated 16-character password in the line, spaces in the password can be omitted.
  • If you do not use two-factor authentication, you need to allow access to unsecure apps. You can do so on your Less Secure Apps page.

Create aliases for local usernames (optional)

To test whether the Gmail server will properly forward your email:

Change the 'From' text by editing /etc/passwd to receive mail from 'root at myhost' instead of just 'root'. Which changes /etc/passwd to:

Security

Because your email password is stored as cleartext in /etc/ssmtp/ssmtp.conf, it is important that this file is secure. By default, the entire directory is accessible only by root and the mail group. The /usr/bin/ssmtp binary runs as the mail group and can read this file. There is no reason to add yourself or other users to the mail group.

Sending email

To send email from the terminal, do:

$ echo -e "Subject: this is the subject\n\nthis is the body" | mail user@example.com

or interactively as:

$ sendmail username@example.com
Subject: this is my subject
CC: optional@example.com

Now I can type the body here

An alternate method for sending emails is to create a text file and send it with ssmtp or mail

Send the file

$ sendmail -t < test-mail.txt

Some users might prefer the syntax of mail from , , or other mailx providers instead. For example, mail has options to provide the subject as an argument. mail requires sendmail and can use ssmtpAUR as sendmail.

Attachments

If you need to be able to add attachments, install and configure Mutt and Msmtp and then go see the tip at nixcraft.

Alternatively, you can attach using uuencode from . To attach 'file.txt' as 'myfile.txt':

$ uuencode file.txt myfile.txt | sendmail user@example.com

Mail to Local Users

Messages sent to local users (or any other address not ending in @fqdn are treated in one of two ways

  • destination user has UID < 1000 - The address is replaced by the address defined by root=user@fqdn in /etc/ssmtp/ssmtp.conf
  • destination user has UID ≥ 1000 or the user is unknown - The the value from in /etc/ssmtp/ssmtp.conf is appended to the end of the user id.

This can lead to problems if local users on your system are not also valid users at your , but are receiving mail from system services, esp if your rewrite domain is a public service like .

To work around this, you can use mail from . The mail command can read aliases defined in . Example:

You can then pipe messages into mail instead of into sendmail.

$ echo -e "Hey archuser." | mail archuser
gollark: No, it's from their docs.
gollark: Er, yes.
gollark: The last one using UTTERLY apiaristic string manipulation which nevertheless runs very very fast.
gollark: And solve sudokus.
gollark: You can abuse "recursive common table expressions" (why is this a feature) to compute mandelbröts apparently?

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.