Sendmail - Attachments & Subjects

Hi All,

Not been around in a while. However I have been all over tinternet (google) for days looking for a solution.

Where I work has decided to use Sendmail on our Linux and Unix estate for sending emails via scripts. So I am hoping to eventually get a working solution for Sendmail and not any other program like mailx or mut.

I have installed sharutils to get uuencode working.

Sends subject

echo "Subject: Test from HOST" | sendmail recipient@domain.com
( echo "Subject: Test from HOST" ) | sendmail recipient@domain.com

Sends Subject & Body

MSG=/tmp/temp.txt
echo "This is in the body of the email" >> $MSG
( echo "Subject: Test from HOST"; cat $MSG ) | sendmail recipient@domain.com

Sends Attachments only

uuencode test.txt test.txt | sendmail recipient@domain.com

However I cannot get Attachments & Subject - which to be honest, does make sense to have.

Both send with Subject only

uuencode test.txt test.txt | ( echo "Subject: Test from HOST" ) | sendmail recipient@domain.com
uuencode test.txt test.txt | echo "Subject: Test from HOST" | sendmail recipient@domain.com

I have also tried the following to get an attachment, Subject & Body, but again this does not work, it sends a .dat file which when opened is just the contents withing the code (below) and nothing else

( echo "to: recipient@domain.com" 
echo "Subject: Test from HOST"
echo "mime-version: 1.0"
echo "content-type: multiple/related; boundary=messageBoundary"
echo ""
echo "--messageBoundary"
echo "contrent-type: text/plain"
echo ""
echo "Please find the document atttached." 
echo ""
echo "--messageBoundary" 
echo "content-type: text; name=test.txt" 
echo "content-transfer-encoding: base64"
echo ""
openssl base64 < /tmp/test.txt ) | sendmail -t -i

Can anyone help in getting attachments & subjects working with Sendmail or even better, Subject, Body & Attachments

you are missing a final boundary line.
you should be able to find a workable solution if you search 'sendmail' and restrict the output to my posts.

1 Like

Thanks jgt, but I never found what I was looking for via the search.

However, I was able to fix my problem this morning - it's great what a nights sleep can do.

( echo "Subject: Test from HOST"; cat /home/dakelly/message_body.txt; uuencode /home/dakelly/attachment.txt attachment.txt ) | sendmail recipient@domain.com

the above code sends an email with a subject, a body & an attachment... after testing I can add in more attachments as well as long as I add in more

uuencode /path/to/file file_name_to_send; uuencode /path/to/file file_name_to_send;

i couldn't find it on my phone yesterday, but here is the thread I was referring to: https://www.unix.com/shell-programming-and-scripting/274308-mailx-attachment-html-content.html\#neo-top

1 Like