Mailx with attachment and html content


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mailx with attachment and html content
# 1  
Old 09-15-2017
Mailx with attachment and html content

Hi, Please see my code below i'm trying get an email send with attachment and html content in the body.

Using the code below will put the encoding for attachment in the body as well

Code:
SUBJECT="$(echo  "XPI Monitoring "${tcnt}" transactions waiting \nContent-Type: text/html")"
            cat $RT_DIR/${RPT_DNAME[2]}/${XPILOG} > $TEMP_FILE
            uuencode $RT_DIR/${RPT_DNAME[2]}/${XPILOG} "xpimon.csv" >> $TEMP_FILE
            mailx -s "$SUBJECT" "$mailist" < $TEMP_FILE

Please shower some light if possible of what i'm doing wrong
Thanks


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-15-2017 at 06:35 AM.. Reason: Added CODE tags.
# 2  
Old 09-15-2017
Save and examine the contents of temp_file. There are required blank lines close to the "content_type" line.
If need be, post the contents of temp_file, obscuring anything identifiable.
# 3  
Old 09-15-2017
$TEMP_FILE is as follows.

Code:
m158xpimdir,m158xpisdte,m158xpistme, m158xpiprost,m158xpiprbm, m158xpiprst, m1ll, m1mcu, m1ldnm,m1kcoo, m1doco, m1dcto, m1lnid,m158xpiproc,m1user
O,117258,135109,S,TRIGGXPI,S,TS_NL,124030,0,,0,,0,PPLCALL_1,TSTXPI00
I,117258,83411,S,IS02,S,JTS_US,804030,0,,775900,,0,OMACONF_1,XPI
O,117258,135346,S,TRIGGXPI,S,TS_NL,124030,0,,0,,0,PPLCALL_1,TSTXPI00

This $TEMP_FILE will be converted with html tags later

What am really trying to do is send a mail with an attachment while the mail body is html as well.

any sample would be appreciate.
# 4  
Old 09-15-2017
request
Code:
m@from.com~a@to.com~SUBJECT~42833379.memo~uel14647.pdf uel14827.pdf

Send process
Code:
#!/bin/ksh                                                                
 IFS="~"                                                           
 cat requests/$request | read  user email subject memo attachments 
 IFS=" "                                                           
 delvmime $attachments <../requests/$request \                     
 |/usr/lib/sendmail -f$user $email

Build content
Code:
#!/bin/ksh                                                                      
                                                                                
#Convert pdf file to mime encoded                                               
pdf(){                                                                          
echo Start pdf >>/tmp/delv.log                                                  
echo --PART-BOUNDARY.abcdefghijklmnopqrstuvwxyz                                 
echo X-Zm-Content-Name: `/bin/basename $filename.pdf`                           
echo "Content-Type: application/pdf; name=\"`/bin/basename $filename.pdf`\""    
echo "Content-Transfer-Encoding: base64"                                        
echo "Content-Dispostion: attachment;"                                          
echo "       filename=`/bin/basename $filename.pdf` \n"                         
b64encod <$filename.pdf                                                         
}                                                                               
#Convert eml file to mime encoded                                               
eml(){                                                                          
echo Start eml >>/tmp/delv.log                                                  
echo --PART-BOUNDARY.abcdefghijklmnopqrstuvwxyz                                 
echo X-Zm-Content-Name: `/bin/basename $filename.eml`                           
echo "Content-Type: application/eml; name=\"`/bin/basename $filename.eml`\""    
echo "Content-Transfer-Encoding: base64"                                        
echo "Content-Dispostion: attachment;"                                          
echo "       filename=`/bin/basename $filename.eml` \n"                         
b64encod <$HWD/$filename.eml                                                    
}                                                                               
#convert French language letters                                       
frn(){                                                                 
cd /u2/email/eps                                                       
echo '1d\nw\nq' |ed $HWD/$tiff                                         
cat /u2/email/escape /u2/email/letterhead $HWD/$tiff |\                
enscript -B -e -f Courier@10/11.6 -h -X ibmpc -p $HWD/$filename.ps     
ps                                                                     
}                                                                      
#convert French language letters                                       
tsa(){                                                                 
cd /u2/email/eps                                                       
echo '1d\nw\nq' |ed $HWD/$tiff >/dev/null 2>&1                         
cat /u2/email/escape  $HWD/$tiff |\                                    
enscript -B -e -f Courier@10/11.6 -h -X ibmpc -p $HWD/$filename.ps     
ps                                                                     
}                                                                      
#convert PS file to PDF   
#convert PS file to PDF                                          
ps(){                                                            
cd /u2/email/eps                                                 
ps2pdf $HWD/$filename.ps $HWD/$filename.pdf >>/tmp/ps2pdf.log    
cd $HWD                                                          
echo finished ps portion >>/tmp/delv.log                         
pdf                                                              
}                                                                
################Begin process################                    
IFS="~"                                                          
read UID TO SUBJECT MEMO discard                                 
IFS=" "                                                          
#UID=$1; export UID                                              
#TO=$2; export TO                                                
#SUBJECT=$3                                                      
#MEMO=$4                                                         
if [ ! -r $MEMO ]                                                
then                                                             
        MEMO=/u2/email/default.memo                              
