Sponsored Content
Top Forums UNIX for Advanced & Expert Users mailx commannd - Mail and Attachment in same mail Post 302169916 by kpearson on Saturday 23rd of February 2008 02:31:59 AM
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 . . .
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
CRASHWRITE(1)							     CrashMail							     CRASHWRITE(1)

NAME
crashwrite - Creates PKT file from text file SYNOPSIS
crashwrite DIR directory [FROMNAME string] [FROMADDR node] [TONAME string] [TOADDR node] [SUBJECT string] [AREA area] [ORIGIN origin] [TEXT filename] [NOMSGID] [FILEATTACH] [PKTFROMADDR node] [PKTTOADDR node] PASSWORD [string] DESCRIPTION
CrashWrite reads a text file and creates a .pkt file that can be processed by CrashMail. This can be used to post announcements and other messages in areas. The best way to use CrashWrite is to let it generate packets in a separate directory and then toss them with TOSSDIR NOSECURITY. There are many keywords for CrashWrite. All keywords are optional except for DIRECTORY. If you do not enter a keyword, a default value will be used. OPTIONS
FROMNAME string FROMADDR node TONAME string TOADDR node SUBJECT string Use these keywords to set the header of the message. You only need to enter TONAME and TOADDR for netmails. PKTFROMADDR node PKTTOADDR node Use these if you want to set the origin and destination address of the packet to something other than the origin and destination address of the message inside the packet. If you do not specify these keywords, FROMADDR and TOADDR will be used for the packet as well. PASSWORD string You can use this keyword to set a password for the packet. The maximum length of the password is eight characters. AREA area The area the message should be posted in. If you do not enter an area, the message will be sent as a netmail. ORIGIN origin The origin line for the message. This keyword has no effect for netmail messages. DIR directory The directory where the packet should be placed. TEXT filename The name of a text file that should be included as the message text. NOMSGID Prevents CrashWrite from adding a MSGID line. FILEATTACH Sets the file-attach flag for netmails. The filename should be put in the subject line. SEE ALSO
crashmail(1) AUTHOR
CrashMail is written by Johan Billing <billing@df.lth.se> This manual page was written by Peter Karlsson <peter@softwolves.pp.se> Johan Billing 1999-08-01 CRASHWRITE(1)
All times are GMT -4. The time now is 07:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy