How set the From email address for mailx command?
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
add a comment |
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
add a comment |
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
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
shell email solaris ksh mailx
edited Jun 6 '14 at 2:36
sth
164k40241332
164k40241332
asked Aug 18 '09 at 22:43
AieshaDot
3953513
3953513
add a comment |
add a comment |
8 Answers
8
active
oldest
votes
You can use the "-r" option to set the sender address:
mailx -r me@example.com -s ...
@sth thx that worked!
– AieshaDot
Aug 18 '09 at 23:03
add a comment |
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>"
1
In my case, onan Ubuntu 16.04, using your-a
option, it does show theFoo Bar
name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of thefoo.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
add a comment |
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!
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
add a comment |
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 --
.
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 installedbsd-mailx
versionVersion: 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
add a comment |
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.
add a comment |
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
add a comment |
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
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You can use the "-r" option to set the sender address:
mailx -r me@example.com -s ...
@sth thx that worked!
– AieshaDot
Aug 18 '09 at 23:03
add a comment |
You can use the "-r" option to set the sender address:
mailx -r me@example.com -s ...
@sth thx that worked!
– AieshaDot
Aug 18 '09 at 23:03
add a comment |
You can use the "-r" option to set the sender address:
mailx -r me@example.com -s ...
You can use the "-r" option to set the sender address:
mailx -r me@example.com -s ...
answered Aug 18 '09 at 22:55
sth
164k40241332
164k40241332
@sth thx that worked!
– AieshaDot
Aug 18 '09 at 23:03
add a comment |
@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
add a comment |
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>"
1
In my case, onan Ubuntu 16.04, using your-a
option, it does show theFoo Bar
name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of thefoo.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
add a comment |
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>"
1
In my case, onan Ubuntu 16.04, using your-a
option, it does show theFoo Bar
name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of thefoo.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
add a comment |
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>"
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>"
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 theFoo Bar
name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of thefoo.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
add a comment |
1
In my case, onan Ubuntu 16.04, using your-a
option, it does show theFoo Bar
name in the received mail, but a reply to the received mail offers my gmail email address, used as smtp login, instead of thefoo.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
add a comment |
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!
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
add a comment |
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!
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
add a comment |
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!
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!
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
add a comment |
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
add a comment |
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 --
.
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 installedbsd-mailx
versionVersion: 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
add a comment |
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 --
.
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 installedbsd-mailx
versionVersion: 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
add a comment |
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 --
.
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 --
.
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 installedbsd-mailx
versionVersion: 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
add a comment |
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 installedbsd-mailx
versionVersion: 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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Sep 25 '14 at 9:43
Neik
183
183
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jun 10 '17 at 8:14
kitschmaster
1,0661013
1,0661013
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered May 21 at 23:39
woohoo
2,1471622
2,1471622
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 22 at 17:58
answered Nov 22 at 16:19
Chris Woods
17511
17511
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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