Operating System - HP-UX
1753797 Members
7852 Online
108799 Solutions
New Discussion юеВ

how to attach the file using sendmail

 
rajesh73
Super Advisor

how to attach the file using sendmail

how to attach the file using send mail command
8 REPLIES 8
Steven Schweda
Honored Contributor

Re: how to attach the file using sendmail

There should be dozens of old threads on how
to use e-mail attachments. Did you look? A
Forum search for keywords like, say:
mail attachment
should find several.

http://forums.itrc.hp.com/service/james/home.do?from=forums


Also: On what?

uname -a
rajesh73
Super Advisor

Re: how to attach the file using sendmail

HP_UX B.11.11
Rita C Workman
Honored Contributor

Re: how to attach the file using sendmail

There are third party vendor software that will do it for you.

Folks like uuencode. For myself I am a fan of the 'include' statment.

As Steven says just search for 'mail attachments sendmail' or try 'mail attachments mime'

Here is one to get you started..

http://h30499.www3.hp.com/t5/System-Administration/sending-attachment-using-sendmail/m-p/3852840#M275270


Rgrds,
Rita

Dennis Handly
Acclaimed Contributor

Re: how to attach the file using sendmail

You could also install thunderbird.
Mel Burslan
Honored Contributor

Re: how to attach the file using sendmail

This should do it:

uuencode filename filename | mailx -m -s "subject line for email" address@domain.com

and yes filename is repeated twice intentionally. fist one is the name of the file you are attaching. second is for the name of the attachment. The do not have to be the same but it helps tremendously if you keep them the same in the long run, when problems start to show up.

hope this helps
________________________________
UNIX because I majored in cryptology...
Doug O'Leary
Honored Contributor

Re: how to attach the file using sendmail

Hey;

As others have pointed out, there are numerous methods - google search would probably be enlightening.

That being said, I created my own little cheat sheet for my favorite ways of doing just that:

http://www.olearycomputers.com/ll/mail_attach.html

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
PM Srividhya
Advisor

Re: how to attach the file using sendmail

Hi,

Attached is a handy script which is used to attach PDF files and text files which uses sendmail.

Cheers,
Vidhya
PM Srividhya
Advisor

Re: how to attach the file using sendmail

Oops.. attachment is missed! Due to some reason attachment is not working.. Posting the script down.



#! /usr/bin/ksh
###########################################
###########################################
################
# Filename : sendMail
# Description : To send a mail to a user with an attachemnt
# Arguments : -f -t -c -s -b -a
# Author : P.M. Srividhya
# Date : 6-March-2007
#
#For Eg. sendMail -f -t user@host.com -c user1@host1.com -s subject -b body -a attach.txt
#############################################
###########################################
##############
export PATH=$PATH:/usr/bin:/usr/sbin:/usr/lib
if [ $# = 0 ]
then
print "Usage: $0 -f fromuser -t user@host.com -c user1@host1.com -s subject -b body -a attach.txt [optional]"
exit 1
fi

while getopts 'f:t:c:s:b:a:' opt
do
case $opt in
f)
fromAddress=$OPTARG
;;
t)
toAddress=$OPTARG
;;
c)
ccAddress=$OPTARG
;;
s)
subject=$OPTARG
;;
b)
body=$OPTARG
;;
a)
attachment=$OPTARG
;;
:)
print "$OPTARG need an argument"
exit 1
;;
\?)
print "$OPTARG need a value"
exit 1
;;
esac
done

body="$(echo $body)"

if [ -z "$fromAddress" ] || [ -z "$toAddress" ] || [ -z "$subject" ] || [ -z "$body" ]
then
print "Error: From Address, To Address, Subject and Body of the mail are required arguments"
exit 1
fi
if [ ! -z "$attachment" ]
then
if [ ! -f $attachment ] || [ ! -r $attachment ]
then
print "$attachment is not a readable file"
exit 1
else
filename=$(/usr/bin/basename $attachment)
fileextn=$(echo $filename | cut -f2 -d ".")
typeset -l fileextn=$fileextn
fi
if [ "$fileextn" = "pdf" ]
then
filetype="ACROBAT"
else
filetype="TEXT/PLAIN"
fi
boundary='=== This is the boundary between parts of the message. ==='
{
print - "From: <${fromAddress}>"
print - "To: <${toAddress}>"
print - "Cc: <${ccAddress}>"
print - 'Subject:' $subject
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - ' BOUNDARY='\"$boundary\"
print -
print - "--${boundary}"
print -
print - $body
print -
print - "--${boundary}"
print - 'Content-Type: '$filetype'; charset=US-ASCII; name='$filename
print - 'Content-Disposition: attachment; filename='$filename
print - 'Content-Transfer-Encoding: 7bit'
print -
cat $attachment
print -
print - "--${boundary}--"
} | sendmail "${toAddress} ${ccAddress}"
else
mail -t $toAddress << EOF1
Subject: $subject
From: $fromAddress
Cc: $ccAddress
$body
EOF1
fi

exit 0