How to send mail from Linux with To, From, Subject, and File Attachment

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to be able to send mail from a bash script with the following:
To Address, From Address, Subject, Body Text, and File Attachment
I can send everything just perfectly using mutt EXCEPT, no matter what I do the "From" address does not get set correctly:
e.g. mutt -e "my_hdr From:$FROM")...
I can also use sendmail or mailx but I can't seem to get the file attachment and the body text correct.
e.g. sendmail -t -a file
mutt sendmail
add a comment |Â
up vote
0
down vote
favorite
I need to be able to send mail from a bash script with the following:
To Address, From Address, Subject, Body Text, and File Attachment
I can send everything just perfectly using mutt EXCEPT, no matter what I do the "From" address does not get set correctly:
e.g. mutt -e "my_hdr From:$FROM")...
I can also use sendmail or mailx but I can't seem to get the file attachment and the body text correct.
e.g. sendmail -t -a file
mutt sendmail
The body comes from stdin. Any attachments you need to encode yourself and add to the body.
â Ignacio Vazquez-Abrams
Jun 7 at 17:45
For the sendmail approach, see unix.stackexchange.com/q/160200/4667
â glenn jackman
Jun 7 at 18:18
Some implementations ofmailhave a-aargument which can be used to attach files, e. g.mail -s "Subject goes here" -a /path/to/file.tgz somebody@example.com < /path/to/messagebody.
â DopeGhoti
Jun 7 at 19:48
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to be able to send mail from a bash script with the following:
To Address, From Address, Subject, Body Text, and File Attachment
I can send everything just perfectly using mutt EXCEPT, no matter what I do the "From" address does not get set correctly:
e.g. mutt -e "my_hdr From:$FROM")...
I can also use sendmail or mailx but I can't seem to get the file attachment and the body text correct.
e.g. sendmail -t -a file
mutt sendmail
I need to be able to send mail from a bash script with the following:
To Address, From Address, Subject, Body Text, and File Attachment
I can send everything just perfectly using mutt EXCEPT, no matter what I do the "From" address does not get set correctly:
e.g. mutt -e "my_hdr From:$FROM")...
I can also use sendmail or mailx but I can't seem to get the file attachment and the body text correct.
e.g. sendmail -t -a file
mutt sendmail
edited Jun 7 at 18:15
Jeff Schaller
30.9k846105
30.9k846105
asked Jun 7 at 17:44
SSDdude
544
544
The body comes from stdin. Any attachments you need to encode yourself and add to the body.
â Ignacio Vazquez-Abrams
Jun 7 at 17:45
For the sendmail approach, see unix.stackexchange.com/q/160200/4667
â glenn jackman
Jun 7 at 18:18
Some implementations ofmailhave a-aargument which can be used to attach files, e. g.mail -s "Subject goes here" -a /path/to/file.tgz somebody@example.com < /path/to/messagebody.
â DopeGhoti
Jun 7 at 19:48
add a comment |Â
The body comes from stdin. Any attachments you need to encode yourself and add to the body.
â Ignacio Vazquez-Abrams
Jun 7 at 17:45
For the sendmail approach, see unix.stackexchange.com/q/160200/4667
â glenn jackman
Jun 7 at 18:18
Some implementations ofmailhave a-aargument which can be used to attach files, e. g.mail -s "Subject goes here" -a /path/to/file.tgz somebody@example.com < /path/to/messagebody.
â DopeGhoti
Jun 7 at 19:48
The body comes from stdin. Any attachments you need to encode yourself and add to the body.
â Ignacio Vazquez-Abrams
Jun 7 at 17:45
The body comes from stdin. Any attachments you need to encode yourself and add to the body.
â Ignacio Vazquez-Abrams
Jun 7 at 17:45
For the sendmail approach, see unix.stackexchange.com/q/160200/4667
â glenn jackman
Jun 7 at 18:18
For the sendmail approach, see unix.stackexchange.com/q/160200/4667
â glenn jackman
Jun 7 at 18:18
Some implementations of
mail have a -a argument which can be used to attach files, e. g. mail -s "Subject goes here" -a /path/to/file.tgz somebody@example.com < /path/to/messagebody.â DopeGhoti
Jun 7 at 19:48
Some implementations of
mail have a -a argument which can be used to attach files, e. g. mail -s "Subject goes here" -a /path/to/file.tgz somebody@example.com < /path/to/messagebody.â DopeGhoti
Jun 7 at 19:48
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
0
down vote
You can set the From: and other settings in a configuration file. The body must come from standard input.
For example:
cat msg.txt | mutt to@example.com -F ~/.mutt_settings -s "this is my subject" -a file.zip
For the settings file, copy an already working settings file and change the From line:
my_hdr From: Super Man <me@example.com>
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
add a comment |Â
up vote
0
down vote
There are two methods usually of building emails, over the system aka compatible sendmail interface or via PORT 25/TCP. No matter what programming language or scripting language you are using, you will find examples for both cases.
It is known that when using the compatible sendmail interface, i.e. directly via the system, and not via port 25, only root can change the From Field.
When building emails from PORT 25/TCP, you usually can pretty much build email body with any FROM: field as you wish.
Other option is setting it globally as @Juancho says for one server, but then you are limited to only one and one From:
The other option is sending them as root, which I do not advise.
add a comment |Â
up vote
0
down vote
This is the code required to override .muttrc from a script...
echo "THIS IS THE BODY" | mutt -e "send-hook . "my_hdr From: TechSupport <TechSupport@SSDdude.com>"" -s "THIS IS THE SUBJECT" recipient@somewhere.com -a test.log
THANKS!
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can set the From: and other settings in a configuration file. The body must come from standard input.
For example:
cat msg.txt | mutt to@example.com -F ~/.mutt_settings -s "this is my subject" -a file.zip
For the settings file, copy an already working settings file and change the From line:
my_hdr From: Super Man <me@example.com>
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
add a comment |Â
up vote
0
down vote
You can set the From: and other settings in a configuration file. The body must come from standard input.
For example:
cat msg.txt | mutt to@example.com -F ~/.mutt_settings -s "this is my subject" -a file.zip
For the settings file, copy an already working settings file and change the From line:
my_hdr From: Super Man <me@example.com>
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can set the From: and other settings in a configuration file. The body must come from standard input.
For example:
cat msg.txt | mutt to@example.com -F ~/.mutt_settings -s "this is my subject" -a file.zip
For the settings file, copy an already working settings file and change the From line:
my_hdr From: Super Man <me@example.com>
You can set the From: and other settings in a configuration file. The body must come from standard input.
For example:
cat msg.txt | mutt to@example.com -F ~/.mutt_settings -s "this is my subject" -a file.zip
For the settings file, copy an already working settings file and change the From line:
my_hdr From: Super Man <me@example.com>
answered Jun 7 at 18:17
Juancho
51625
51625
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
add a comment |Â
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
Hello Juancho... you mention a configuration file but I am not sure what you mean. If you are talking about .muttrc I cannot edit this due to co. policy. Can you elaborate further? I am very new at this! Thanks!
â SSDdude
Jun 7 at 19:40
add a comment |Â
up vote
0
down vote
There are two methods usually of building emails, over the system aka compatible sendmail interface or via PORT 25/TCP. No matter what programming language or scripting language you are using, you will find examples for both cases.
It is known that when using the compatible sendmail interface, i.e. directly via the system, and not via port 25, only root can change the From Field.
When building emails from PORT 25/TCP, you usually can pretty much build email body with any FROM: field as you wish.
Other option is setting it globally as @Juancho says for one server, but then you are limited to only one and one From:
The other option is sending them as root, which I do not advise.
add a comment |Â
up vote
0
down vote
There are two methods usually of building emails, over the system aka compatible sendmail interface or via PORT 25/TCP. No matter what programming language or scripting language you are using, you will find examples for both cases.
It is known that when using the compatible sendmail interface, i.e. directly via the system, and not via port 25, only root can change the From Field.
When building emails from PORT 25/TCP, you usually can pretty much build email body with any FROM: field as you wish.
Other option is setting it globally as @Juancho says for one server, but then you are limited to only one and one From:
The other option is sending them as root, which I do not advise.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
There are two methods usually of building emails, over the system aka compatible sendmail interface or via PORT 25/TCP. No matter what programming language or scripting language you are using, you will find examples for both cases.
It is known that when using the compatible sendmail interface, i.e. directly via the system, and not via port 25, only root can change the From Field.
When building emails from PORT 25/TCP, you usually can pretty much build email body with any FROM: field as you wish.
Other option is setting it globally as @Juancho says for one server, but then you are limited to only one and one From:
The other option is sending them as root, which I do not advise.
There are two methods usually of building emails, over the system aka compatible sendmail interface or via PORT 25/TCP. No matter what programming language or scripting language you are using, you will find examples for both cases.
It is known that when using the compatible sendmail interface, i.e. directly via the system, and not via port 25, only root can change the From Field.
When building emails from PORT 25/TCP, you usually can pretty much build email body with any FROM: field as you wish.
Other option is setting it globally as @Juancho says for one server, but then you are limited to only one and one From:
The other option is sending them as root, which I do not advise.
answered Jun 7 at 18:19
Rui F Ribeiro
34.4k1268113
34.4k1268113
add a comment |Â
add a comment |Â
up vote
0
down vote
This is the code required to override .muttrc from a script...
echo "THIS IS THE BODY" | mutt -e "send-hook . "my_hdr From: TechSupport <TechSupport@SSDdude.com>"" -s "THIS IS THE SUBJECT" recipient@somewhere.com -a test.log
THANKS!
add a comment |Â
up vote
0
down vote
This is the code required to override .muttrc from a script...
echo "THIS IS THE BODY" | mutt -e "send-hook . "my_hdr From: TechSupport <TechSupport@SSDdude.com>"" -s "THIS IS THE SUBJECT" recipient@somewhere.com -a test.log
THANKS!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This is the code required to override .muttrc from a script...
echo "THIS IS THE BODY" | mutt -e "send-hook . "my_hdr From: TechSupport <TechSupport@SSDdude.com>"" -s "THIS IS THE SUBJECT" recipient@somewhere.com -a test.log
THANKS!
This is the code required to override .muttrc from a script...
echo "THIS IS THE BODY" | mutt -e "send-hook . "my_hdr From: TechSupport <TechSupport@SSDdude.com>"" -s "THIS IS THE SUBJECT" recipient@somewhere.com -a test.log
THANKS!
answered Jun 7 at 21:09
SSDdude
544
544
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448479%2fhow-to-send-mail-from-linux-with-to-from-subject-and-file-attachment%23new-answer', 'question_page');
);
Post as a guest
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
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
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
The body comes from stdin. Any attachments you need to encode yourself and add to the body.
â Ignacio Vazquez-Abrams
Jun 7 at 17:45
For the sendmail approach, see unix.stackexchange.com/q/160200/4667
â glenn jackman
Jun 7 at 18:18
Some implementations of
mailhave a-aargument which can be used to attach files, e. g.mail -s "Subject goes here" -a /path/to/file.tgz somebody@example.com < /path/to/messagebody.â DopeGhoti
Jun 7 at 19:48