1

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 ?

VivienG
  • 2,143
  • 3
  • 24
  • 43
Sameervb
  • 381
  • 3
  • 5
  • 15
  • 1
    [so] is about proramming, your question is not; you might try [su], where you can find e.g. [this](http://superuser.com/questions/583210/) – umläute Mar 06 '14 at 12:41

3 Answers3

1

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"
nothrow
  • 15,882
  • 9
  • 57
  • 104
0

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 tom@example.com
From: Some Alias <process-noeeply@example.com>
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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

-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''."]

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Amit May 04 '22 at 14:19