Send Email To Windows OS Preserving The Format

I am trying to send an email using mailx and mutt commands with a body inside it. For some reason all the lines in the body are coming as one line, i figured it's not the issue with mailx/mutt but with line feed & carriage returns. So I tried adding carriage returns with below command based on other posts but still it doesn't help me. Can you please help me what i am missing?

sed 's/$/\r/' unix.txt > win.txt

Actual Code:

for i in `cat "${GEN_PARAM_LIST3}"`
do
        UNINUM=`echo $i | awk -F"|" '{print $1}'`
        PROVIDER=`echo $i | awk -F"|" '{print $2}'`
        EXTRACT_DT=`echo $i | awk -F"|" '{print $3}'`
        PROCESS_STATUS=`echo $i | awk -F"|" '{print $4}'`

        echo "Provider:"$PROVIDER", Uninum:"$UNINUM", Extract Date:"$EXTRACT_DT", Loading Status:"$PROCESS_STATUS"" \
             >> "${LOG_DIR}"/StageLoadEmailBody

done
(cat ${LOG_DIR}/StageLoadEmailBody) | /bin/mailx -s "Provider File Loaded Successfully" "${EMAIL_LIST}"

Thank you.

I use a .mailrc file:

set crt=21
set encoding=8bit
set charset=iso-8859-1
# set mimeheader=yes

( here its HP-UX to WIN...)

Just noticed, you have not done a ux2dos /unix2dos before !

(cat ${LOG_DIR}/StageLoadEmailBody) | ux2dos | /bin/mailx -s "Provider File Loaded Successfully" "${EMAIL_LIST}"

It's still not working. Everything coming in one line

Informatica Was Able To Successfully Load the Provider File Provider:16, Uninum:710119, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:610000, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710056, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710122, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710139, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710739, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710150, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710549, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710862, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710551, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710973, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710981, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710990, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:810586, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710566, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710659, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710924, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710985, Extract Date:2012-09-30, Loading Status:COMPLETED

---------- Post updated at 11:04 AM ---------- Previous update was at 10:57 AM ----------

when i do below i am getting line space between lines which i don't want.

 echo -e "\r\nProvider:"$PROVIDER", Uninum:"$UNINUM", Extract Date:"$EXTRACT_DT", Loading Status:"$PROCESS_STATUS"" \
             >> "${LOG_DIR}"/StageLoadEmailBody

Output:

Informatica Was Able To Successfully Load the Provider File


Provider:16, Uninum:710119, Extract Date:2012-09-30, Loading Status:COMPLETED

Provider:16, Uninum:610000, Extract Date:2012-09-30, Loading Status:COMPLETED

Provider:16, Uninum:710056, Extract Date:2012-09-30, Loading Status:COMPLETED

Try removing the \r

What are you using ux2dos or unix2dos ?
Have you tried with the file StageLoadEmailBody without mail e.g.
via samba nfs ftp ... on win and open the file?
It must work here first...
try:

 ux2dos StageLoadEmailBody>StageLoadEmailBody.txt 

and look on you PC if the file is multy line...

Apologies for not posting the version of my OS

Linux XXXX.com 2.6.18-348.3.1.el5 #1 SMP Tue Mar 5 13:19:32 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

I don't have ux2dos. I tried sending the email to my outlook and yahoo looks ok but outlook its coming in single line or if i use "echo -e \r\n or only \r" its putting an extra space between lines.

To Corona688:
when i tried that i am seeing spaces between lines.

please help

You dont have ux2dos so there is chance you have unix2dos then...

Well if not this is how CFA Johnson does it (In his book and is contributor here...):

