🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Sending HTML mail with pictures using indy 9?

#3911
From: Remy Lebeau (TeamB)
Date: Thu, 19 May 2005 10:39
66 lines
3070 bytes
"Paw Suddergaard" <paw@easyflex.dk> wrote in message
news:428c63af@newsgroups.borland.com...

> I can send the email, and the attachments. But the html come out as
code...

That is because you are not setting up the message properly at all.

>     TIdText(IdMessage->MessageParts, TempList); //just the same...
>     TIdText(IdMessage->MessageParts, TempList); //html

That shouldn't even compile.  You need to call TIdText's constructor via the
'new' operator.

Also, you never set up the ContentType for the TIdText instances at all.

Also, you have memory leaks in your use of temporary TStringList that you
never free properly.

Use this code instead:

    try
    {
        IdMessage->From->Address = FromEmail;
        IdMessage->From->Name = FromName;
        IdMessage->ReplyTo->EMailAddresses = FromEmail;
        IdMessage->Subject = eSubject->Text;
        IdMessage->Recipients->EMailAddresses = ToEMail;
        TIdText *TempText = new TIdText(IdMessage->MessageParts, NULL);
        TempText->ContentType = "text/plain";
        // fill in TempText->Body with plain text...
        TempText = new TIdText(IdMessage->MessageParts, NULL);
        TempText->ContentType = "text/html";
        // fill in TempText->Body with html...
        TStringList *TempList = FindImagesInHTML(Filename);
        try
        {
            for(int i = 0; i < TempList->Count; ++i)
            {
                TIdAttachment *IImagePart = new
TIdAttachment(IdMessage->MessageParts, TempList->Strings[i]);
                IImagePart->ContentType = "image/jpg";
                IImagePart->ContentID =
ExtractFileName(TempList->Strings[i]);
            }
        }
        __finally {
            delete TempList;
        }
        IdSMTP->Host = frmToolL->Host;
        IdSMTP->Username = frmToolL->UserId;
        IdSMTP->Connect();
        try {
            IdSMTP->Send(IdMessage);
        }
        __finally {
            IdSMTP->Disconnect();
        }
    }
    catch(const Exception &) {
        //...
    }


Gambit
Technical Details
Message-ID: <428c6c9b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <428c63af@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,31e2e9ad50e48b5c
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: <428c63af@newsgroups.borland.com>
Subject: Re: Sending HTML mail with pictures using indy 9?
Date: Thu, 19 May 2005 03:39:27 -0700
Lines: 68
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: <428c6c9b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1116499099 68.69.17.41 (19 May 2005 03:38:19 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail