I am looking to update one of my applications. I need a SMTP component that
will use authentication.
Someone wrote Indy, Synapse, ICS ??? Has anyone had experience with these
products working with C++ Builder 5 Enterprise.
Thanks in advance
JMAC out
I have successfully implemented SMTP in my apps using the ICS by Francois Piette (a very
fine programmer indeed!). It is available at http://www.overbyte.be/frame_index.html
(click on the ICS link on the left-hand side menu).
Since I also use C++ Builder 5, here is some sample code for you (mjsmtp is the ICS SMTP
component I dropped on the form, you are Steve Jobs, and you are sending an email to Bill
Gates) :-
Usage :-
mysendit("The body of the message which could contain HTML if you like.");
Implementation :-
AnsiString mysendit(AnsiString yurmess)
{
int ii,ctr=20,dly=500;
// ctr is max number of retries, dly is delay in msec between each try
if (!mjsmtp) return er+"No EMail Component";
mjsmtp->RcptName->Text="Bill Gates <bi...@microsoft.com>";
mjsmtp->HdrFrom="Steve Jobs <ste...@apple.com>";
mjsmtp->HdrTo="Bill Gates <bi...@microsoft.com>";
mjsmtp->HdrSubject="For Your Eyes Only!";
mjsmtp->SignOn="Your SMTP User ID";
mjsmtp->FromName="Steve Jobs <ste...@apple.com>";
mjsmtp->EmailFiles->Text="Attach1.doc;Attach2.xls";
mjsmtp->Host="Your SMTP Host";
mjsmtp->PlainText->Text=""; mjsmtp->HtmlText->Text="";
if (yurmess.LowerCase().Pos("<html")>0)
{
mjsmtp->ContentType=smtpHtml; mjsmtp->HtmlText->Text=yurmess;
}
else
{
mjsmtp->ContentType=smtpPlainText; mjsmtp->PlainText->Text=yurmess;
}
mjsmtp->Open(); ii=0;
while (mjsmtp->State!=smtpReady && mjsmtp->State!=smtpAbort && ii<ctr)
{
Sleep(500); ++ii;
}
if (mjsmtp->State==smtpAbort || ii>=ctr) return "Open Aborted";
mjsmtp->Mail(); ii=0;
while (mjsmtp->State!=smtpReady && mjsmtp->State!=smtpAbort && ii<ctr)
{
Sleep(500); ++ii;
}
if (mjsmtp->State==smtpAbort || ii>=ctr) return "EMail Aborted";
return "EMail Sent OK "+Now().DateTimeString()+" "+mjsmtp->LastResponse;
}
As you can see, this is very much a synchronous operation, so you may want to put it into
a separate thread. Anyway, good luck - I hope that gets you going. As for validation,
you'll have to dig through the properties and methods in the ics\Delphi\Vc32\SmtpProt.pas
file. Here is what I found :-
procedure TCustomSmtpClient.Auth;
at row 1448 in the .pas file.
--
Mark Jacobs
http://www.dkcomputing.co.uk