0

When I try to read a file and send email using cat and sendmail, the email I receive has additional spaces between the letters of words in the text.

My code:

export MAILTO="sa@y.com"
export SUBJECT="mydomain PREPROD MONITOR AT ${DATE}"
export BODY1="/usr/local/oracle/wls1036/domains/mydomain/bin/mydomainmonitor/mydomainmonitor.log"

(
  echo "To: $MAILTO"
  echo "Subject: $SUBJECT"
  echo "MIME-Version: 1.0"
  echo "Content-Type:text/html"
  echo "Content-Disposition: inline"

  cat $BODY1

) | /usr/sbin/sendmail -i $MAILTO

Please let me know why these additional spaces are added. When I check the file I don't see any spaces in there.

tripleee
  • 175,061
  • 34
  • 275
  • 318
SSA
  • 73
  • 1
  • 9
  • 1
    The `export` commands are superfluous here -- you only need them if a child process needs access to the environment. A subshell `( command )` sees them because they are interpolated by the current shell when the subshell is spawned. – tripleee Apr 27 '14 at 18:49
  • agreed and corrected. Thanks – SSA Apr 27 '14 at 19:38

2 Answers2

1

If the file has long lines, Sendmail needs to break them.

The transparent way to ensure the integrity of data is to use a simple MIME wrapper. You probably want to use a properly MIME-aware MUA to piece together a properly formatted message, but doing it by hand basically amounts to adding a Content-Transfer-Encoding: quoted-printable header, and correspondingly QP-encoding the body.

MAILTO="sa@y.com"
SUBJECT="mydomain PREPROD MONITOR AT ${DATE}"
BODY1="/usr/local/oracle/wls1036/domains/mydomain/bin/mydomainmonitor/mydomainmonitor.log"

( cat <<____HEADERS
To: $MAILTO
Subject: $SUBJECT
MIME-Version: 1.0
Content-Type:text/html
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

____HEADERS

# Really quick and dirty; does not implement full QP
perl -pe 's/=/=3D/g;s/(.{72})/$1=\n/g' "$BODY1"

) | /usr/sbin/sendmail -i $MAILTO
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • while I test it, can you please explain perl -pe 's/=/=3D/g;s/(.{72})/$1=\n/g' "$BODY1" what is this doing? – SSA Apr 27 '14 at 19:39
  • I tested this and the it doesnt add whitespaces now, instead it is adding "D" in the email: eg: suppossed to be: HeapFreePercent= 27, but displayed as HeapFreePercent= D27 – SSA Apr 27 '14 at 19:48
  • `s/=/=3D/g` replaces each equals sign with its QP equivalent. `s/(.{72})/$1=\n/g` splits overlong lines by inserting = and a newline every 72 characters. – tripleee Apr 27 '14 at 19:56
  • If you have access to a proper QP encoder then by all means use that instead. – tripleee Apr 27 '14 at 19:57
  • based on your suggestion, I broke the line in my output file to multiple lines using \n which resolved the white spaces issue. – SSA Apr 28 '14 at 10:21
0

I broke the output to my log file into multiple lines using new line char. Now send mail is sending the email correctly without any additional spaces.

SSA
  • 73
  • 1
  • 9