Home Devices
New Blog Post: Email: Multi-Service

Sending an Email with a PDF attachment

edited January 2012 in Devices
Using Delphi XE, Indy 10, and RB 12.05, I'm attempting to send an email
using the following code. I don't receive an error (like I do when I have
an unknown host name), but I also don't receive an email. This SMTP server
doesn't currently have a problem with a different program of ours that's
using a TIdSMTP component, so the login information is good, and it accepts
and sends attachments. Some of the host and port setting is certainly
excessive, but I wanted to make sure I wasn't leaving one of them out that
may cause it to silently fail. SSL is not required for this server.

procedure TfrmRPSelector.EmailReport(reportName: string);
ioHandler: TIdIOHandlerStack;
lEmail: TppEmail;
if not FileExists(reportName) then
ppReport1.Template.FileName := reportName;
ppReport1.AllowPrintToFile := true;
TppEmail(ppReport1.Email).SMTP.OnEmailError := EmailErrorEvent;
ppReport1.ArchiveFileName := 'Test.pdf';
ppReport1.EmailSettings.Enabled := true;
ppReport1.EmailSettings.HostAddress := 'smtp.east.cox.net';
ppReport1.EmailSettings.UserName := myUserName;
ppReport1.EmailSettings.Password := myPassword;
ppReport1.EmailSettings.ShowEmailDialog := false;
ppReport1.EmailSettings.PreviewInEmailClient := false;
ppReport1.EmailSettings.Subject := 'Test Report';
ppReport1.EmailSettings.Recipients.Text := sSendTo;
ppReport1.EmailSettings.FileName := 'Test.pdf';
ppReport1.EmailSettings.Body.Text := 'See attached.';
ppReport1.EmailSettings.ReplyTo := sSendFrom;
ppReport1.EmailSettings.FromAddress := sSendFrom;
ppReport1.EmailSettings.FromName := 'Steve';

lEmail := TppEmail(ppReport1.Email);
TppSMTPIndy(lEmail.SMTP).IndySMTP.Port := 25;
TppSMTPIndy(lEmail.SMTP).IndySMTP.Host := 'smtp.east.cox.net';
ioHandler := TIdIOHandlerStack.Create(self);
ioHandler.Destination := 'smtp.east.cox.net:25';
ioHandler.Port := 25;
ioHandler.Host := 'smtp.east.cox.net';
TppSMTPIndy(lEmail.SMTP).IndySMTP.IOHandler := ioHandler;


  • edited January 2012
    Hi Steve,

    Some servers do not function well with the Authenticate command that
    Indy sends. Try setting the AuthenticateConnection property of the
    TppSMTPIndy object to False and see if that helps.

    TppSMTPIndy(lEmail.SMTP).AuthenticateConnection := False;

    If this does not help, as a test, try removing all code after setting
    the FromName property of the EmailSettings except for the SendMail call.
    There should be no need to create an iohandler if you are not trying
    to connect to a secured server and by default the port number is 25.

    Best Regards,

    Nico Cizik
    Digital Metaphors
  • edited January 2012
    That one command was it. Thank you!

This discussion has been closed.