Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by Paw Suddergaard
Thu, 19 May 2005 10:04
Sending HTML mail with pictures using indy 9?
Author: Paw Suddergaard
Date: Thu, 19 May 2005 10:04
Date: Thu, 19 May 2005 10:04
39 lines
2275 bytes
2275 bytes
Hi all!
Im trying to send an HTML email, with pictures (not linked but within
the email - hope you know what i mean...)
I can send the email, and the attachments. But the html come out as code...
Can anyone help please?
Here's my code:
//Send email...
try{
TStringList *TempList = new TStringList();
TempLsit->LoadFromFile(Filename);
TIdText(IdMessage->MessageParts, TempList); //just the same...
TIdText(IdMessage->MessageParts, TempList); //html
IdMessage->From->Address = FromEmail;
IdMessage->From->Name = FromName;
IdMessage->ReplyTo->EMailAddresses = FromEmail;
IdMessage->Subject = eSubject->Text;
IdMessage->Recipients->EMailAddresses = ToEMail;
TempList = FindImagesInHTML(Filename);//custom function
for(int i=0;i<TempList->Count;i++){
TIdAttachment *IImagePart = new
TIdAttachment(IdMessage->MessageParts, TempList->Strings[i]);
IImagePart->ContentType = "image/jpg";
IImagePart->Headers->Add("Content-ID:"+TempList->Strings[i]);
}
IdSMTP->Host = frmToolL->Host;
IdSMTP->Username = frmToolL->UserId;
IdSMTP->Connect();
IdSMTP->Send(IdMessage);
if(IdSMTP->Connected())
IdSMTP->Disconnect();
}
catch(...){
//some error...
}
Re: Sending HTML mail with pictures using indy 9?
Author: Remy Lebeau (TeamB)
Date: Thu, 19 May 2005 10:39
Date: Thu, 19 May 2005 10:39
66 lines
3070 bytes
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
Re: Sending HTML mail with pictures using indy 9?
Author: Paw Suddergaard
Date: Thu, 19 May 2005 12:43
Date: Thu, 19 May 2005 12:43
42 lines
1889 bytes
1889 bytes
Hi again! Thankyou very much! That helped alot. But i still have some problems... My HTML Code gets messed up! Here' an example: Original: <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"> <META NAME="Generator" CONTENT="Internet Assistant for Word Version 3.0"> </HEAD> <BODY> When recieving the email: <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Dwindow= s-1252"> <META NAME=3D"Generator" CONTENT=3D"Internet Assistant for Word Version = 3.0"> </HEAD> <BODY> Where does the 3D come from and sometimes there are an = sign? Any idea? And last but not least... 2 questions: 1. Is it really nessecary to delete the templist? Doesn't the VCL do this for me? 2. catch(const Exception &) ?? Why can't i use catch(...)??? Thanks!!!!
Re: Sending HTML mail with pictures using indy 9?
Author: Remy Lebeau (TeamB)
Date: Thu, 19 May 2005 18:24
Date: Thu, 19 May 2005 18:24
41 lines
2783 bytes
2783 bytes
"Paw Suddergaard" <paw@easyflex.dk> wrote in message news:428c88d1$1@newsgroups.borland.com... > When recieving the email: <snip> > Where does the 3D come from and sometimes there are an = sign? The text is being encoded using the Quoted-Printable algorithm for transmission. That is perfectly normal. The 'Content-Transfer-Encoding' header for the text should be getting set to 'Quoted-Printable', which will tell the receiver that it needs to decode the text before displaying/saving it. > 1. Is it really nessecary to delete the templist? Yes, otherwise the memory is leaked. Unless your FindImagesInHTML() function is actually returning a TStringList that is owned elsewhere in code that you did not show which will free the TStringList later on. > Doesn't the VCL do this for me? No, it does not. > 2. catch(const Exception &) ?? Why can't i use catch(...)??? 99.9999% of the possible exceptions that can be thrown in the code you showed will be based on the Exception class. The only one that will not will be is if the 'new' operator fails, in which case a std::bad_alloc exception will be thrown instead. However, I'm not so sure about even that, since 'new' is allocating VCL objects, so Borland's VCL memory manager is being invoked instead of the C runtime memory manager instead, so the resulting exception will probably be VCL-based as well. Also, you did not specify which version of BCB you are actually using, but BCB6 changed how '...' handles VCL exceptions, so it is good practive to no longer use '...' to handle VCL exceptions. They should be caught explicitally. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads