Operating System - HP-UX
1827458 Members
5584 Online
109965 Solutions
New Discussion

sending email with a file attachment

 
SOLVED
Go to solution
Chris Harris
Contributor

sending email with a file attachment

how can i send an email with a file attachment with mailx or sendmail? or is there another solution?

thanks in advance,

chris
10 REPLIES 10
Michael Tully
Honored Contributor
Solution

Re: sending email with a file attachment

Hi,

Here is fairly simple method for sending one or multiple files.

##############################################
for e in `echo file1 file2 file3`
do
uuencode $e $e.txt
done|mailx -m -s "mymail" username@domain.com
##############################################
Change ".txt" to the proper format of the file e.g. .xls for excel, .doc for word etc

You can use mailx, sendmail, just change the command. Have a look at the various man pages for additional help.

Michael
Anyone for a Mutiny ?
Scott Van Kalken
Esteemed Contributor

Re: sending email with a file attachment

if the file is "file"

you can use:

uuencode file file.txt | mailx -m me@here.com


the -m is for mime encoding (I think).

If it's a text file, I usually give it an extension that can be opened from outlook, or I go to whoever it's being mailed to, create a new extnesion that uses wordpad to open it up.

Don't forget, if it's plain text you can also use ux2dos before uuencoding it so it's got dos/win EOL characters.

Hope this helps.

Scott.
S.K. Chan
Honored Contributor

Re: sending email with a file attachment

A. Clay Stephenson
Acclaimed Contributor

Re: sending email with a file attachment

My weapon of choice for this is elm.

Simply include the following syntax in your mail textfile (e.g) my_message

-----------------
This is some sample text.
[include myfile1 application/octet-stream base64]

This is some more stuff.

[include myfile2 application/octet-stream base64]

That's all folks
------------------

Then, elm -s "Sample Subject" someuser@xxx.com < my_message

The only requirement is that you must first create a .elm directory in the sender's home directory; the command-line version will not automatically create the .elm directory unlike the interactive version of elm. The above will attach myfile1 and myfile2. You can play with the application part to suit your needs (e.g. ms-excel). This makes a nice way to do multiple attachments.

Regards, Clay



If it ain't broke, I can fix that.
Wong_3
Advisor

Re: sending email with a file attachment

For my case,

I do a mailx -s "title" "email address" < "file attachment"

Learning is a journey till the end of life
Bill Thorsteinson
Honored Contributor

Re: sending email with a file attachment

Have you considered createing a shell archive.

Pipe the archve to mail as the message body.
Hai Nguyen_1
Honored Contributor

Re: sending email with a file attachment

Chris,

There have been many posts on this in the forum. Please search for "attachment".

Hai
Rita C Workman
Honored Contributor

Re: sending email with a file attachment

Scott Hanson_1
Frequent Advisor

Re: sending email with a file attachment

We use the following script to send binary files as attachments from the command line. HTH.

http://home.clara.net/dwotton/unix/mail_files.htm
Anthony khan
Frequent Advisor

Re: sending email with a file attachment

Sending for example text file as attachment and that it can be opened by Windows do the
following:

ux2dos YourDocument|uuencode YourDocument.txt|mailx -m -s "Here is your text document"
email@domain.com