fi                                                               
HWD=`pwd`; export HWD                                            
ed $MEMO </u2/email/ff.inp >/dev/null                            
HDRS=/u1/ltrs/header.txt; export HDRS                             TRLR=/u1/ltrs/trailer.txt; export TRLR                           
files="$*"                                                       
echo To: $TO                                                     
echo From: $UID                                                  
echo Reply-to: $UID                                              
echo Subject: $SUBJECT                                           
echo Remarks: $req                                               
echo Mime-Version: 1.0                                           
echo "Content-Type: multipart/mixed;"                            
echo "  boundary=\"PART-BOUNDARY.abcdefghijklmnopqrstuvwxyz\"\n" 
echo --PART-BOUNDARY.abcdefghijklmnopqrstuvwxyz                  
echo "Content-Type: text/plain; charset=us-ascii\n"              
cat $MEMO                                                        
echo                                                             
cat $TRLR                                                        
echo "\n"                                                        
echo `date` $req $files, all attachments >>/tmp/delv.log         
for tiff in $files                                               
do                                                               
EXT=`echo $tiff|cut -d"." -f2`       
 filename=`echo $tiff|cut -d"." -f1`           
#convert attachment based on extension
$EXT                                              
done                                              
echo --PART-BOUNDARY.abcdefghijklmnopqrstuvwxyz--

You will have to add a routine to convert a csv file and create a html section.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Content of attachment is displaying along with subject in mailx

Hi All, I want to send the csv to an email address. I have tried the below two approaches. Approach1: Got error -ksh: uuencode: not found $ uuencode test_file.csv test_file.csv | mailx -s "Attaching test" msdc.kiran@gmail.com </usr/home/test_file.csv -ksh: uuencode: not found Approach2:... (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

2. Shell Programming and Scripting

Facing issues with Content-Type:application/x-download Content-Disposition:attachment

I am in the process of developing a perl cgi page. I had succeeded in developing the page but there are few errors/issues with the page. description about cgi page: My CGI page retrieves all the file names from an directory and displays the files in drop down menu for downloading the... (5 Replies)
Discussion started by: scriptscript
5 Replies

3. Solaris

mailx with attachment

Hi, When i used below command, i am able to send mail mailx -s "Testing mail working or not " babu.sudhakar@ymail.com" but if i want send attachment with mail,which syntax i need to follow to send a file as attachment. (3 Replies)
Discussion started by: sridhardwh
3 Replies

4. UNIX for Dummies Questions & Answers

Sending html email with html attachment

Hello, I have a script which is sending an html file as an attachment. #!/usr/bin/ksh export MAILTO="user@company.com" export CONTENT="/usr/tmp/file.html" export SUBJECT="EmailSubject" ( echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo "Content-Type: text/html" echo... (0 Replies)
Discussion started by: sreenathkg
0 Replies

5. Red Hat

Send HTML body and HTML attachment using MUTT command

Hi there.. I need a proper "mutt" command to send a mail with html body and html attachment at a time. Also if possible let me know the other commands to do this task. Please help me.. (2 Replies)
Discussion started by: vickramshetty
2 Replies

6. HP-UX

mailx with -m attachment corrupted

mailx with -m command sending emails with attachments correctly to all users except users who have email on microsoft exchange server. They are receiving attachments as garbled text in mail body (5 Replies)
Discussion started by: sankalpag
5 Replies

7. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

8. Shell Programming and Scripting

Sendmail with html attachment and html body

Hi folks, I have a perl script which sends out email after successful completion of job as inline html, I want to send it out as two parts now as html inline and html attachment. see the attached script. Thanks in advance (1 Reply)
Discussion started by: sol_nov
1 Replies

9. Shell Programming and Scripting

Adding an attachment as an attachment to mailx

I don't want the attachment embedded in the mail. I would like a file attached. When I do mailx -s "Report, `date +'%D %r` " -r "Notifications" bob@bob.com < /usr/local/bin/myreport.log> /dev/null It gets embedded in my email. I want a file attachment. How do I do that? (2 Replies)
Discussion started by: guessingo
2 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