Sending mail in UNIX with body and attachment(.txt) using sendmail command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sending mail in UNIX with body and attachment(.txt) using sendmail command
# 1  
Old 10-10-2013
Sending mail in UNIX with body and attachment(.txt) using sendmail command

Hi All,

In my .ksh script, I am sending an email with body and attachment (.txt) using sendmail command. I am able to receive the attachement along with the body of the mail. But I am getting special characters along with the content in the .txt. Also the alignment is incorrect. Can you please suggest how to avoid special characters and misallignment.

Below is the code I am using,

Code:
 # Code for sending mail - start
export MAILTO=$list 
export SUBJECT="Subject of the mail"
export BODY=$OUTPIPE
export ATTACH=$records.txt
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 cat $BODY
 uuencode $ATTACH $(basename $ATTACH)
) | sendmail $MAILTO
# Code for sending mail - end


Last edited by KRR; 10-12-2013 at 04:04 PM..
# 2  
Old 10-10-2013
Depends, but this is a bit vague. What are you reading the mail in. Try using strings

Code:
.
.
.
cat $BODY | strings   
.
.
.

Post sample of mail message that "appears" incorrect. What does the message look like when you read it with unix mail?
This User Gave Thanks to blackrageous For This Post:
# 3  
Old 10-10-2013
Hi, Thanks for u r reply, the attachement is attached
# 4  
Old 10-11-2013
If you are reading the mail with Microsoft Office Outlook, look at the following setting in that program:
Tools / Options / Email Options / "Remove extra line breaks in plain text messages".
If that option is set, uncheck the box.
# 5  
Old 10-11-2013
Thanks for your reply Methyl, Even if I download the .txt file and open, the alignment is incorrect. The sample .txt file is attached in my request. But if I open it with word pad it looks good. But client requires .txt with proper alignment. Is there any parameter I need to pass while sending mail from unix to windows?
# 6  
Old 10-12-2013
If you want to convert text attachments to Windoze style, replace
uuencode $ATTACH
by
unix2dos $ATTACH | uuencode
If you don't have unix2dos then look it up in Wikipedia for a replacement.
NB this will corrupt a binary attachment.
# 7  
Old 10-12-2013
Quote:
Originally Posted by KRR
Is there any parameter I need to pass while sending mail from unix to windows?
Not directly: Your problem is missing/wrong line breaks and the reason for this is that UNIX(oid) systems and DOS(-like) systems have different standards for what a line break constitutes. The following:

Code:
line 1
line 2

would be represented by the characters:

Code:
line 1<cr>line 2

in UNICes and by

Code:
line 1<cr><lf>line 2

in DOSses.

The reason for this is that the developers of DOS shied away from implementing printing filters. Instead they adopted a "standard" which could be sent to a printer directly and still print correctly because the control characters necessary for carriage return (<cr>, 0Dh) and line feed (<lf>, 0Ah) were already in the files.

unix2dos (and recode and similar tools) correct just this small detail. In "ftp" you may have noticed the mode "ASCII" and "binary". These modes are about the same difference, in "ASCII" mode line breaks are corrected during transfer, in "binary" the files are passed "as is".

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending mail with attachment(image) using sendmail in Linux(ksh)

Hi guys, I am trying to send a mail with below command which is working fine. $FilePath_mail have To,From and other information along with mail body which is in HTML format. I want to have image(logo) in the body. So just wanted to send it as an an attachment. /usr/sbin/sendmail -t <... (1 Reply)
Discussion started by: balakrishnaps
1 Replies

2. Shell Programming and Scripting

Sending attachment using sendmail command

Send_Mail() { C_Date=`date +"%m/%d/%Y"` #Subject="MMDB Load Job Status" for i in `cat $Metafile` do if then email_address=`echo $i | cut -d":" -f2` /usr/lib/sendmail "$email_address" < $Email_File fi done } this is the send mail command i am using .please let me... (1 Reply)
Discussion started by: Alok K Yadav
1 Replies

3. Shell Programming and Scripting

problem with sending mail from txt file having HTML code via sendmail -t

Hi, i have the following code in shell named as test3.sh.. #!/bin/sh . /home/<user>/.profile export dt=`date "+%d%b%y"` export tim=`date "+%d%b%y %HM:%MM"` cd export WD=`pwd` SID="<sid>" export SID export ORACLE_SID=$SID export ORACLE_HOME=/oracle/$SID/102_64 export... (4 Replies)
Discussion started by: jassi10781
4 Replies

4. UNIX for Dummies Questions & Answers

Sending email with attachment and body

Hi I want to able to attach a file to a email and send it with a body the body of the email is within the "body" file, and the attachment in "atch" if i send like below it will send the email correctly /usr/sbin/sendmail me@you.com< body And when i send the attachment alone... (3 Replies)
Discussion started by: sridanu
3 Replies

5. Shell Programming and Scripting

unix mail body with attachment

How can I send mail with attachment in HP-UX I am able to send mail with specific body,but not successful while attaching a file. I am using the below command however it stuck : uuencode test.txt |mailx -s "Subject" <e-mail id> (5 Replies)
Discussion started by: gautamadak
5 Replies

6. Shell Programming and Scripting

Not able to attach text in body of email while sending mail with attachment

Hi, We have been trying to send mail with attachment and it is going fine, but when we try to attach a text to the body of the email, we find that the mail is going fine with the body text but the attachment is not going through. We are using ksh. The command that is successfull without the... (6 Replies)
Discussion started by: jmathew99
6 Replies

7. UNIX for Dummies Questions & Answers

Issue on sending a mail with attachment using unix script ?

Issue on sending a mail with attachment using unix script ? Below is my code and is working fine and there is a issue in the attachment, the attachment file printing as a text-encripted message in the mail draft box instead of putting as a attachment (cat $msg; uuencode $attach1 in1.txt ;... (2 Replies)
Discussion started by: gksenthilkumar
2 Replies

8. Shell Programming and Scripting

Attaching file and sending text in body using sendmail command!!

Hello, I need to send with text in the body and 2 files as attachments using sendmail command. i can send only one at a time either attachment or text in body of email. Can any one please help me how to get that? I will be great for any help. Thanks, Sparan (1 Reply)
Discussion started by: sparan_peddu
1 Replies

9. AIX

Command line/Script to send E-mail with HTML body and binary attachment

I apoligize for the cross-post but I'm not getting much in the way of help in the dummies forum: I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements: 1. command line switch to specify file name containing message body in HTML format 2. command... (3 Replies)
Discussion started by: G-Man
3 Replies

10. UNIX for Advanced & Expert Users

sending mails with attachment and also some text in mail body

Hi, Can some one help me with the syntax of the mailx that should send an attachment and also some text in the message body together. When I am using the following syntax it is not sending the attachment but only the message body. unix2dos -ascii $REPORTFILE | uuencode $PCFILE | mailx -s... (7 Replies)
Discussion started by: guptan
7 Replies
Login or Register to Ask a Question