Sameervb
Sameervb

Reputation: 421

How to use an alias while sending mail on linux?

I have a shell script which sends out a mail at the end of its processing about the status. I am using the command -

mail -s "MAIL_SUBJECT" "tom@my_domain.com" < "MAIL_TEXT"

This mail is being sent from an email id like user@<machine_name>.my_domain.local.

Is it possible to use an alias while sending these mails ?

Something like process.name@my_domain.com?

If yes how do we do it ?

Upvotes: 1

Views: 3439

Answers (3)

David Mu&#241;oz Tord
David Mu&#241;oz Tord

Reputation: 365

-r doesn't do anything IF you have not set :

FromLineOverride=Yes

in /etc/ssmtp/ssmtp.conf (for debian at least) see -> https://linux.die.net/man/5/ssmtp.conf ["FromLineOverride Specifies whether the From header of an email, if any, may override the default domain. The default is ''no''."]

Upvotes: 0

user7616519
user7616519

Reputation: 11

Use the -r option to mention the from address.

mail -r "process.name@my_domain.com" -s "MAIL_SUBJECT" "tom@my_domain.com" < "MAIL_TEXT"

Upvotes: 1

tripleee
tripleee

Reputation: 189618

Some versions of mail have options for this, but they are not universally portable. If your needs are simple, just write your own sendmail wrapper.

cat - MAIL_TEXT << ____HERE | sendmail -oi [email protected]
From: Some Alias <[email protected]>
Subject: MAIL_SUBJECT

____HERE

The empty line after the headers is significant. Sendmail will fill in (what it thinks are) sensible defaults for the headers you don't specify.

It doesn't have to be a proper Sendmail; most MTAs ship a "sendmail" binary which (more or less) supports the traditional Sendmail command-line API.

If you need MIME or other bells and whistles, maybe look at mutt instead.

Upvotes: 0

Related Questions