🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Bare LFs in SMTP

#2735
From: Remy Lebeau (TeamB)
Date: Fri, 27 Jan 2006 19:02
143 lines
5626 bytes
"Mr. Wuf" <wuf@email.si> wrote in message
news:43da1e0d@newsgroups.borland.com...

> The "MaxLineLength" property of TIdSMTP is set to 0 (zero)
> and "MaxLineAction" to maException.

That is not what I was referring to.  Those properties only apply to reading
incoming strings, not sending outgoing strings.  The lines in your
TIdMessage's content are too long when they get encoded for transmission.
The problem only occurs when you use "quoted-printable" as the
TransferContent for your text (which Indy uses by default).  Since your code
has a setting for using "base64", you should not be getting the error when
that is enabled.

>     NText->Body = Memo2->Lines;

How many characters are on each line of your Memo text?

>   // There was a bug in an old Indy version. 1 message part caused
> an error.. so create a blank text-part

By doing that, your code is producing an invalid email layout.  You have 2
"text/plain" parts in your message.

>   int TextParts = 0;
>   for (int MP=0; MP < SMTPMessage->MessageParts->Count; MP++)
>   {
>     if(dynamic_cast<TIdText*>(SMTPMessage->MessageParts->Items[MP]));
>     TextParts++;
>   }

TIdMessage has a CountParts() method that does that for you, assigning the
TIdMessage's TextPartCount property.  Besides, your code has a semi-colon at
the end of the if() statement, so the variable will be incremented for all
parts regardless of their actual class type.  You should have gotten a "code
has no effect" warning from the compiler.

>     if (IdSMTP1->AuthenticationType == atLogin)
>       if (!IdSMTP1->Authenticate())

You do not need to call that manually.  Send() automatically calls
Authenticate().

With that said, use this code instead:

    SMTPMessage->Clear();
    SMTPMessage->From->Text = ComboBox3->Text;
    SMTPMessage->Priority = TIdMessagePriority(ComboBox5->ItemIndex);
    SMTPMessage->Recipients->EMailAddresses = Edit1->Text;
    SMTPMessage->Subject = SubjectEdit->Text;
    SMTPMessage->UseNowForDate = true;
    SMTPMessage->CharSet = ComboBox7->Text;
    SMTPMessage->Encoding = meMIME;

    IdSMTP1->Host = AccountFile->Lines->Strings[4];
    IdSMTP1->Port = StrToInt(AccountFile->Lines->Strings[5]);

    if( LMDRadioButton4->Checked )
    {
        IdSMTP1->AuthenticationType = atLogin;
        IdSMTP1->Username = AccountFile->Lines->Strings[6];
        IdSMTP1->Password = AccountFile->Lines->Strings[7];
    }
    else
        IdSMTP1->AuthenticationType = atNone;

    // create messageparts
    if( AttachmentForm->ListView1->Items->Count > 0 )
    {
        NText = new TIdText(SMTPMessage->MessageParts, NULL);
        NText->ContentType = "text/plain";

        // Encode text
        if( (ComboBox6->Text == "base64") && (LMDRadioButton1->Checked) )
        {
            NText->Body->Text = IdEncoderMIME1->Encode(Memo2->Text);
            NText->ContentTransfer = "base64";
        }
        else
        {
            NText->Body = Memo2->Lines;
            NText->ContentTransfer = "quoted-printable";
        }

        // no need for a second TIdText instance when attachments are
involved...

        // Create attachments
        for(int i = 0; i < AttachmentForm->ListView1->Items->Count; ++i)
        {
            att = new TIdAttachment(SMTPMessage->MessageParts,
AttachmentForm->ListView1->Items->Item[i]->Caption);
            att->ContentType = GetMimeTypeFromFile(att->FileName);
        }
    }
    else
    {
        SMTPMessage->ContentType = "text/plain";

        if( (ComboBox6->Text == "base64") && (LMDRadioButton1->Checked) )
        {
            SMTPMessage->Body->Text = IdEncoderMIME1->Encode(Memo2->Text);
            SMTPMessage->ContentTransfer = "base64";
        }
        else
        {
            SMTPMessage->Body = Memo2->Lines;
            SMTPMessage->ContentTransfer = "quoted-printable";
        }
    }

    try
    {
        if( LMDRadioButton7->Checked )
        {
            // .. for "SMTP after POP"
            IdPOP31->Connect();
            try {
                IdPOP31->CheckMessages();
            }
            __finally {
                IdPOP31->Disconnect();
            }
        }

        IdSMTP1->Connect();
        try
        {
            IdSMTP1->Send(SMTPMessage);
        }
        __finally {
            IdSMTP1->Disconnect();
        }
    }
    catch(const Exception &E)
    {
        Application->MessageBox(("Error:\n" + e.Message).c_str(),
"MailGate", MB_OK | MB_ICONHAND);
    }


Gambit
Technical Details
Message-ID: <43da6e72$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!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>

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>
Subject: Re: Bare LFs in SMTP
Date: Fri, 27 Jan 2006 11:02:52 -0800
Lines: 145
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: <43da6e72$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1138388594 68.69.17.41 (27 Jan 2006 11:03:14 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail