🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2678

Re: Bare LFs in SMTP

#2678
From: Remy Lebeau (TeamB)
Date: Fri, 03 Feb 2006 23:56
181 lines
7606 bytes
"Mr. Wuf" <wuf@email.si> wrote in message
news:43e3ce90$1@newsgroups.borland.com...

> This this mirror: http://www.sendmefile.com/00264635

What you see happening is hard-coded behavior.  When there are attachments
present, Indy 9 *requires* there to be two TIdText parts present in order to
send your own text with the attachments.  But like i told you before, DO NOT
create two "text/plain" parts!  The email will be malformed if you do that.
If you want to include a single "text/plain" part with attachment, then you
need to put the text into the TIdMessage.Body instead of a TIdText.  Then
your text will be sent properly, although you will have no control over its
headers.

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");
    }


Gambit
Technical Details
Message-ID: <43e3ecf8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,c40bbd54da4c4431
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
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>
Subject: Re: Bare LFs in SMTP
Date: Fri, 3 Feb 2006 15:56:12 -0800
Lines: 183
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <43e3ecf8$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1139010808 68.69.17.41 (3 Feb 2006 15:53:28 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail