mailx commannd - Mail and Attachment in same mail


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users mailx commannd - Mail and Attachment in same mail
# 1  
Old 02-23-2008
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  
Old 02-23-2008
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  
Old 02-23-2008
Tools 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  
Old 03-05-2008
Bug Multiple attachments to a mail ????

Quote:
Originally Posted by joeyg
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.
VarunSmilie
# 5  
Old 03-05-2008
Quote:
Originally Posted by varungupta
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  
Old 03-19-2008
Lightbulb

Quote:
Originally Posted by Dave Miller
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 !!
VarunSmilie
# 7  
Old 03-19-2008
Quote:
Originally Posted by Dave Miller
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.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Red Hat

Problems sending mail: Difference between Mail and Mailx?

Whats the difference between mail and mailx? I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL) ... (1 Reply)
Discussion started by: RedSpyder
1 Replies

3. Shell Programming and Scripting

Not able to send the mail using mail and mailx command

Hi All, I am trying to send a mail from linux server but could'nt able to send the mail. I tried the below syntax's so far but no luck. mail -s “Hello world” abc@xyz.com < /usr/g/txt.log cat "txt.log" | mailx -s "Hello world" abc@xyz.com mailx -s “Hello world” abc@xyz.com <... (2 Replies)
Discussion started by: scriptscript
2 Replies

4. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

5. Shell Programming and Scripting

send attachment and body in one mail using mailx

Hi, Our requirement is to send an attachment and content in a single mail. I am using the below command to send attachement. --------------------- (uuencode $exp_file $exp_file) |mailx -s "$email_subject" $EmailRecipients -------------------- I m not able to send any message in the... (4 Replies)
Discussion started by: ashwin3086
4 Replies

6. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

7. UNIX for Advanced & Expert Users

how to send file as attachment using mail or mailx

I have a need to send a file from the unix command line to be sent as an attachment. Is this possible? That is when I open my outlook email I need to file to appear as an attachment. Also, is there a way to use the mail binary (not mailx) to modify the "reply address". mailx -r works but I need... (1 Reply)
Discussion started by: kieranfoley
1 Replies

8. Shell Programming and Scripting

Mail attachment with unix mail

Hi Could someone help me with the details on how to send an attachment through mail in unix. I have an html file in my unix machine and I want this to be send to some mail id, plese help with the steps. Regards Ajay (2 Replies)
Discussion started by: ajaykumarboyana
2 Replies

9. Shell Programming and Scripting

Problem with Mailx command to send mail with attachment

Hi, I am using mailx command to send a mail with attachment. It's working fine, but with attachment I am getting one extra attachment like (ATT00131.txt). I have tried to use unix2dos command also. But still I am getting the extra attachment. I am using the following code: subject="temp... (5 Replies)
Discussion started by: viswanatharv
5 Replies

10. UNIX for Dummies Questions & Answers

mail or mailx attachment

I have used the forum to determine the format required to send attachments from hp-ux 11. the problem I have is that using mailx does not attach the file, but subsititing mailx for mail on the command line attaches the file but i'm not able to specify a subject? The attachment has been convert... (3 Replies)
Discussion started by: brettmartin99
3 Replies
Login or Register to Ask a Question