Operating System - HP-UX
1833939 Members
1597 Online
110063 Solutions
New Discussion

Sending a File as an Attachement using Sendmail

 
SOLVED
Go to solution
Kehad Snydewel
Frequent Advisor

Sending a File as an Attachement using Sendmail

Hi

I wish to send a file as an attachement using Sendmail, but it refuses to send it as an attachement.
I've tried the following with mailx

uuencode file file | mailx -s " " me@domain.com

Please help...
15 REPLIES 15
whiteknight
Honored Contributor
Solution

Re: Sending a File as an Attachement using Sendmail


hi,
here is some tips

Sendmail

Example1:
(uuencode /etc/hosts /etc/hosts.txt;uuencode /etc/services /etc/services.txt)
| sendmail abc@hp.com

Note:
The ( ) around the uuencode is required

Example2:
cat /etc/hosts /etc/services > newfile ; cat newfile | sendmail abc@hp.com

WK
please assign points
Problem never ends, you must know how to fix it
Dennis Handly
Acclaimed Contributor

Re: Sending a File as an Attachement using Sendmail

>WK: cat /etc/hosts /etc/services > newfile ; cat newfile | sendmail

Any reason you want to create newfile, instead of just piping the first cat of two files to sendmail?
Bill Hassell
Honored Contributor

Re: Sending a File as an Attachement using Sendmail

Actually, you can use mailx -- just add the -m option. And if the destination is a PC, use ux2dos to properly format the file:

ux2dos myfile | uuencode someTitle.txt | mailx -m -s "my subject" you@somewhere.com

ux2dos will translate from Unix to DOS/PC style line terminators and the uuencode filename becomes the name for the attachment (which can be anything including the original filename).


Bill Hassell, sysadmin
Steven E. Protter
Exalted Contributor

Re: Sending a File as an Attachement using Sendmail

Shalom,

This script is pretty nifty.

http://www.hpux.ws/mailfile2

It actually uses sendmail though this is not a requirement. It's production quality code, used by myself and many others. If there are still default email addresses in there, please change them.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Geoff Wild
Honored Contributor

Re: Sending a File as an Attachement using Sendmail

And yet another way:

Try using mpack to send the file instead:

http://hpux.ee.ualberta.ca/hppd/hpux/Users/mpack-1.6/

Run like so:

/usr/local/bin/mpack -s "svr004 cfg2html" /opt/cfg2html/svr004.html gwild@mydomian.ca


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Kehad Snydewel
Frequent Advisor

Re: Sending a File as an Attachement using Sendmail

Thanks Guys for your input.

Now, how do I add this command in a script file?
(uuencode file file) | sendmail me@domain.com

The reason I ask is I want to create a cronjob that executes the script file to send me the e-mail with the attached file.

I added the command as it is a a script,but it does not work.

Help
Anshumali
Esteemed Contributor

Re: Sending a File as an Attachement using Sendmail

1. Set your environment in script. User and cron env are different.
2. Give full paths to command and your files.
Dreams are not which you see while sleeping, Dreams are which doesnt allow you to sleep while you are chasing for them!!
Kehad Snydewel
Frequent Advisor

Re: Sending a File as an Attachement using Sendmail

I've tried /usr/bin/sh at the top of the script but still no luck, any further ideas?
Franky_1
Respected Contributor

Re: Sending a File as an Attachement using Sendmail

Hi,

just try the following

uuencode |sendmail
For example
uuencode test test.rpt|sendmail sam (as defined in /etc/mail/aliases) or the full address is also possible of course

Regards

Franky
Don't worry be happy
Franky_1
Respected Contributor

Re: Sending a File as an Attachement using Sendmail

Just enter the previously mentioned command line (uuencode ...) in a scriptfile and start this script via cronjob - that's it

Regards

Franky
Don't worry be happy
Sandman!
Honored Contributor

Re: Sending a File as an Attachement using Sendmail

One problem with your cmd line is the absence of the "-m" switch which forces mailx to distinguish between attachments and message body text. See if the cmd below works:

# uuencode file file | mailx -m -s " " me@domain.com

~cheers
Dave La Mar
Honored Contributor

Re: Sending a File as an Attachement using Sendmail

Sir -
I realize you are wanting to use sendmail, but as others posted, there are a myriad of ways to handle this with mailx.
I am attaching an inhouse doc we use quite frequently in our shop with many examples.

Regards,

-dl
"I'm not dumb. I just have a command of thoroughly useless information."
Steven E. Protter
Exalted Contributor

Re: Sending a File as an Attachement using Sendmail

Shalom again.

mailx uses sendmail as a transport.

It makes no difference whether your code uses mailx or sendmail directly as does my script.

Take another look at my earlier post. It has the exact lines of code you want to use to do the job with sendmail.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Kehad Snydewel
Frequent Advisor

Re: Sending a File as an Attachement using Sendmail

So how do I add this to a scritp file.
I want to execute two of these commands to attach to different files, but after I execute the script it does nothing

Help
Bill Hassell
Honored Contributor

Re: Sending a File as an Attachement using Sendmail

Here is a script as an example. It uses mailx and a 'here' document with text in the body of the message. This example attaches 3 files:

#!/usr/bin/sh
mailx -m -s "This is the subject" me@somplace.com << EOF
$(ux2dos /etc/profile | uuencode MyProfile.txt)
$(ux2dos /etc/hosts| uuencode MyHosts.txt)
$(ux2dos /etc/inittab| uuencode MyInittab.txt)
So there are 3 files here.
The uuencode filename is not local to your system, it is used to provide a title for
the attachment.

You can put lots of comments here or even
use a text file like this:
$(cat /etc/nsswitch.files)

This is the end...
EOF

-------------
Now notice that *full pathnames* are used, not something in your local directory. When cron runs, there is no login, no profile, just a simple environment.


Bill Hassell, sysadmin