Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending simple message body + file attachment using Linux Mailx [duplicate]

Tags:

shell

mailx

I am writing a shell script to send an email using Linux Mailx, the email must contain a file attachment and a message body.

Currently sending an email with an attachment:

output.txt | mail -s "Daily Monitoring" [email protected]

I wish to add a message body. How should i?

Linux Mailx:

mail [-eIinv] [-a header] [-b addr] [-c addr] [-s subj] to-addr
like image 692
Oh Chin Boon Avatar asked Nov 29 '11 17:11

Oh Chin Boon


People also ask

How do I write a message body in mailx?

Method 2 : -a switch in mailx command The -a options is easier to use that the uuencode command. The above command will print a new blank line. Type the body of the message here and press [ctrl] + [d] to send. This will attach the file to the outbound email correctly with proper Content-Type and boundary headers.

What command is used to send mail from a Unix system with attachment file XYZ txt to user ABC?

To send an attachment from the email, use uuencode command.


2 Answers

The usual way is to use uuencode for the attachments and echo for the body:

(uuencode output.txt output.txt; echo "Body of text") | mailx -s 'Subject' [email protected]

For Solaris and AIX, you may need to put the echo statement first:

(echo "Body of text"; uuencode output.txt output.txt) | mailx -s 'Subject' [email protected]
like image 99
Johnsyweb Avatar answered Sep 20 '22 06:09

Johnsyweb


The best way is to use mpack!

mpack -s "Subject" -d "./body.txt" "././image.png" mailadress

mpack - subject - body - attachment - mailadress

like image 37
Vautschi Avatar answered Sep 24 '22 06:09

Vautschi