🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Looking for relaible SMTP tool with authentication

#26
From: Mark Jacobs
Date: Tue, 05 Aug 2008 14:16
70 lines
3627 bytes
"John MacDonald" <jmac@itmeasures.com> wrote in message 
news:48751525$1@newsgroups.borland.com...
> 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.

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 <billg@microsoft.com>";
  mjsmtp->HdrFrom="Steve Jobs <stevej@apple.com>";
  mjsmtp->HdrTo="Bill Gates <billg@microsoft.com>";
  mjsmtp->HdrSubject="For Your Eyes Only!";
  mjsmtp->SignOn="Your SMTP User ID";
  mjsmtp->FromName="Steve Jobs <stevej@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 
Technical Details
Message-ID: <489860d6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <48751525$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,c54e90514d953d0
X-Google-Attributes: gid11508e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mark Jacobs" <markj@critical.co.uk>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <48751525$1@newsgroups.borland.com>
Subject: Re: Looking for relaible SMTP tool with authentication
Date: Tue, 5 Aug 2008 15:16:44 +0100
Lines: 72
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 81.144.157.8
Message-ID: <489860d6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1217945814 81.144.157.8 (5 Aug 2008 07:16:54 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 3478