I have a simple ssmtp setup.

The command echo test | mail -s "testing" username always results in me trying to send an email to username@hostname which always fails.

I am thus trying to map the local username to a specific email address.

How do I do this?

I tried /etc/aliases, but

$ sudo newaliases 
newaliases: Aliases are not used in sSMTP

Then I tried

$ cat /etc/mail.rc 
alias root root<xxx@yyy.com>
alias username username<xxx@yyy.com>

But it still isn't working. Any ideas?


I have struggled a bit with ssmtp too. The first thing I learned is that the aliases mechanism does not work with the plain mail program; I have to use mailx from the package bsd-mailx — never knew why. So before starting to change configurations around check with it.

Anyway, as a reference, I have a working ssmtp setup like the following:

  1. file /etc/ssmtp/ssmtp.conf:

    # Config file for sSMTP sendmail
    # The person who gets all mail for userids < 1000
    # Make this empty to disable rewriting.
    # The place where the mail goes. The actual machine name is required no 
    # MX records are consulted. Commonly mailhosts are named mail.domain.com
    # Where will the mail seem to come from?
    # The full hostname
    # Use SSL/TLS before starting negotiation 
    # Are users allowed to set their own From: address?
    # YES - Allow the user to specify their own From: address
    # NO - Use the system generated From: address
  2. file /etc/ssmtp/revaliases/

    # sSMTP aliases
    # Format:   local_account:outgoing_address:mailhub
    # Example: root:your_login@your.domain:mailhub.your.domain[:port]
    # where [:port] is an optional port number that defaults to 25.

and now it works:

[romano:~] % mailx -v root
Subject: test
[<-] 220 mymailserver.mymail.domain.com ESMTP my mail server
[->] HELO myhostname.mymail.domain.com
[<-] 250 mymailserver.mymail.domain.com
[->] MAIL FROM:<romano@mymail.domain.com>
[<-] 250 2.1.0 Ok
[->] RCPT TO:<romano@mymail.domain.com>
[<-] 250 2.1.5 Ok
[->] DATA
[<-] 354 End data with <CR><LF>.<CR><LF>
[->] Received: by myhostname.mymail.domain.com (sSMTP sendmail emulation); Fri, 03 Jul 2015 13:25:52 +0200
[->] From: "Romano Giannetti" <romano@mymail.domain.com>
[->] Date: Fri, 03 Jul 2015 13:25:52 +0200
[->] To: root
[->] Subject: test
[->] test
[->] .
[<-] 250 2.0.0 Ok: queued as BF1CB3BC050
[->] QUIT
[<-] 221 2.0.0 Bye

Notice that domains, hostnames etc. are scrambled for privacy here (so there can be typoes).

  • any idea if the rewriteDomain attribute works with gmail? – qodeninja Aug 26 '18 at 16:06
  • @qodeninja, no, never tried... – Rmano Aug 27 '18 at 7:13
  • Thanks, it worked after I added root:user1@example.com:mail.example.com line to /etc/ssmtp/revaliases file. – Ikrom Apr 16 at 9:07

protected by Community Mar 28 '16 at 9:22

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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