You can even use it to send attachements. For that you would need install a utility "uuencode". Package name for this is "sharutils"( in linux).
Syntax for sending mail with attachment is :
uuencode filename filename | mailx -s " hi " user@domain.com
Here first filename is name of the file you want to send as an attachment and second filename would become the name of the file when it gets attached to the mail. You can keep it same or different as per your convenience.
-s option with mailx specifies the subject of the mail.
For example, if I have a file named " test" which I want to send, I can send it as follows:
uuencode test test | mail -s " hi " user@domain.com
However, "uuencode" sends file in binary format. There are some email clients which cannot decode it . So instead of attachment you would find an encoded text written in email.
To overcome , there is an another package "mutt" , which can be used to send email attachment from terminal.
Syntax for "mutt" is :
mutt -s "hi " -a file -- user@domain.com < /dev/null
Here " -s " option specifies subject of the mail
"-a" option provides the file to be attached.
You can also attach multiple files with mail using "mutt" as :
mutt -s "hi " -a file1 file2 -- user@domain.com < /dev/null
Make sure to separate attachments and destination address with "--"(two hyphen signs)
If you dont provide "/dev/null " as input to "mutt", it will open up in an interactive mode and ask some inputs . However, if you are using it in shell script , provide "/dev/null" as an input.
No comments:
Post a Comment