Unable to send the email in formatted way

Legends,

I have following entries in

/tmp/a.txt

file

GAP Ric XEOJ181477500.W Flag2 5 Sym XEO1418J775-E msg SEQ_NO:159 db:5 diff 154 process msg
GAP Ric XEOJ181400.W Flag2 19 Sym XE418J815-E msg SEQ_NO:101 db:5 diff 96 process msg
GAP Ric XEOJ18140.W Flag2 18 Sym XEO18J855-E msg SEQ_NO:88 db:5 diff 83 process msg
GAP Ric XEOK221400.W Flag2 18 Sym XE422K690-E msg SEQ_NO:104 db:5 diff 99 process msg
GAP Ric XEOJ181400.W Flag2 3 Sym XEO18J705-E msg SEQ_NO:83 db:5 diff 78 process msg
GAP Ric XEOJ1814500.W Flag2 23 Sym X1418J865-E msg SEQ_NO:85 db:5 diff 80 process msg

I am using the following in sendmail but the email is coming in plain text without any new line as per the file

#!/usr/bin/bash
{
echo "From: "
echo "To: abc@xyz.com"
echo "Subject: GAPReport"
echo "Content-Type: text/html"

cat /tmp/a.txt
} | /usr/sbin/sendmail -t

Please help me getting a formatted email in the inbox

If you like you can add attachment to the email.

uuencode path/file file | mailx -s "your subject" sender@email.com
Else use 
Mailx -s "your subject" sender@email.com< path/file
1 Like

No luck with mailx. Actually after some code written in script i am sending the email.
I am not using mailx from command prompt.
Sorry if i was not clear in my first post

Hello sdosanjh,

Could you please try following and let me know if this helps.

cat - ${Filename} <<EOF | /usr/sbin/sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF

NOTE: Where Filename, MAILFROM, MAILTO, SUBJECT are the variables which you can define them.

Thanks,
R. Singh

1 Like

I got the email as HTML format now, but there is no new lines.
everything is in continuation

GAP Ric FEYEI201402550.M4 Flag2 10 Sym FEYE1420I25.5-4 msg SEQ_NO:1223 db:5 diff 1218 process msg GAP Ric FEYEI201402850.M4 Flag2 11 Sym FEYE1420I28.5-4 msg SEQ_NO: 2233 db: 5 diff 2228 ; Process msg GAP Ric FEYEI201403150.M4 Flag2 15 Sym FEYE1420I31.5-4 msg SEQ_NO:982 db:5 diff 977 process msg GAP Ric FEYEI201402300.M4 Flag2 13 Sym FEYE1420I23-4 msg SEQ_NO:342 db:5 diff 337 process msg GAP Ric FEYEI201402350.M4 Flag2 21 Sym FEYE1420I23.5-4 msg SEQ_NO:739 db:5 diff 734 process msg GAP Ric FEYEI201403650.M4 Flag2 17 Sym FEYE1420I36.5-4 msg SEQ_NO:263 db:5 diff 258 process msg GAP Ric FEYEI201402450.M4 Flag2 23 Sym FEYE1420I24.5-4 msg SEQ_NO:565 db:5 diff 560 process msg GAP Ric FEYEI201403350.M4 Flag2 9 Sym FEYE1420I33.5-4 msg SEQ_NO:465 db:5 diff 460 process msg GAP Ric FEYEU201402300.M4 Flag2 11 Sym FEYE1420U23-4 msg SEQ_NO:403 db:5 diff 398 process msg GAP Ric FEYEU201402450.M4 Flag2 3 Sym FEYE1420U24.5-4 msg SEQ_NO:703 db:5 diff 698 process msg GAP Ric FEYEU201402850.M4 Flag2 15 Sym FEYE1420U28.5-4 msg SEQ_NO:1940 db:5 diff 1935 process msg GAP Ric FEYEU201403450.M4 Flag2 15 Sym FEYE1420U34.5-4 msg SEQ_NO:842 db:5 diff 837 process msg GAP Ric FEYEU201403350.M4 Flag2 17 Sym FEYE1420U33.5-4 msg SEQ_NO:869 db:5 diff 864 process msg GAP Ric FEYEU201403650.M4 Flag2 9 Sym FEYE1420U36.5-4 msg SEQ_NO:462 db:5 diff 457 process msg GAP Ric FDOI201406950.QB Flag2 17 Sym FDO1420I69.5-J msg SEQ_NO:31 db:5 diff 26 process msg GAP Ric FDOI201407350.QB Flag2 3 Sym FDO1420I73.5-J msg 

