Article View: borland.public.cppbuilder.internet.socket
Article #2692Re: Bare LFs in SMTP
From: Mark Jacobs
Date: Thu, 09 Feb 2006 11:20
Date: Thu, 09 Feb 2006 11:20
171 lines
7721 bytes
7721 bytes
Remy Lebeau (TeamB) wrote:
> For the moment, use the following code:
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> SMTPMessage->Clear();
>
> bool UsePlainText = (Memo1->GetTextLen() > 0);
> bool UseHTML = (Memo2->GetTextLen() > 0);
> int AttachmentCount = ListBox1->Items->Count;
>
> if( AttachmentCount ) // no attachments
> {
> if( UsePlainText && !UseHTML )
> {
> SMTPMessage->Body->Text = Memo1->Text;
> SMTPMessage->ContentType = "text/plain";
> SMTPMessage->ContentTransferEncoding = "quoted-printable";
> }
> else if( !UsePlainText && UseHTML )
> {
> SMTPMessage->Body->Text = Memo2->Text;
> SMTPMessage->ContentType = "text/html";
> SMTPMessage->ContentTransferEncoding = "quoted-printable";
> }
> else
> {
> if( UsePlainText )
> {
> TIdText *NText = new TIdText(SMTPMessage->MessageParts,
> Memo1->Lines);
> NText->ContentType = "text/plain";
> NText->ContentTransfer = "quoted-printable";
> }
>
> if( UseHTML )
> {
> TIdText *HText = new TIdText(SMTPMessage->MessageParts,
> Memo2->Lines);
> HText->ContentType = "text/html";
> HText->ContentTransfer = "quoted-printable";
> }
> }
> }
> else
> {
> if( UsePlainText && !UseHTML )
> {
> // In order to provide a single text part with attachments,
> you have to use the
> // TIdMessage.Body property here. Do note, however, that
> you do not have
> // any control over the headers for the text part in this
> scenerio!
>
> SMTPMessage->Body = Memo1->Lines;
> }
> else if( !UsePlainText && UseHTML )
> {
> // Cannot use the TIdMessage.Body property in this scenerio
> due to the
> // lack of control over the headers for that text part, so
> use a dummy
> // plain-text part so that the html can be put into its own
> text part.
>
> TIdText *NText = new TIdText(SMTPMessage->MessageParts,
> NULL);
> NText->ContentType = "text/plain";
>
> TIdText *HText = new TIdText(SMTPMessage->MessageParts,
> Memo2->Lines);
> HText->ContentType = "text/html";
> HText->ContentTransfer = "quoted-printable";
> }
> else
> {
> if( UsePlainText )
> {
> TIdText *NText = new TIdText(SMTPMessage->MessageParts,
> Memo1->Lines);
> NText->ContentType = "text/plain";
> NText->ContentTransfer = "quoted-printable";
> }
>
> if( UseHTML )
> {
> TIdText *HText = new TIdText(SMTPMessage->MessageParts,
> Memo2->Lines);
> HText->ContentType = "text/html";
> HText->ContentTransfer = "quoted-printable";
> }
> }
>
> // Attachments erstellen
> for(int i = 0; i < AttachmentCount; ++i)
> {
> TIdAttachment *att = new
> TIdAttachment(SMTPMessage->MessageParts, ListBox1->Items->Strings[i]);
> att->ContentType = GetMIMETypeFromFile(att->FileName);
> }
> }
>
> SMTPMessage->SaveToFile("c:\\test.eml");
> }
>
>
> In the meantime, I have made a small update TIdMessageClient to allow a
> single TIdText to be used with attachments, with full header control. You
> can download the newest snapshot within the next couple of days. Then the
> above code can be simplified to the following:
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> TIdText *TextPart;
> TIdAttachment *Att;
> int AttachmentCount = ListBox1->Items->Count;
>
> SMTPMessage->Clear();
>
> if( Memo1->GetTextLen() > 0 )
> {
> if( (AttachmentCount == 0) && (!UseHTML) )
> {
> SMTPMessage->Body->Text = Memo1->Text;
> SMTPMessage->ContentType = "text/plain";
> SMTPMessage->ContentTransferEncoding = "quoted-printable";
> }
> else
> {
> TextPart = new TIdText(SMTPMessage->MessageParts,
> Memo1->Lines);
> TextPart->ContentType = "text/plain";
> TextPart->ContentTransfer = "quoted-printable";
> }
> }
>
> if( Memo2->GetTextLen() > 0 )
> {
> if( (AttachmentCount == 0) && (!UsePlainText) )
> {
> SMTPMessage->Body->Text = Memo2->Text;
> SMTPMessage->ContentType = "text/html";
> SMTPMessage->ContentTransferEncoding = "quoted-printable";
> }
> else
> {
> TextPart = new TIdText(SMTPMessage->MessageParts,
> Memo2->Lines);
> TextPart->ContentType = "text/html";
> TextPart->ContentTransfer = "quoted-printable";
> }
> }
>
> // Attachments erstellen
> for(int i = 0; i < AttachmentCount; ++i)
> {
> Att = new TIdAttachment(SMTPMessage->MessageParts,
> ListBox1->Items->Strings[i]);
> Att->ContentType = GetMIMETypeFromFile(att->FileName);
> }
>
> SMTPMessage->SaveToFile("c:\\test.eml");
> }
Remy, even the simplified code is overly complicated. An email component is supposed to
hold your hand, not bite it off! This is why I steer clear of Indy, and program at
ClientSocket level - my code is much cleaner.
--
Mark Jacobs
http://www.dkcomputing.co.uk
Technical Details
Message-ID:
<43eb24a7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43d80b2b$1@newsgroups.borland.com> <43d81c0d$1@newsgroups.borland.com> <43d8ce05@newsgroups.borland.com> <43d912e0$1@newsgroups.borland.com> <43d96959@newsgroups.borland.com> <43d97297@newsgroups.borland.com> <43da1e0d@newsgroups.borland.com> <43da6e72$1@newsgroups.borland.com> <43dccb8e@newsgroups.borland.com> <43ddbb09$1@newsgroups.borland.com> <43e24225$1@newsgroups.borland.com> <43e3a59d$1@newsgroups.borland.com> <43e3ce90$1@newsgroups.borland.com> <43e3ecf8$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,c40bbd54da4c4431 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 09 Feb 2006 11:20:52 +0000 From: Mark Jacobs <markj@critical.co.uk> User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Bare LFs in SMTP References: <43d80b2b$1@newsgroups.borland.com> <43d81c0d$1@newsgroups.borland.com> <43d8ce05@newsgroups.borland.com> <43d912e0$1@newsgroups.borland.com> <43d96959@newsgroups.borland.com> <43d97297@newsgroups.borland.com> <43da1e0d@newsgroups.borland.com> <43da6e72$1@newsgroups.borland.com> <43dccb8e@newsgroups.borland.com> <43ddbb09$1@newsgroups.borland.com> <43e24225$1@newsgroups.borland.com> <43e3a59d$1@newsgroups.borland.com> <43e3ce90$1@newsgroups.borland.com> <43e3ecf8$1@newsgroups.borland.com> In-Reply-To: <43e3ecf8$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 81.144.157.8 Message-ID: <43eb24a7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1139483815 81.144.157.8 (9 Feb 2006 03:16:55 -0700) Lines: 171 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail