PDA

View Full Version : SendMail embedding linefeeds in the message body


Flournoy
11-18-02, 14:44
OK, first, I haven't even begun unix 101 or shell scripts so go easy with me. This is what we're using and it works, I'd just like to dress up the body by inserting newline/return/LFCR, tabs, etc .... Is it possible?

java SendMail -g est04grp -f pcunix -s "EST04 Notification" -m "Attached please find two reports: est04.fc.new which contains a list of original Final Certificates printed and est04.fc.rep which contains a list of reprinted Final Certificates. Please contact Jeff Miller, if there are any questions or concerns. Thank you." -a "$NEW_FC_REPORT" -a "$REPRINTED_FC_REPORT"

Damian Ibbotson
11-19-02, 05:46
You should be able to use escape sequences with the backslash character...

The example below is all on one line.

echo "Here is a newline...\n\t...and this line begins with a tab\nand here is \"some text\" in enclosed quotes."

Here is a newline...
...and this line begins with a tab
and here is "some text" in enclosed quotes.

WingMan
11-19-02, 13:30
go Damian :)

Flournoy
11-19-02, 13:37
It didn't work, the email is recieved with the slashes and characters printed with the text. I've tried separating the message with quotes and putting the control characters between the lines and it still prints the control characters within the body. HELP !

WingMan
11-26-02, 12:02
Humm .... Have you tried putting the text into a script variable, and then using the script variable in the mail statement ??

Flournoy
11-26-02, 13:14
Yes, I have, it printed the control characters in the body.

MY_MESSAGE="HELLO....\n\t...did it work"

java SendMail -g est04grp -f pcunix -s "My Test" -m $MY_MESSAGE

And it printed in the body of the e-mail:

HELLO....\n\t...did it work


I don't know what the problem is .....

Damian Ibbotson
11-27-02, 13:14
I'm not sure what could be going on here. I've posted a thread on comp.unix.shell which might throw some light on the subject.

http://dbforums.com/t579094.html

backer
11-27-02, 16:11
Originally posted by Flournoy
Yes, I have, it printed the control characters in the body.

MY_MESSAGE="HELLO....\n\t...did it work"

java SendMail -g est04grp -f pcunix -s "My Test" -m $MY_MESSAGE

And it printed in the body of the e-mail:

HELLO....\n\t...did it work


I don't know what the problem is .....


How about not putting your \'s in quotes... end quotes before the slash?

backer
11-27-02, 16:13
Originally posted by backer
How about not putting your \'s in quotes... end quotes before the slash?

That almost appeared how I wanted it .. :(

I was trying to say, \\'s maybe?

Flournoy
11-27-02, 16:47
I've tried that,
MY_MESSAGE="HELLO...."\n\t"...did it work"
prints
HELLO....\n\t...did it work
go figure ....

With spaces
MY_MESSAGE="HELLO...." \n\t "...did it work"
prints
HELLO....

This looks way to easy to be so hard ......

Damian Ibbotson
11-28-02, 11:30
I've tried this and it seems to work okay...

public class JavaTest {
public static void main (String[] args) {
System.out.println(args[0]);
}
}

java JavaTest "Text
on
many
lines."

The output looks like this:

Text
on
many
lines.

If passing in your message body parameter over multiple lines doesn't work, I would suggest that the SendMail application is stripping out the newlines.

jmcphe
12-15-02, 17:56
good old meta characters. instead of double quotes " use single quotes '
if that doesn't work you may need to escape your backslashes \ with a backslash \ themselves.

Check this. To ftp into an NT ftp server from a unix one, I had to do the following:
user domain\\\\name password

a the 4 backslashes send 2 backslashes to the script, which sends 1 backslash to the ftp program. I think you're running into the same thing. Your stuffs is being interpretted in the double quotes. single quotes will kill the issue if you're using a unix shell. escaping the backslash \ escape character with an escape character, namely a backslash, will send a literal backslash through. Of course, you may have to do what I did and escape the escape of the escape. Hehehe. any wonder why regular expressions look so funny?

jmcphe
12-15-02, 18:10
oops. I misread the thread. Please ignore my above lame comments. In atonement, I offer the following
$ var="foo\nbar"; export var
$ echo $var
foo
bar
$ var2=`echo $var`; export var2
$ echo $var2
foo bar
$ cat << !!
> $var2
> !!
foo
bar


Go figure, huh? Cat isn't interpretting the newlines into their ascii equivalents, but if you feed the already interpretted newlines into it, it works, but breaks the original. I'll leave it up to ya'll.