How To…Show Email Errors

Question

“My emails won’t send.  Is there a way to see the error returned by my email server/MAPI client?”

Solution

By default all email errors are caught and suppressed.  Use the TppSMTPCustom.OnEmailError event to capture the error text returned by your email server or MAPI compatible email client.  This event can be accessed from the TppReport object by typecasting the TppReport.Email object as TppEmail.

Download: ShowEmailErrors.zip

Sample Delphi code:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TppEmail(ppReport1.Email).SMTP.OnEmailError := EmailErrorEvent;


  //Assign bad email address as recipients to ensure an error code is returned.
  ppReport1.EmailSettings.Recipients.Add('BadEmailAddressDotCom');
  ppReport1.EmailSettings.Recipients.Add('WorseEmailAddressDotCom');

  ppReport1.SendMail;
end;

procedure TForm1.EmailErrorEvent(Sender: TObject; aErrorText: String);
begin
  ShowMessage(aErrorText);

end;