Can someone pls help, issue is still open.

awk 'BEGIN{print "<pre>"}1' ORS='<br>' ${Filename} <<EOF | /usr/sbin/sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF
1 Like

Why are you using "Content-Type: text/html", since you are not using html to format the email? Try leaving it out or try using "Content-Type: text/plain" .

@Srinishoo

I am getting the below error

awk: syntax error near line 1
awk: bailing out near line 1
No recipient addresses found in header

---------- Post updated at 05:08 PM ---------- Previous update was at 05:04 PM ----------

@Scrutinizer,
I tried plain content-type; but is same email without new line.

You haven't said what OS you're using. If you using Solaris/SunOS, change awk to /usr/xpg4/bin/awk in the script.

1 Like

@Don Cragun,
sorry i missed that info part. it is SunOS.

Awk error is no more existing now after changing it to

/usr/xpg4/bin/awk

The new error came now, despite of giving From and To:
I am getting the below error now

No recipient addresses found in header

Provide us the entire script (masking sensitive data) so that we can look into for errors

---------- Post updated at 11:24 PM ---------- Previous update was at 11:21 PM ----------

But the error you have provided tells that you have missed To part
If you are using the script as it is, assign the 'To' address to MAILTO variable

How are Filename , MAILFROM , MAILTO , and SUBJECT set when you get to the here-document in your script?

Here is entire code

/usr/xpg4/bin/awk 'BEGIN{print "<pre>"}1' ORS='<br>' ${FILE}.txt <<EOF | /usr/sbin/sendmail -oi -t
From: abc@xyz.com
To: def@xyz.com
Subject: GAP Report
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF

2nd time i tried as below; but error was same

MAILFROM=`hostname`
MAILTO='def@xyz.com'
/usr/xpg4/bin/awk 'BEGIN{print "<pre>"}1' ORS='<br>' ${FILE}.txt <<EOF | /usr/sbin/sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: GAP Report
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF

You cannot use a filename and a redirect like that. Try:

#!/usr/bin/bash
/usr/sbin/sendmail -oi -t <<EOF
From: abc@xyz.com
To: def@xyz.com
Subject: GAP Report
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
$(/usr/xpg4/bin/awk 'BEGIN{print "<pre>"}1' ORS='<br>' ${FILE}.txt)
EOF
1 Like

@srinishoo,
posting the code after masking

#!/usr/bin/bash

FILE=/tmp/RicGapInfo
DAY=`date  |awk '{print $1}'| tr -s '[:upper:]' '[:lower:]'`

LIST=`grep perRicGapCount /tmp/alert.$DAY | awk '{print $5}' | sort|uniq`

if [ -f $FILE ];
then
        rm -f $FILE
fi

if [ -z $LIST ];
then
        echo "No perRicGapCount on `hostname`" >> ${FILE} <= here normal mail also works fine since it is only one line
fi

for i in $LIST
do
         Command here to get missing data | grep GAP >> ${FILE}
done

MAILFROM=`hostname`
MAILTO='def@xyz.com'
/usr/xpg4/bin/awk 'BEGIN{print "<pre>"}1' ORS='<br>' ${FILE} <<EOF | /usr/sbin/sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: GAP Report perRic
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF

---------- Post updated at 10:12 PM ---------- Previous update was at 09:48 PM ----------

@scrutinizer,
that worked :slight_smile: thanks for your help

But the email received have unexpected line breaks.
like below

