KornShell code (ksh) for sending attachments with mailx and uuencode?

I need to attach a file with mailx, but at the moment I have no success.

Here is my code:

subject="Something happened"
to="somebody@somewhere.com"
body="Attachment Test"
attachment=/path/to/somefile.csv

uuencode $attachment | mailx -s "$subject" "$to" << EOF

The message is ready to be sent with the following file or link attachments:

somefile.csv

Note: To protect against computer viruses, e-mail programs may prevent
sending or receiving certain types of file attachments.  Check your
e-mail security settings to determine how attachments are handled.

EOF

Any feedback would be highly appreciated.


Update I added a var application to avoid having to use this path every time.

+3
source share
2 answers

You need to execute both the text of your message and the attachment with uuencoded:

$ subject="Something happened"
$ to="somebody@somewhere.com"
$ body="Attachment Test"
$ attachment=/path/to/somefile.csv
$
$ cat >msg.txt <<EOF
> The message is ready to be sent with the following file or link attachments:
>
> somefile.csv
>
> Note: To protect against computer viruses, e-mail programs may prevent
> sending or receiving certain types of file attachments.  Check your
> e-mail security settings to determine how attachments are handled.
>
> EOF
$ ( cat msg.txt ; uuencode $attachment somefile.csv) | mailx -s "$subject" "$to"

There are various ways to provide the text of the message, this is just an example close to your original question. If the message should be reused, it makes sense to just save it in a file and use this file.

+3
source

, , .

  • , , uuencoded - . .

  • /: uuencode mailx, .

  • uuencode: , , , . , , , . -m base64 . mailx.

mpack, , .

, - :

cat <<EOF | ( cat -; uuencode -m /path/to/somefile.csv /path/to/somefile.csv; ) | mailx -s "$subject" "$to" 
place your message from the here block in your example here
EOF

... , , temp.

+1

Source: https://habr.com/ru/post/1697157/


All Articles