#! /usr/bin/ksh
progname=${0##*/}
CR=$(printf "\r")
tempfile=$(mktemp $progname.XXXXXX) || exit 5
for file
do
   sed -e "s/$/$CR/" -e "s/$CR$CR$/$CR/" "$file" > "$tempfile" &&
   mv "$tempfile" "$file"
done

call it ux2dos and make it executable...

okay i used the unix2dos, when i check in outlook it all in single line. But when i download the actual data file into Windows OS via winscp and looked at it looks fine..

Outlook:

Informatica Was Able To Successfully Load the Provider File Provider:16, Uninum:710119, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:610000, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710056, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710122, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710139, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710739, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710150, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710549, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710862, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710551, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710973, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710981, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710990, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:810586, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710566, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710659, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710924, Extract Date:2012-09-30, Loading Status:COMPLETED Provider:16, Uninum:710985, Extract Date:2012-09-30, Loading Status:COMPLETED

Download to Windows:

Informatica Was Able To Successfully Load the Provider File
Provider:16, Uninum:710119, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:610000, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710056, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710122, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710139, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710739, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710150, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710549, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710862, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710551, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710973, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710981, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710990, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:810586, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710566, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710659, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710924, Extract Date:2012-09-30, Loading Status:COMPLETED
Provider:16, Uninum:710985, Extract Date:2012-09-30, Loading Status:COMPLETED

Modified code:

 echo "Provider:"$PROVIDER", Uninum:"$UNINUM", Extract Date:"$EXTRACT_DT", Loading Status:"$PROCESS_STATUS"" \
             >> "${LOG_DIR}"/StageLoadEmailBody

done
(cat ${LOG_DIR}/StageLoadEmailBody) | unix2dos | /bin/mailx -s "Provider File Loaded Successfully" "${EMAIL_LIST}"

I need the the output in outlook also in same format please help
Thank you.

Just tested for you:

\tail -8  /var/cron/log/m_ux.log | \ux2dos | \mailx -s "Aaaarghh NO MILK FOR MY MORNING TEA " me@mywork.com 

Works...

Do i need to make any changes it's not working for me. email is coming out as empty. I made a executable(755) file called ux2dos in my bin directory. I changed the script to below.

echo "Provider:"$PROVIDER", Uninum:"$UNINUM", Extract Date:"$EXTRACT_DT", Loading Status:"$PROCESS_STATUS"" \
             >> "${LOG_DIR}"/StageLoadEmailBody

done
(cat ${LOG_DIR}/StageLoadEmailBody) | ux2dos | /bin/mailx -s "Provider File Loaded Successfully" "${EMAIL_LIST}"

Try like this

\cat $LOG_DIR/StageLoadEmailBody | \ux2dos | \/bin/mailx -s "Provider File Loaded Successfully" "${EMAIL_LIST}"

The email body is coming out as empty..I am using bash and dos2unix is in ksh. is that causing the issue?

That script ought to work fine in bash, it and ksh are similar in many ways.

It expects a filename, though. unix2dos filename It will edit the file.

I tried using unix2dos as well, for some reason in the outlook i see spaces between the lines.

---------- Post updated at 01:48 PM ---------- Previous update was at 01:30 PM ----------

I didn't understand and not able to figure out what's happening. when i edit sample.txt file and use a simple command.

 mailx -s "Test" "xxx@fxxxg.com" <sample.txt

every line is intact. But when i send email with file generated from echo commands and all format options its still not working...i am frustrated.

Hello Everyone
Is this thing really difficult

---------- Post updated at 02:15 PM ---------- Previous update was at 01:48 PM ----------

Finally, if i remove the commas its working fine i see the expected format in outlook all lines. Do you know why please ?

     #echo "Provider:"$PROVIDER", Uninum:"$UNINUM", Extract Date:"$EXTRACT_DT", Loading Status:"$PROCESS_STATUS"" \
        #>> "${LOG_DIR}"/StageLoadEmailBody
        echo "Provider:$PROVIDER Uninum:$UNINUM Extract Date:$EXTRACT_DT Loading Status:$PROCESS_STATUS" >> "${LOG_DIR}"/StageLoadEmailBody
        #echo -e "\r">> "${LOG_DIR}"/StageLoadEmailBody
done
(cat "${LOG_DIR}/StageLoadEmailBody") | /bin/mailx -s "Provider File Loaded Successfully" "${EMAIL_LIST}"

probably outlook intelligently treating comma as continuation of paragraph hence wrapping up the lines ..quite a ride
Thank you