The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mail with attachment param786 Shell Programming and Scripting 1 07-15-2007 12:20 PM
How To Add Attachment to Mail lesstjm Shell Programming and Scripting 3 12-06-2005 11:24 AM
mail or mailx attachment brettmartin99 UNIX for Dummies Questions & Answers 3 03-07-2005 11:27 AM
mail attachment sushrut UNIX for Dummies Questions & Answers 3 08-28-2001 03:14 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-23-2008
sharif sharif is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 40
mailx commannd - Mail and Attachment in same mail

Hi ,
I am using mailx command for sending the mails. Rightnow I am sending the attachment (by using uuencode $filename) as a seperate mail.I wanna send the attachment also with the same mail.
  #2 (permalink)  
Old 02-23-2008
kpearson's Avatar
kpearson kpearson is offline
Registered User
  
 

Join Date: Nov 2006
Location: Lehi, Utah, USA
Posts: 15
You have to include the following lines in the header of the email to have the file go as an attachment:

Code:
Content-Disposition: attachment; filename="filename.ext"
Mime-Version: 1.0
Content-Type: text/plain
... rest of email ...
And you will probably have to not use mailx and use sendmail with a command like:

Code:
/usr/sbin/sendmail -t -iep < emailfilename
But, for that to work, the file, emailfilename has to have a From: line, a Date: line and a Subject: line. There has to be a blank line after these header lines, the ones above, and the start of the data.

Here's a commandline script I wrote for AIX, but which should work just about anywhere you have access to sh (bash, ksh, sh):

Code:
#!/usr/bin/ksh

if [ $# -lt 4 ] ; then
 echo "USAGE: send.email UNIXDIR UNIXFILE FROM@atsindustrial.com TO@ADDR.com"
exit 1
fi

UNIXPATH="$1"
UNIXFILE="$2"
FROMADDR="$3"
TOADDR="$4"

if [ -f "$UNIXPATH/$UNIXFILE" ] ; then
 OBJECT="$UNIXPATH/$UNIXFILE"
 cat "$OBJECT" | /usr/sbin/sendmail -oi -t -f $FROMADDR $TOADDR
else
 echo "$UNIXPATH/$UNIXFILE not valid..."
 exit 2
fi

exit 0
HTH

Last edited by kpearson; 02-23-2008 at 03:37 AM.. Reason: addition of a script to call . . .
  #3 (permalink)  
Old 02-23-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool are you asking about all on one line?

From memory, I recall using a command such as:

Code:
uuencode file.att file.att | mailx -s "subject" you@somebody.com
is that what you are trying to do?
  #4 (permalink)  
Old 03-05-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Smile Multiple attachments to a mail ????

Quote:
Originally Posted by joeyg View Post
From memory, I recall using a command such as:

Code:
uuencode file.att file.att | mailx -s "subject" you@somebody.com
is that what you are trying to do?
Hey,

Thanks man, this is great help !! It solved my purpose too to send a mail with an attachment and text as an option.

If I want to attach more then one file to the same mail then what would be the syntax ???


Thanks.
Varun
  #5 (permalink)  
Old 03-05-2008
Dave Miller's Avatar
Dave Miller Dave Miller is offline
Registered User
  
 

Join Date: Dec 2007
Location: Northern NJ, USA
Posts: 151
Quote:
Originally Posted by varungupta View Post
If I want to attach more then one file to the same mail then what would be the syntax ???
echo "Email message" > tempfile
uuencode file1.ext file1.ext >> tempfile
uuencode file2.ext file2.ext >> tempfile
uuencode file3.ext file3.ext >> tempfile
.
.
.
mail -s "Subject" user@domain.com < tempfile


FYI: In case you didn't already know it, the first file named in the uuencode command is the source file. Include the path if necessary. The second file is the name that will be used when the recipient extracts it from their email.
  #6 (permalink)  
Old 03-19-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Lightbulb

Quote:
Originally Posted by Dave Miller View Post
echo "Email message" > tempfile
uuencode file1.ext file1.ext >> tempfile
uuencode file2.ext file2.ext >> tempfile
uuencode file3.ext file3.ext >> tempfile
.
.
.
mail -s "Subject" user@domain.com < tempfile


FYI: In case you didn't already know it, the first file named in the uuencode command is the source file. Include the path if necessary. The second file is the name that will be used when the recipient extracts it from their email.
Hey,

Thanks for the reply.
One more question regarding the same topic.

How to send a mail which contains the text as well as the attachment file ?

Note :The text to the mail could be hardcoded or could be taken from a file.

Please suggest !!
Appreciate your help !!
Varun
  #7 (permalink)  
Old 03-19-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by Dave Miller View Post
echo "Email message" > tempfile
uuencode file1.ext file1.ext >> tempfile
uuencode file2.ext file2.ext >> tempfile
uuencode file3.ext file3.ext >> tempfile
.
.
.
mail -s "Subject" user@domain.com < tempfile


FYI: In case you didn't already know it, the first file named in the uuencode command is the source file. Include the path if necessary. The second file is the name that will be used when the recipient extracts it from their email.

Hey Guys,

Thanks, I got the answer !!
Thanks for visiting !!
Varun.
Closed Thread

Bookmarks

Tags
mailx, mailx attachment, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0