begin 644 in received message sent with sendmail

I send an attachment 123.pdf using the below script:-

<< script content >>

#!/usr/bin/ksh

/usr/lib/sendmail -C sendmail.cf abc@gmail.com << END
Subject: HELLO
`uuencode 123.pdf 123.pdf`
END

However, the message I got in gmail look like:-

begin 644 123.pdf
... garbage ...
... many lines ...
... garbage ...

end

Anyone knows what can I do in the sending side so that the receiving side can display the correct attachment in gmail? Thanks...

uuencode 123.pdf 123.pdf | sendmail ...

You are not sending the file as an attachment to your email. You are embedding it within your email.

Do a web search for "shell script mail MIME attachment" and you will find lots of examples of how to mail a message with a MIME attachment.

I modified the script and gmail can show the attachment. However, the pdf cannot be opened. It seems to be damaged. Thanks.

Anyone can help to identify what parts are not good.

<< script content >>

#!/usr/bin/ksh

/usr/lib/sendmail -C sendmail.cf abc@gmail.com << END
Subject: HELLO
Content-Type: multipart/mixed; boundary="_boundarystring"

--_boundarystring
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="123.pdf"
Content-Transfer-Encoding: 7bit
`uuencode 123.pdf 123.pdf`
--_boundarystring--
END

Anyone here can help? Thanks.