1819941 Members
3404 Online
109607 Solutions
New Discussion юеВ

Sendmail file attachment

 
system administrator_15
Frequent Advisor

Sendmail file attachment

Hi guys i have two questions firstly i have written a script in which i need to send a file attachment via either sendamail or mailx,
i have looked at both man pages and maybe im giong blind, but i can't see and option to allow this
can anyone tell me how.
also i have stopped recieving forum notification updates and i used to and haven't changed anything, but yet don't recieve them anymore.
regards
andy
11 REPLIES 11
Robert-Jan Goossens
Honored Contributor
twang
Honored Contributor

Re: Sendmail file attachment

# uuencode |mail user@domain.com
Steven E. Protter
Exalted Contributor

Re: Sendmail file attachment

Forum notification is being worked on.

If you are using a relay server for smtp, make sure its patched. They can play havoc with really perfectly good scripts.

I'm attaching my script though.

Just for reference. Its production.

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: Sendmail file attachment

Get mpack - works great:

mpack/munpack version 1.5 for unix

Mpack and munpack are utilities for encoding and decoding
(respectively) binary files in MIME (Multipurpose Internet Mail
Extensions) format mail messages. For compatibility with older forms
of transferring binary files, the munpack program can also decode
messages in split-uuencoded format.

http://hpux.ee.ualberta.ca/hppd/hpux/Users/mpack-1.5/readme.html

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.
A. Clay Stephenson
Acclaimed Contributor

Re: Sendmail file attachment

My favorite method is to use elm because multiple attachments with text in-between is so easy. Elm will work just fine from the command line as well as interactively. I have scripts that use it that are run everyday.

Within the body of your email add this:

------------------------------------

This is my text. How are you?


[include /tmp/myattach application/octet-stream base]

This is some more text in the middle.

[include /tmp/myexcel.xls application/ms-excel base]

This is a closing message in the email.

----------------------------------------



That will attach /tmp/myattach and /tmp/myexcel.xls. You can include multiple attachments using this method. If you are running 10.20 make sure that you have a MIME enabled version of elm (PHNE_15835 or later).

Then to use it from a script:
elm -s "My Subject" user@mailserver.com < myletter

Where myletter contains the attachment include statement as well as your message text. It is also necessary that you have a .elm directory
under the sender's home directory because unlike the interactive version of elm the command-line version will not create a .elm directory automatically.

Regards, Clay
If it ain't broke, I can fix that.
Todd McDaniel_1
Honored Contributor

Re: Sendmail file attachment

Here is a great script from a poster on www.unix.com MB...

Handles 1 message and 1 attachment.. can be modified to handle multiple attachments.
Unix, the other white meat.
doug mielke
Respected Contributor

Re: Sendmail file attachment

a very simple command for attachments is:

mailx me@myaddress.com < attachmentname
Dave La Mar
Honored Contributor

Re: Sendmail file attachment

Andy-
As you can see, there are a multitude of good ways to do this.
In our shop this is one common way using mailx.
Build the file for the mailx process to look similar to the following:
mailx -m -s "Hello" someone@somewhere.com <<-END
`ux2dos file_name_one | uuencode file_name_one.txt`
`ux2dos file_name_two | uuencode file_name_two.txt`
This is all you get.
END

This sends two file attachments to someone@somewhere.com with a subject of Hello and a body of "This is all you get."
OR
From the command line:
echo "This is all you get." | ux2dos file_name_one | uuencode file_name_one.txt |ux2dos file_name_two | uuencode file_name_two.txt | mailx -m -s "Hello" someone@somewhere.com

Then there are options to doing a CC and BC as well.
Best of luck.

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Dave La Mar
Honored Contributor

Re: Sendmail file attachment

Andy -
Actually, attached is a text file with a number of ways to use mailx.

Best regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Rita C Workman
Honored Contributor

Re: Sendmail file attachment

Like Clay, I am a user of the 'include'. We find it works quite well, especially when using it within a script for multiple files. You can send them using any number of options, from text to Excel file types...

Here's an old thread:
http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F0%2C%2C0x41950559ff7cd4118fef0090279cd0f9%2C00.html&admit=716493758+1066419055845+28353475

Regards,
Rita
Todd McDaniel_1
Honored Contributor

Re: Sendmail file attachment

Doug,

your example is only for a message to be sent, not for a TRUE attachment sent with a message.

Unless Im really mistaken, mailx doesnt support attachments, not in the true sense of an attachment. If you want to try, send a binary file wiht mailx and see that you get a jumble of characters...

I believe ELM does allow real attachments, but I have never used that feature.
Unix, the other white meat.