Board index » cppbuilder » How to get line feeds in the body of IdSMTP

How to get line feeds in the body of IdSMTP


2008-01-16 01:37:20 AM
cppbuilder104
Hi,
I'm using the IdSMTP component to send emails, multipart, and it basically works fine. However, when I enter text into th body section of the IdMessage, I lose any linefeeds there might have been. This is my code:-
TIdText *Text = new TIdText(IdMessage1->MessageParts,NULL);
Text->ContentType = "text/plain";
Text->Body->Text = acBody;
Where acBody is char acBody[512];
I am using BDS2006 on an XP machine.
I have tried inserting \r\n etc., but to no avail.
I have also tried using the Text from a TMemo.
What am I doing wrong?
Thanks,
David
 
 

Re:How to get line feeds in the body of IdSMTP

Asger Joergensen < XXXX@XXXXX.COM >wrote:
Quote

I don't know the answer to Your problem, but I just thought
that this might be because the \r\n is changed to \n when
it goes throug a unix/linux server s=C3=A5 You might need to do a
replace on the recieved text:

Replace \n with \r\n
I've tried various combinations but haven't found the right one.
Quote

P.s. please break Your text lines.
Sorry. A lapse of concentration.
Cheers,
David
 

Re:How to get line feeds in the body of IdSMTP

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

TIdMessage and TIdSMTP do not strip line breaks out of the message whern
sending it.

>Where acBody is char acBody[512];

Is it always null-terminated?
Yes. I have tried something like this:-
strcpy(acBody,"Some words.\r\nSome more words\r\nEtc etc");
and the received email comes out like this:-
Some words.Some more wordsEtc etc
I have also tried entering the message into a TMemo with
WantReturns set true and then doing this:-
strcpy(acBody,Memo1->Text.c_str()); and I get the same result.
Cheers,
David
 

{smallsort}

Re:How to get line feeds in the body of IdSMTP

Hi David
David Ayre says:
Quote

Hi,

I'm using the IdSMTP component to send emails, multipart, and it basically works fine. However, when I enter text into th body section of the IdMessage, I lose any linefeeds there might have been. This is my code:-

TIdText *Text = new TIdText(IdMessage1->MessageParts,NULL);
Text->ContentType = "text/plain";
Text->Body->Text = acBody;
Where acBody is char acBody[512];

I am using BDS2006 on an XP machine.

I have tried inserting \r\n etc., but to no avail.
I have also tried using the Text from a TMemo.
What am I doing wrong?
I don't know the answer to Your problem, but I just thought
that this might be because the \r\n is changed to \n when
it goes throug a unix/linux server så You might need to do a
replace on the recieved text:
Replace \n with \r\n
P.s. please break Your text lines.
Kind regards
Asger
 

Re:How to get line feeds in the body of IdSMTP

"David Ayre" < XXXX@XXXXX.COM >wrote in message
Quote
However, when I enter text into th body section of the IdMessage,
I lose any linefeeds there might have been.
TIdMessage and TIdSMTP do not strip line breaks out of the message whern
sending it.
Quote
Where acBody is char acBody[512];
Is it always null-terminated?
Gambit
 

Re:How to get line feeds in the body of IdSMTP

"Asger Joergensen" < XXXX@XXXXX.COM >wrote in message
Quote
I don't know the answer to Your problem, but I just thought
that this might be because the \r\n is changed to \n when
it goes throug a unix/linux server
That is not an issue here. For one thing, he's assigning his data to a
TStrings.Text property, which is going to parse the data and separate the
lines into the Strings[] property. When the message is actually sent, each
entry in the Strings[] property is re-appended with \r\n again, as per RFC
specs. At that point, the data in in the email system's hands, not Indy's.
Gambit
 

Re:How to get line feeds in the body of IdSMTP

"David Ayre" < XXXX@XXXXX.COM >wrote in message
Quote
strcpy(acBody,"Some words.\r\nSome more words\r\nEtc etc");
Why are you using a char[] array in the first place instead of an
AnsiString?
Quote
and the received email comes out like this:-

Some words.Some more wordsEtc etc
Please show a log of the actual SMTP transmission from a packet sniffer,
such as Ethereal/Wireshark.
Quote
strcpy(acBody,Memo1->Text.c_str()); and I get the same result.
That is a buffer overflow waiting to happen. At the very least, you should
be using strncpy() instead:
strncpy(acBody, Memo1->Text.c_str(), 511);
Gambit
 