GAP Ric FEYEU2012300.M4 Flag2 11 Sym FEYE14223-4 msg SEQ_NO:403 db:5 diff 398 process msg
GAP Ric FEYEU2012450.M4 Flag2 3 Sym FEY420U24.5-4 msg SEQ_NO:703 db:5 d!
 iff 698 process msg
GAP Ric FEYEU2402850.M4 Flag2 15 Sym FE1420U28.5-4 msg SEQ_NO:1940 db:5 diff 1935 process msg

GAP Ric FEYEU2002300.M4 Flag2 11 Sym FEY420U23-4 msg SEQ_NO:403 db:5 diff 398 process msg
GAP Ric FEYEU2002450.M4 Flag2 3 Sym FEYE10U24.5-4 msg SEQ_NO:703 db:5 d!
 iff 698 process msg
GAP Ric FEYEU2012850.M4 Flag2 15 Sym FEY420U28.5-4 msg SEQ_NO:1940 db:5 diff 1935 process msg

---------- Post updated 08-26-14 at 06:04 PM ---------- Previous update was 08-25-14 at 10:12 PM ----------

pls help i am still getting broken characters email

GAP Ric FEYEU2012300.M4 Flag2 11 Sym FEYE14223-4 msg SEQ_NO:403 db:5 diff 398 process msg
GAP Ric FEYEU2012450.M4 Flag2 3 Sym FEY420U24.5-4 msg SEQ_NO:703 db:5 d!
 iff 698 process msg
GAP Ric FEYEU2402850.M4 Flag2 15 Sym FE1420U28.5-4 msg SEQ_NO:1940 db:5 diff 1935 process msg

GAP Ric FEYEU2002300.M4 Flag2 11 Sym FEY420U23-4 msg SEQ_NO:403 db:5 diff 398 process msg
GAP Ric FEYEU2002450.M4 Flag2 3 Sym FEYE10U24.5-4 msg SEQ_NO:703 db:5 d!
 iff 698 process msg
GAP Ric FEYEU2012850.M4 Flag2 15 Sym FEY420U28.5-4 msg SEQ_NO:1940 db:5 diff 1935 process msg

how is the content in ${FILE} ?
check if that too had the broken lines

contents in file is not broken. it is a simple text file

GAP Ric FEYEI201402300.M4 Flag2 13 Sym FEYE1420I23-4 msg SEQ_NO:342 db:5 diff 337 process msg
GAP Ric FEYEI201402350.M4 Flag2 21 Sym FEYE1420I23.5-4 msg SEQ_NO:739 db:5 diff 734 process msg
GAP Ric FEYEI201403650.M4 Flag2 17 Sym FEYE1420I36.5-4 msg SEQ_NO:263 db:5 diff 258 process msg
GAP Ric FEYEI201402450.M4 Flag2 23 Sym FEYE1420I24.5-4 msg SEQ_NO:565 db:5 diff 560 process msg
GAP Ric FEYEI201403350.M4 Flag2 9 Sym FEYE1420I33.5-4 msg SEQ_NO:465 db:5 diff 460 process msg
GAP Ric FEYEU201402300.M4 Flag2 11 Sym FEYE1420U23-4 msg SEQ_NO:403 db:5 diff 398 process msg
GAP Ric FEYEU201402450.M4 Flag2 3 Sym FEYE1420U24.5-4 msg SEQ_NO:703 db:5 diff 698 process msg
GAP Ric FEYEU201402850.M4 Flag2 15 Sym FEYE1420U28.5-4 msg SEQ_NO:1940 db:5 diff 1935 process msg
% file /tmp/RicGapInfo.txt
/tmp/RicGapInfo.txt:    ascii text

Removed the <br> part. use the below code and comment

#!/usr/bin/bash
/usr/sbin/sendmail -oi -t <<EOF
From: abc@xyz.com
To: def@xyz.com
Subject: GAP Report
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
$(/usr/xpg4/bin/awk 'BEGIN{print "<pre>"}1' ${FILE}.txt)
EOF
2 Likes

@SriniShoo..and Moderators...
Thanks..
You rocked and it worked :slight_smile: