Send e-mail with multiple attachments using command line and sendmail
14,048
Solution 1
uuencode
attachemnts and send via sendmail
Sending MIME attachemnts is better.
uuencode
is simpler to implement in scripts but email some clients DO NOT support it.
attachments="attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf"
recipient='[email protected]'
# () sub sub-shell should generate email headers and body for sendmail to send
(
# generate email headers and begin of the body asspecified by HERE document
cat - <<END
Subject: This is the subject
From: [email protected]
To: $recipient
Content-Type: text/plain
This is the body.
END
# generate/append uuencoded attachments
for attachment in $attachments ; do
uuencode $attachment $attachment
done
) | /usr/sbin/sendmail -i -- $recipient
Solution 2
For what its worth, mailx
also works well.
mailx -s "Subject" -a attachment1 -a attachement2 -a attachment3 [email protected] < /dev/null
Author by
user2656114
Updated on June 17, 2022Comments
-
user2656114 almost 2 years
Is it possible to send multiple attachments with
uuencode
andsendmail
?In a script I have a variable containing the files that need to be attached to a single e-mail like:
$attachments=attachment_1.pdf attachment_2.pdf attachment_3.pdf attachment_4.pdf
Also a
$template
variable like:$template="Subject: This is the subject From: [email protected] To: %s Content-Type: text/plain This is the body. "
I have come up with:
printf "$template" "$recipient" | sendmail -oi -t
Somewhere within this I must attach everything in the
$attachments
variable? -
SNR about 3 yearsworked for me but it's sending some noname file as an attachment. how to avoid this?