Re:How to get line feeds in the body of IdSMTP

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

>strcpy(acBody,"Some words.\r\nSome more words\r\nEtc etc");

Why are you using a char[] array in the first place instead of an
AnsiString?
Because I am comfortable with char[]. I have used them for years.
Quote

>and the received email comes out like this:-
>
>Some words.Some more wordsEtc etc

Please show a log of the actual SMTP transmission from a packet sniffer,
such as Ethereal/Wireshark.
I've got Ethereal so I'll try it.

>strcpy(acBody,Memo1->Text.c_str()); and I get the same result.

That is a buffer overflow waiting to happen. At the very least, you should
be using strncpy() instead:

strncpy(acBody, Memo1->Text.c_str(), 511);

I know. I just used that as a quick example to try it out.
I normally use sprintf or strncpy. I was just being lazy in my
description of what I was doing.
Cheers,
David
 

Re:How to get line feeds in the body of IdSMTP

Quote
>Please show a log of the actual SMTP transmission from a packet sniffer,
>such as Ethereal/Wireshark.
I tried Ethereal but don't know how to interpret the results.
Quote

Cheers,

David
 

Re:How to get line feeds in the body of IdSMTP

"David Ayre" < XXXX@XXXXX.COM >wrote:
Quote


>>Please show a log of the actual SMTP transmission from a packet sniffer,
>>such as Ethereal/Wireshark.

This is an extract of the saved log file:-
To: XXXX@XXXXX.COM
Content-Type: multipart/mixed; boundary="=_MoreStuf_2zzz1234sadvnqw3nerasdf"
MIME-Version: 1.0
Date: Wed, 16 Jan 2008 10:10:02 +0000
This is a multi-part message in MIME format
--=_MoreStuf_2zzz1234sadvnqw3nerasdf
Content-Type: multipart/alternative;
boundary="=_MoreStuf_2altzzz1234sadvnqw3nerasdf"
--=_MoreStuf_2altzzz1234sadvnqw3nerasdf
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Attached is the list of produce for which we would like you to quote cur=
rent prices. The file can be opened in Excel and the prices, and quantit=
ies for the price, can be entered in the first two columns.
Using 'Save As', save the file as a csv file and email it back to us.
Best regards,
Company Name
Cheers,
David
 

Re:How to get line feeds in the body of IdSMTP

Quote
>
>>>Please show a log of the actual SMTP transmission from a packet sniffer,
>>>such as Ethereal/Wireshark.
>
On further investigation I find that if I set Outlook Express to
receive plain text only, it is OK. It is when it is set to
accept HTML that the problem occurs.
Here is the log extract for the HTML message:-
--=_MoreStuf_2altzzz1234sadvnqw3nerasdf
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<html>Attached is the list of produce for which we would like you to quo=
te current prices. The file can be opened in Excel and the prices, and q=
uantities for the price, can be entered in the first two columns.
Using 'Save As', save the file as a csv file and email it back to us.
Best regards,
Company Name</html>
Am I setting something wrong in the HTML section?
This is my code:-
TIdText *html = new TIdText(IdMessage1->MessageParts,NULL);
html->ContentType = "text/html";
char acHtml[512];
sprintf(acHtml,"<html>%s</html>",acBody);
html->Body->Text = acHtml;
Cheers,
David
 

Re:How to get line feeds in the body of IdSMTP

Asger Joergensen < XXXX@XXXXX.COM >wrote:
Quote


Maybe You need to replace \r\n with <br>to send in html

I tried replacing \r\n with <br>throughout the body string and
that worked fine.
Problem solved.
Thanks for the help.
Cheers,
David
 

Re:How to get line feeds in the body of IdSMTP

Hi David
David Ayre says:
Quote
On further investigation I find that if I set Outlook Express to
receive plain text only, it is OK. It is when it is set to
accept HTML that the problem occurs.
Maybe You need to replace \r\n with <br>to send in html
Just a thought..
Kind regards
Asger
 

Re:How to get line feeds in the body of IdSMTP

"David Ayre" < XXXX@XXXXX.COM >wrote in message
Quote
I tried Ethereal but don't know how to interpret the results.
Just post the log to the .attachments newgroup.
Gambit
 

Re:How to get line feeds in the body of IdSMTP

"David Ayre" < XXXX@XXXXX.COM >wrote in message
Quote
This is an extract of the saved log file:-
There are line breaks in that data.
Gambit