How set the From email address for mailx command?












30














I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx.



Question: How to I set the "From" email address on the mailx command?



Current Code:



echo ${msg_txt} | mailx -s "Script Failure" ${to_email}


Note: The command works fine, however, the "From" is the name of the user I am running the script as and I would like for this to another email address.



How would I accomplish this?










share|improve this question





























    30














    I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx.



    Question: How to I set the "From" email address on the mailx command?



    Current Code:



    echo ${msg_txt} | mailx -s "Script Failure" ${to_email}


    Note: The command works fine, however, the "From" is the name of the user I am running the script as and I would like for this to another email address.



    How would I accomplish this?










    share|improve this question



























      30












      30








      30


      9





      I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx.



      Question: How to I set the "From" email address on the mailx command?



      Current Code:



      echo ${msg_txt} | mailx -s "Script Failure" ${to_email}


      Note: The command works fine, however, the "From" is the name of the user I am running the script as and I would like for this to another email address.



      How would I accomplish this?










      share|improve this question















      I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx.



      Question: How to I set the "From" email address on the mailx command?



      Current Code:



      echo ${msg_txt} | mailx -s "Script Failure" ${to_email}


      Note: The command works fine, however, the "From" is the name of the user I am running the script as and I would like for this to another email address.



      How would I accomplish this?







      shell email solaris ksh mailx






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 6 '14 at 2:36









      sth

      164k40241332




      164k40241332










      asked Aug 18 '09 at 22:43









      AieshaDot

      3953513




      3953513
























          8 Answers
          8






          active

          oldest

          votes


















          36














          You can use the "-r" option to set the sender address:



          mailx -r me@example.com -s ...





          share|improve this answer





















          • @sth thx that worked!
            – AieshaDot
            Aug 18 '09 at 23:03



















          33














          The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.



          -a "From: Foo Bar <foo.bar@someplace.com>"





          share|improve this answer

















          • 1




            In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
            – Stephane
            Jul 3 '17 at 13:48






          • 1




            This should be considered as a proper answer.
            – Denis V
            Apr 12 at 10:01






          • 1




            i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
            – datdinhquoc
            Jun 15 at 4:10



















          22














          In case you also want to include your real name in the from-field, you can use the following format



          mailx -r "me@example.com (My Name)" -s "My Subject" ...


          If you happen to have non-ASCII characters in you name, like My AEÆoeøaaå
          (Æ= C3 86, ø= C3 B8, å= C3 A5), you have to encode them like this:



          mailx -r "me@example.com (My =?utf-8?Q?AE=C3=86oe=C3=B8aa=C3=A5?=)" -s "My Subject" ...


          Hope this can save someone an hour of hard work/research!






          share|improve this answer





















          • In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
            – Josh Kelley
            Apr 1 '14 at 13:25












          • The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
            – peabody
            May 28 '14 at 17:45










          • @Rune Your method returns (My AE??oe??aa??) any idea why?
            – RafaSashi
            May 14 '15 at 12:27












          • @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
            – Rune
            May 15 '15 at 14:27












          • Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
            – Stephane
            Jul 3 '17 at 13:51



















          9














          On debian where bsd-mailx is installed by default, the -r option does not work. However you can use mailx -s subject recipient@abc.com -- -f sender@abc.com instead. According to man page, you can specify sendmail options after --.






          share|improve this answer





















          • Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
            – 4ae1e1
            Nov 18 '14 at 8:56






          • 4




            Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
            – praseodym
            Dec 17 '14 at 13:05










          • I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
            – ssc
            Jan 29 '17 at 13:40












          • On Debian 9 stretch the -r option still works :)
            – woohoo
            Apr 21 at 14:34



















          1














          The package nail provides an enhanced mailx like interface. It includes the -r option.



          On Centos 5 installing the package mailx gives you a program called mail, which doesn't support the mailx options.






          share|improve this answer





























            0














            On macOS Sierra, creating ~/.mailrc with smtp setup did the trick:



            set smtp-use-starttls
            set smtp=smtp://smtp.gmail.com:587
            set smtp-auth=login
            set smtp-auth-user=youremail@gmail.com
            set smtp-auth-password=yourpass


            Then to send mail from CLI:



            echo "your message" | mail -s "your subject" to_email@gmail.com





            share|improve this answer





























              0














              On Ubuntu Bionic 18.04, this works as desired:



              $ echo -e "testing email via yourisp.com from command linennsent on: $(date)" | mailx --append='FROM:Foghorn Leghorn <fleghorn@yourisp.com>' -s "test cli email $(date)" -- recipient@acme.com






              share|improve this answer





























                0














                Just ran into this syntax problem on a CentOS 7 machine.



                On a very old Ubuntu machine running mail, the syntax for a nicely composed email is



                echo -e "$body" | mail -s "$subject" -a "From: Sender Name <$sender>" "$recipient"


                However on a CentOS 7 box which came with mailx installed, it's quite different:



                echo -e "$body" | mail -s "$subject" -S "from=Sender Name <$sender>" "$recipient"


                Consulting man mail indicates that -r is deprecated and the 'From' sender address should now be set directly using -S "variable=value".




                In these and subsequent examples, I'm defining $sender as "Sender Name <sender.address@domain.tld>" and $recipients as "recipient.name@domain.tld" as I do in my bash script.




                You may then find, as I did, that when you try to generate the email's body content in your script at the point of sending the email, you encounter a strange behaviour where the email body is instead attached as a binary file ("ATT00001.bin", "application/octet-stream" or "noname", depending on client).



                This behaviour is how Heirloom mailx handles unrecognised / control characters in text input. (More info: https://access.redhat.com/solutions/1136493, which itself references the mailx man page for the solution.)



                To get around this, I used a method which pipes the generated output through tr before passing to mail, and also specifies the charset of the email:



                echo -e "$body" | tr -d \r | mail -s "$subject" -S "from=$sender" -S "sendcharsets=utf-8,iso-8859-1" "$recipients"


                In my script, I'm also explicitly delaring the locale beforehand as it's run as a cronjob (and cron doesn't inherit environmental variables):



                LANG="en_GB.UTF8" ; export LANG ;


                (An alternate method of setting locales for cronjobs is discussed here)



                More info on these workarounds via https://stackoverflow.com/a/29826988/253139 and https://stackoverflow.com/a/3120227/253139.






                share|improve this answer























                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1296979%2fhow-set-the-from-email-address-for-mailx-command%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  8 Answers
                  8






                  active

                  oldest

                  votes








                  8 Answers
                  8






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  36














                  You can use the "-r" option to set the sender address:



                  mailx -r me@example.com -s ...





                  share|improve this answer





















                  • @sth thx that worked!
                    – AieshaDot
                    Aug 18 '09 at 23:03
















                  36














                  You can use the "-r" option to set the sender address:



                  mailx -r me@example.com -s ...





                  share|improve this answer





















                  • @sth thx that worked!
                    – AieshaDot
                    Aug 18 '09 at 23:03














                  36












                  36








                  36






                  You can use the "-r" option to set the sender address:



                  mailx -r me@example.com -s ...





                  share|improve this answer












                  You can use the "-r" option to set the sender address:



                  mailx -r me@example.com -s ...






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 18 '09 at 22:55









                  sth

                  164k40241332




                  164k40241332












                  • @sth thx that worked!
                    – AieshaDot
                    Aug 18 '09 at 23:03


















                  • @sth thx that worked!
                    – AieshaDot
                    Aug 18 '09 at 23:03
















                  @sth thx that worked!
                  – AieshaDot
                  Aug 18 '09 at 23:03




                  @sth thx that worked!
                  – AieshaDot
                  Aug 18 '09 at 23:03













                  33














                  The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.



                  -a "From: Foo Bar <foo.bar@someplace.com>"





                  share|improve this answer

















                  • 1




                    In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
                    – Stephane
                    Jul 3 '17 at 13:48






                  • 1




                    This should be considered as a proper answer.
                    – Denis V
                    Apr 12 at 10:01






                  • 1




                    i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
                    – datdinhquoc
                    Jun 15 at 4:10
















                  33














                  The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.



                  -a "From: Foo Bar <foo.bar@someplace.com>"





                  share|improve this answer

















                  • 1




                    In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
                    – Stephane
                    Jul 3 '17 at 13:48






                  • 1




                    This should be considered as a proper answer.
                    – Denis V
                    Apr 12 at 10:01






                  • 1




                    i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
                    – datdinhquoc
                    Jun 15 at 4:10














                  33












                  33








                  33






                  The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.



                  -a "From: Foo Bar <foo.bar@someplace.com>"





                  share|improve this answer












                  The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.



                  -a "From: Foo Bar <foo.bar@someplace.com>"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 28 '13 at 14:19









                  Finch_Powers

                  1,72811426




                  1,72811426








                  • 1




                    In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
                    – Stephane
                    Jul 3 '17 at 13:48






                  • 1




                    This should be considered as a proper answer.
                    – Denis V
                    Apr 12 at 10:01






                  • 1




                    i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
                    – datdinhquoc
                    Jun 15 at 4:10














                  • 1




                    In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
                    – Stephane
                    Jul 3 '17 at 13:48






                  • 1




                    This should be considered as a proper answer.
                    – Denis V
                    Apr 12 at 10:01






                  • 1




                    i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
                    – datdinhquoc
                    Jun 15 at 4:10








                  1




                  1




                  In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
                  – Stephane
                  Jul 3 '17 at 13:48




                  In my case, onan Ubuntu 16.04, using your -a option, it does show the Foo Bar name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of the foo.bar@someplace.com one.
                  – Stephane
                  Jul 3 '17 at 13:48




                  1




                  1




                  This should be considered as a proper answer.
                  – Denis V
                  Apr 12 at 10:01




                  This should be considered as a proper answer.
                  – Denis V
                  Apr 12 at 10:01




                  1




                  1




                  i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
                  – datdinhquoc
                  Jun 15 at 4:10




                  i faced error: "From: Foo Bar <foo.bar@someplace.com>" No such file or directory
                  – datdinhquoc
                  Jun 15 at 4:10











                  22














                  In case you also want to include your real name in the from-field, you can use the following format



                  mailx -r "me@example.com (My Name)" -s "My Subject" ...


                  If you happen to have non-ASCII characters in you name, like My AEÆoeøaaå
                  (Æ= C3 86, ø= C3 B8, å= C3 A5), you have to encode them like this:



                  mailx -r "me@example.com (My =?utf-8?Q?AE=C3=86oe=C3=B8aa=C3=A5?=)" -s "My Subject" ...


                  Hope this can save someone an hour of hard work/research!






                  share|improve this answer





















                  • In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
                    – Josh Kelley
                    Apr 1 '14 at 13:25












                  • The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
                    – peabody
                    May 28 '14 at 17:45










                  • @Rune Your method returns (My AE??oe??aa??) any idea why?
                    – RafaSashi
                    May 14 '15 at 12:27












                  • @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
                    – Rune
                    May 15 '15 at 14:27












                  • Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
                    – Stephane
                    Jul 3 '17 at 13:51
















                  22














                  In case you also want to include your real name in the from-field, you can use the following format



                  mailx -r "me@example.com (My Name)" -s "My Subject" ...


                  If you happen to have non-ASCII characters in you name, like My AEÆoeøaaå
                  (Æ= C3 86, ø= C3 B8, å= C3 A5), you have to encode them like this:



                  mailx -r "me@example.com (My =?utf-8?Q?AE=C3=86oe=C3=B8aa=C3=A5?=)" -s "My Subject" ...


                  Hope this can save someone an hour of hard work/research!






                  share|improve this answer





















                  • In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
                    – Josh Kelley
                    Apr 1 '14 at 13:25












                  • The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
                    – peabody
                    May 28 '14 at 17:45










                  • @Rune Your method returns (My AE??oe??aa??) any idea why?
                    – RafaSashi
                    May 14 '15 at 12:27












                  • @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
                    – Rune
                    May 15 '15 at 14:27












                  • Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
                    – Stephane
                    Jul 3 '17 at 13:51














                  22












                  22








                  22






                  In case you also want to include your real name in the from-field, you can use the following format



                  mailx -r "me@example.com (My Name)" -s "My Subject" ...


                  If you happen to have non-ASCII characters in you name, like My AEÆoeøaaå
                  (Æ= C3 86, ø= C3 B8, å= C3 A5), you have to encode them like this:



                  mailx -r "me@example.com (My =?utf-8?Q?AE=C3=86oe=C3=B8aa=C3=A5?=)" -s "My Subject" ...


                  Hope this can save someone an hour of hard work/research!






                  share|improve this answer












                  In case you also want to include your real name in the from-field, you can use the following format



                  mailx -r "me@example.com (My Name)" -s "My Subject" ...


                  If you happen to have non-ASCII characters in you name, like My AEÆoeøaaå
                  (Æ= C3 86, ø= C3 B8, å= C3 A5), you have to encode them like this:



                  mailx -r "me@example.com (My =?utf-8?Q?AE=C3=86oe=C3=B8aa=C3=A5?=)" -s "My Subject" ...


                  Hope this can save someone an hour of hard work/research!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 '12 at 18:10









                  Rune

                  6381621




                  6381621












                  • In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
                    – Josh Kelley
                    Apr 1 '14 at 13:25












                  • The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
                    – peabody
                    May 28 '14 at 17:45










                  • @Rune Your method returns (My AE??oe??aa??) any idea why?
                    – RafaSashi
                    May 14 '15 at 12:27












                  • @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
                    – Rune
                    May 15 '15 at 14:27












                  • Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
                    – Stephane
                    Jul 3 '17 at 13:51


















                  • In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
                    – Josh Kelley
                    Apr 1 '14 at 13:25












                  • The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
                    – peabody
                    May 28 '14 at 17:45










                  • @Rune Your method returns (My AE??oe??aa??) any idea why?
                    – RafaSashi
                    May 14 '15 at 12:27












                  • @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
                    – Rune
                    May 15 '15 at 14:27












                  • Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
                    – Stephane
                    Jul 3 '17 at 13:51
















                  In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
                  – Josh Kelley
                  Apr 1 '14 at 13:25






                  In case anyone's curious, the =?utf-8?...?= bit is a MIME encoded-word.
                  – Josh Kelley
                  Apr 1 '14 at 13:25














                  The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
                  – peabody
                  May 28 '14 at 17:45




                  The real name part of this doesn't work for me on solaris. The message successfully sends and has the proper email from, but each email I send the from is stripped down just to the email address.
                  – peabody
                  May 28 '14 at 17:45












                  @Rune Your method returns (My AE??oe??aa??) any idea why?
                  – RafaSashi
                  May 14 '15 at 12:27






                  @Rune Your method returns (My AE??oe??aa??) any idea why?
                  – RafaSashi
                  May 14 '15 at 12:27














                  @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
                  – Rune
                  May 15 '15 at 14:27






                  @RafaSashi I'm guessing this is because your system is not set up to show UTF-8 characters (2-byte Norwegian characters in this case). On my Norwegian (UTF-8) system it reads "my AEÆoeøaaå"
                  – Rune
                  May 15 '15 at 14:27














                  Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
                  – Stephane
                  Jul 3 '17 at 13:51




                  Adding the -a "Content-Type: text/plain; charset=UTF-8" header solved my UTF-8 letters issue. Now the é is properly displayed.
                  – Stephane
                  Jul 3 '17 at 13:51











                  9














                  On debian where bsd-mailx is installed by default, the -r option does not work. However you can use mailx -s subject recipient@abc.com -- -f sender@abc.com instead. According to man page, you can specify sendmail options after --.






                  share|improve this answer





















                  • Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
                    – 4ae1e1
                    Nov 18 '14 at 8:56






                  • 4




                    Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
                    – praseodym
                    Dec 17 '14 at 13:05










                  • I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
                    – ssc
                    Jan 29 '17 at 13:40












                  • On Debian 9 stretch the -r option still works :)
                    – woohoo
                    Apr 21 at 14:34
















                  9














                  On debian where bsd-mailx is installed by default, the -r option does not work. However you can use mailx -s subject recipient@abc.com -- -f sender@abc.com instead. According to man page, you can specify sendmail options after --.






                  share|improve this answer





















                  • Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
                    – 4ae1e1
                    Nov 18 '14 at 8:56






                  • 4




                    Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
                    – praseodym
                    Dec 17 '14 at 13:05










                  • I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
                    – ssc
                    Jan 29 '17 at 13:40












                  • On Debian 9 stretch the -r option still works :)
                    – woohoo
                    Apr 21 at 14:34














                  9












                  9








                  9






                  On debian where bsd-mailx is installed by default, the -r option does not work. However you can use mailx -s subject recipient@abc.com -- -f sender@abc.com instead. According to man page, you can specify sendmail options after --.






                  share|improve this answer












                  On debian where bsd-mailx is installed by default, the -r option does not work. However you can use mailx -s subject recipient@abc.com -- -f sender@abc.com instead. According to man page, you can specify sendmail options after --.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 26 '13 at 20:29









                  Marki555

                  3,96722144




                  3,96722144












                  • Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
                    – 4ae1e1
                    Nov 18 '14 at 8:56






                  • 4




                    Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
                    – praseodym
                    Dec 17 '14 at 13:05










                  • I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
                    – ssc
                    Jan 29 '17 at 13:40












                  • On Debian 9 stretch the -r option still works :)
                    – woohoo
                    Apr 21 at 14:34


















                  • Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
                    – 4ae1e1
                    Nov 18 '14 at 8:56






                  • 4




                    Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
                    – praseodym
                    Dec 17 '14 at 13:05










                  • I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
                    – ssc
                    Jan 29 '17 at 13:40












                  • On Debian 9 stretch the -r option still works :)
                    – woohoo
                    Apr 21 at 14:34
















                  Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
                  – 4ae1e1
                  Nov 18 '14 at 8:56




                  Thanks for the tip, guess I should have read the synopsis in more detail. Unfortunately stuck with horrible bsdutils, glad to have a workaround.
                  – 4ae1e1
                  Nov 18 '14 at 8:56




                  4




                  4




                  Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
                  – praseodym
                  Dec 17 '14 at 13:05




                  Unfortunately the DSA 3104-1 security update broke this method. Instead, the heirloom-mailx package can be installed, which does provide a -r option.
                  – praseodym
                  Dec 17 '14 at 13:05












                  I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
                  – ssc
                  Jan 29 '17 at 13:40






                  I just installed bsd-mailx version Version: 8.1.2-0.20160123cvs-2, albeit on an Ubuntu 16.04 system; the -r option works.
                  – ssc
                  Jan 29 '17 at 13:40














                  On Debian 9 stretch the -r option still works :)
                  – woohoo
                  Apr 21 at 14:34




                  On Debian 9 stretch the -r option still works :)
                  – woohoo
                  Apr 21 at 14:34











                  1














                  The package nail provides an enhanced mailx like interface. It includes the -r option.



                  On Centos 5 installing the package mailx gives you a program called mail, which doesn't support the mailx options.






                  share|improve this answer


























                    1














                    The package nail provides an enhanced mailx like interface. It includes the -r option.



                    On Centos 5 installing the package mailx gives you a program called mail, which doesn't support the mailx options.






                    share|improve this answer
























                      1












                      1








                      1






                      The package nail provides an enhanced mailx like interface. It includes the -r option.



                      On Centos 5 installing the package mailx gives you a program called mail, which doesn't support the mailx options.






                      share|improve this answer












                      The package nail provides an enhanced mailx like interface. It includes the -r option.



                      On Centos 5 installing the package mailx gives you a program called mail, which doesn't support the mailx options.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 25 '14 at 9:43









                      Neik

                      183




                      183























                          0














                          On macOS Sierra, creating ~/.mailrc with smtp setup did the trick:



                          set smtp-use-starttls
                          set smtp=smtp://smtp.gmail.com:587
                          set smtp-auth=login
                          set smtp-auth-user=youremail@gmail.com
                          set smtp-auth-password=yourpass


                          Then to send mail from CLI:



                          echo "your message" | mail -s "your subject" to_email@gmail.com





                          share|improve this answer


























                            0














                            On macOS Sierra, creating ~/.mailrc with smtp setup did the trick:



                            set smtp-use-starttls
                            set smtp=smtp://smtp.gmail.com:587
                            set smtp-auth=login
                            set smtp-auth-user=youremail@gmail.com
                            set smtp-auth-password=yourpass


                            Then to send mail from CLI:



                            echo "your message" | mail -s "your subject" to_email@gmail.com





                            share|improve this answer
























                              0












                              0








                              0






                              On macOS Sierra, creating ~/.mailrc with smtp setup did the trick:



                              set smtp-use-starttls
                              set smtp=smtp://smtp.gmail.com:587
                              set smtp-auth=login
                              set smtp-auth-user=youremail@gmail.com
                              set smtp-auth-password=yourpass


                              Then to send mail from CLI:



                              echo "your message" | mail -s "your subject" to_email@gmail.com





                              share|improve this answer












                              On macOS Sierra, creating ~/.mailrc with smtp setup did the trick:



                              set smtp-use-starttls
                              set smtp=smtp://smtp.gmail.com:587
                              set smtp-auth=login
                              set smtp-auth-user=youremail@gmail.com
                              set smtp-auth-password=yourpass


                              Then to send mail from CLI:



                              echo "your message" | mail -s "your subject" to_email@gmail.com






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jun 10 '17 at 8:14









                              kitschmaster

                              1,0661013




                              1,0661013























                                  0














                                  On Ubuntu Bionic 18.04, this works as desired:



                                  $ echo -e "testing email via yourisp.com from command linennsent on: $(date)" | mailx --append='FROM:Foghorn Leghorn <fleghorn@yourisp.com>' -s "test cli email $(date)" -- recipient@acme.com






                                  share|improve this answer


























                                    0














                                    On Ubuntu Bionic 18.04, this works as desired:



                                    $ echo -e "testing email via yourisp.com from command linennsent on: $(date)" | mailx --append='FROM:Foghorn Leghorn <fleghorn@yourisp.com>' -s "test cli email $(date)" -- recipient@acme.com






                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      On Ubuntu Bionic 18.04, this works as desired:



                                      $ echo -e "testing email via yourisp.com from command linennsent on: $(date)" | mailx --append='FROM:Foghorn Leghorn <fleghorn@yourisp.com>' -s "test cli email $(date)" -- recipient@acme.com






                                      share|improve this answer












                                      On Ubuntu Bionic 18.04, this works as desired:



                                      $ echo -e "testing email via yourisp.com from command linennsent on: $(date)" | mailx --append='FROM:Foghorn Leghorn <fleghorn@yourisp.com>' -s "test cli email $(date)" -- recipient@acme.com







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 21 at 23:39









                                      woohoo

                                      2,1471622




                                      2,1471622























                                          0














                                          Just ran into this syntax problem on a CentOS 7 machine.



                                          On a very old Ubuntu machine running mail, the syntax for a nicely composed email is



                                          echo -e "$body" | mail -s "$subject" -a "From: Sender Name <$sender>" "$recipient"


                                          However on a CentOS 7 box which came with mailx installed, it's quite different:



                                          echo -e "$body" | mail -s "$subject" -S "from=Sender Name <$sender>" "$recipient"


                                          Consulting man mail indicates that -r is deprecated and the 'From' sender address should now be set directly using -S "variable=value".




                                          In these and subsequent examples, I'm defining $sender as "Sender Name <sender.address@domain.tld>" and $recipients as "recipient.name@domain.tld" as I do in my bash script.




                                          You may then find, as I did, that when you try to generate the email's body content in your script at the point of sending the email, you encounter a strange behaviour where the email body is instead attached as a binary file ("ATT00001.bin", "application/octet-stream" or "noname", depending on client).



                                          This behaviour is how Heirloom mailx handles unrecognised / control characters in text input. (More info: https://access.redhat.com/solutions/1136493, which itself references the mailx man page for the solution.)



                                          To get around this, I used a method which pipes the generated output through tr before passing to mail, and also specifies the charset of the email:



                                          echo -e "$body" | tr -d \r | mail -s "$subject" -S "from=$sender" -S "sendcharsets=utf-8,iso-8859-1" "$recipients"


                                          In my script, I'm also explicitly delaring the locale beforehand as it's run as a cronjob (and cron doesn't inherit environmental variables):



                                          LANG="en_GB.UTF8" ; export LANG ;


                                          (An alternate method of setting locales for cronjobs is discussed here)



                                          More info on these workarounds via https://stackoverflow.com/a/29826988/253139 and https://stackoverflow.com/a/3120227/253139.






                                          share|improve this answer




























                                            0














                                            Just ran into this syntax problem on a CentOS 7 machine.



                                            On a very old Ubuntu machine running mail, the syntax for a nicely composed email is



                                            echo -e "$body" | mail -s "$subject" -a "From: Sender Name <$sender>" "$recipient"


                                            However on a CentOS 7 box which came with mailx installed, it's quite different:



                                            echo -e "$body" | mail -s "$subject" -S "from=Sender Name <$sender>" "$recipient"


                                            Consulting man mail indicates that -r is deprecated and the 'From' sender address should now be set directly using -S "variable=value".




                                            In these and subsequent examples, I'm defining $sender as "Sender Name <sender.address@domain.tld>" and $recipients as "recipient.name@domain.tld" as I do in my bash script.




                                            You may then find, as I did, that when you try to generate the email's body content in your script at the point of sending the email, you encounter a strange behaviour where the email body is instead attached as a binary file ("ATT00001.bin", "application/octet-stream" or "noname", depending on client).



                                            This behaviour is how Heirloom mailx handles unrecognised / control characters in text input. (More info: https://access.redhat.com/solutions/1136493, which itself references the mailx man page for the solution.)



                                            To get around this, I used a method which pipes the generated output through tr before passing to mail, and also specifies the charset of the email:



                                            echo -e "$body" | tr -d \r | mail -s "$subject" -S "from=$sender" -S "sendcharsets=utf-8,iso-8859-1" "$recipients"


                                            In my script, I'm also explicitly delaring the locale beforehand as it's run as a cronjob (and cron doesn't inherit environmental variables):



                                            LANG="en_GB.UTF8" ; export LANG ;


                                            (An alternate method of setting locales for cronjobs is discussed here)



                                            More info on these workarounds via https://stackoverflow.com/a/29826988/253139 and https://stackoverflow.com/a/3120227/253139.






                                            share|improve this answer


























                                              0












                                              0








                                              0






                                              Just ran into this syntax problem on a CentOS 7 machine.



                                              On a very old Ubuntu machine running mail, the syntax for a nicely composed email is



                                              echo -e "$body" | mail -s "$subject" -a "From: Sender Name <$sender>" "$recipient"


                                              However on a CentOS 7 box which came with mailx installed, it's quite different:



                                              echo -e "$body" | mail -s "$subject" -S "from=Sender Name <$sender>" "$recipient"


                                              Consulting man mail indicates that -r is deprecated and the 'From' sender address should now be set directly using -S "variable=value".




                                              In these and subsequent examples, I'm defining $sender as "Sender Name <sender.address@domain.tld>" and $recipients as "recipient.name@domain.tld" as I do in my bash script.




                                              You may then find, as I did, that when you try to generate the email's body content in your script at the point of sending the email, you encounter a strange behaviour where the email body is instead attached as a binary file ("ATT00001.bin", "application/octet-stream" or "noname", depending on client).



                                              This behaviour is how Heirloom mailx handles unrecognised / control characters in text input. (More info: https://access.redhat.com/solutions/1136493, which itself references the mailx man page for the solution.)



                                              To get around this, I used a method which pipes the generated output through tr before passing to mail, and also specifies the charset of the email:



                                              echo -e "$body" | tr -d \r | mail -s "$subject" -S "from=$sender" -S "sendcharsets=utf-8,iso-8859-1" "$recipients"


                                              In my script, I'm also explicitly delaring the locale beforehand as it's run as a cronjob (and cron doesn't inherit environmental variables):



                                              LANG="en_GB.UTF8" ; export LANG ;


                                              (An alternate method of setting locales for cronjobs is discussed here)



                                              More info on these workarounds via https://stackoverflow.com/a/29826988/253139 and https://stackoverflow.com/a/3120227/253139.






                                              share|improve this answer














                                              Just ran into this syntax problem on a CentOS 7 machine.



                                              On a very old Ubuntu machine running mail, the syntax for a nicely composed email is



                                              echo -e "$body" | mail -s "$subject" -a "From: Sender Name <$sender>" "$recipient"


                                              However on a CentOS 7 box which came with mailx installed, it's quite different:



                                              echo -e "$body" | mail -s "$subject" -S "from=Sender Name <$sender>" "$recipient"


                                              Consulting man mail indicates that -r is deprecated and the 'From' sender address should now be set directly using -S "variable=value".




                                              In these and subsequent examples, I'm defining $sender as "Sender Name <sender.address@domain.tld>" and $recipients as "recipient.name@domain.tld" as I do in my bash script.




                                              You may then find, as I did, that when you try to generate the email's body content in your script at the point of sending the email, you encounter a strange behaviour where the email body is instead attached as a binary file ("ATT00001.bin", "application/octet-stream" or "noname", depending on client).



                                              This behaviour is how Heirloom mailx handles unrecognised / control characters in text input. (More info: https://access.redhat.com/solutions/1136493, which itself references the mailx man page for the solution.)



                                              To get around this, I used a method which pipes the generated output through tr before passing to mail, and also specifies the charset of the email:



                                              echo -e "$body" | tr -d \r | mail -s "$subject" -S "from=$sender" -S "sendcharsets=utf-8,iso-8859-1" "$recipients"


                                              In my script, I'm also explicitly delaring the locale beforehand as it's run as a cronjob (and cron doesn't inherit environmental variables):



                                              LANG="en_GB.UTF8" ; export LANG ;


                                              (An alternate method of setting locales for cronjobs is discussed here)



                                              More info on these workarounds via https://stackoverflow.com/a/29826988/253139 and https://stackoverflow.com/a/3120227/253139.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 22 at 17:58

























                                              answered Nov 22 at 16:19









                                              Chris Woods

                                              17511




                                              17511






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1296979%2fhow-set-the-from-email-address-for-mailx-command%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Berounka

                                                  Sphinx de Gizeh

                                                  Different font size/position of beamer's navigation symbols template's content depending on regular/plain...