Can i send an attatchment with sendmail?

Hello Expert,

Can i send an attatchment with sendmail?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It would help if you could specify (a) what OS you're
using (b) what version of sendmail you're running  and
(c) whether the solution to your problem can involve a MUA
or not.
Isn't sendmail the "lowlevel"  program that takes care of the actual sending/re-routing of the mails? I thjough it depends which end-user mailsystem you are using (eg. elm, openmail, mail, ...)

I assume you want a command line solution. You will need at least uuencode, which comes with most Unix distributions, anyway.

The simplest, with no message, would be

uuencode filename filename | sendmail

With a message, it's a bit different. First create a file "msgfile" with the message you want to send, making sure you put at least one blank line after the message, then

uuncode filename filename >> msgfile
sendmail <<msgfile

You may of course, write this into a script or use some other more efficient method, but the basic idea should remain the same.

Here's a sample quick-and-dirty script ("sendattach"):


file=`uuencode $attach $attach`
sendmail $to <<END
Subject: $subject
To: $to




Replace with your address, of course, or remove the entire From: line to use your default address. Don't forget to chmod +x sendattach. Launch using something like

sendattach "This is a test" someimage.gif

Type in message, and press Control-D.

Hope this helps!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

cwc061097Author Commented:
Thanks Dirge for your help
Can u also make a sample script that i can use with perl 5
Thanks again

Hi. Thanks for the points!

You'd probably be better off using the MIME-tools Perl modules. The "mimesend" example should be a great starting point. You could even use it as-is in many cases.

You can get MIME-tools from CPAN:

Leave a message here or email me at if you need more help.

cwc061097Author Commented:
Hi Dirge
Thanks for the tip

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.