Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to attach files to e-mail using mail[x] 2

Status
Not open for further replies.

Ogzilal

MIS
Oct 9, 2003
280
FR
Hi Linux gurus,

How one can attach text files to e-mail using mail.
uuencode and ~(tilde) operators works fine for me on an AIX box, but I don't know how to convert this in Linux RedHat 4.
Operating system is in production mode and I can't install uuencode or other mail utilities, only mail is available

Any suggestion will help.

Ali

 
Hi,

Thanks mbrooks for your reply.
But what I want is to get text_file.txt, not in the body of the e-mail, but as attached file as you can receive attached .jpg, .doc .xls or others to your personal mails.

Ali
 
I don't have RHEL AS4, but does it have the mail -a option that is found on SLES9? I know that doesn't exist on AS3, but maybe they introduced it...

Failing that, there are two FAQs here describing how to send an attachment using sendmail:



Annihilannic.
 
This one is pretty easy. We'll call the message body message.txt, assume your attachment is named example.doc, and assume you're sending the email to bob@bob.com:

Code:
echo "Bob, here is your file" > message.txt
uuencode example.doc example.doc >> message.txt
cat message.txt | mail -s "Your file" bob@bob.com

The doubled use of "example.doc" above is not an error. The syntax for uuencode requires an input file, and a name to give me encoded file inside the archive.
 
Well then, consider running an off-server website or daemon that can receive the file attachment via FTP and then return that "object" with uuencoded text for attachment.

I'm also going to guess that perl can solve this if the "production" server can tolerate having a module added where necessary. Probably no reason to require using "mail" if perl can be mod'd or used.

AND, PHP can run from binary and undoubtedly contains scripting support for mail and attachments.






D.E.R. Management - IT Project Management Consulting
 
Hi,

Happy new year 2.0.0.7 every body.

Annihilanic, I have the -a option but I don't know how to use it, the man mail is so confuse.

The 1st FAQ script uses uuencode inside it.
The 2nd FAQ deals with sendmail directly and works fine for me. The year begans good.

Have a star to began the year.

Thank you All.
 
Use the -a option like this:

[tt]echo "message text" | mail -s "subject" -a filename address@example.com[/tt]

Annihilannic.
 
Hi,

Sorry, my man is more confuse than I think! it tells me lies when using my locale fr_FR.

man mail using my locale LANG=fr_FR
Code:
# echo $LANG
fr_FR
# man mail
MAIL(1)             Manuel de commandes systèmes générales            MAIL(1)

NOM
     mail, mailx, Mail - recevoir et envoyer des courriers

SYNOPSIS
     mail [-ieInv] [-s sujet] [-a en-tête] [-c adresses cc] [-b adresses bcc]
          to-addr [...] [-sendmail-options [...]]
     mail [-ieInNv] -f [nom]
     mail [-ieInNv] [-u utilisateur]

man mail using LANG=C
Code:
# echo $LANG
C
# man mail
MAIL(1)                  BSD General Commands Manual                  MAIL(1)

NAME
     mail - send and receive mail

SYNOPSIS
     mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr...
     mail [-iInNv] -f [name]
     mail [-iInNv] [-u user]

trying to get help from command
Code:
# mail --help
mail: invalid option -- -
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
            [- sendmail-options ...]
       mail [-iInNv] -f [name]
       mail [-iInNv] [-u user]

Never trust man in your local dialect!!!

Thanks again.
 
you can build your own mime encoding; this codeblock is recycled from another forum...
Code:
# use this function in a (POSIX) shell
func_send_email()
{

(
echo "From: \"sendername ${SERVER}\" <sendername@${SERVER}.senderdomain.com>"
echo "To:receiver@receiverdomain.com"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed;"
echo ' boundary="PAA08673.1018277622/'${SERVER}'.senderdomain.com"'
echo "Subject: this is the mailsubject"
echo "--PAA08673.1018277622/${SERVER}.senderdomain.com"
echo "Content-Type: text/plain"
cat < $1
echo "--PAA08673.1018277622/${SERVER}.senderdomain.com"
echo "Content-Type: text/html;"
echo " name=\"$2\""
echo "Content-Disposition: attachment;"
echo " filename=\"$2\""
cat < $2
) | /usr/sbin/sendmail -t
}

call the function with
func_send_email mailbodyfile mailattachmentfile
set SERVER to your `hostname`

Best Regards, Franz
--
UNIX System Manager from Munich, Germany
 
if you have mutt installed then its just as easy:

mutt -a attachement -s"subject" adress@somewhere

(then goes into mutt vi editor style

or terminate with < bodytextfromfile
or </dev/null (gives no body text)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hi,

DaFranze, this works too. It's a variant of tha second FAQ suggested by Annihilannic.

KarveR, No I don't have mutt installed.

Plain text files works for me now.
The only problem is when I want to attach some .gz logs which need to be base64 encoded.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top