Home General

Sending email via Gmail using TppEmail

edited May 2018 in General
Hi,

I'm trying to send an email via Gmail using TppEmail directly and cannot get it to work. I receive a << raised exception class EIdHostRequired with message ". >> error when trying to send. I setup the Gmail email configuration and credentials the same way as I had done when sending email using TppReport.SendEmail. Do you have an example of sending email via Gmail using the TppEmail class directly that you could send me. Any assistance you can provide is greatly appreciated.
Thanks,
Scott

Comments

  • Hi Scott,

    The email feature consists of three main classes: TppEmail, TppEmailMessage, and TppSMTP... plugin(s).

    The Email class exports the report, creates a message, and sends the message using the desired plugin. It is possible to perform the above manually without TppEmail however its purpose is to perform everything automatically.

    For convenience every TppReport object has its own TppEmail class which is used to directly send.

    ---

    So when you make a call to Report.SendMail, you are essentially using the TppEmail object behind the scenes.

    If you are trying to create and use the TppEmail object as a stand-alone feature, you will need to be sure to manually add the report you want to send using the AddReport() routine. Otherwise the Email object has no information about your server etc. from the Email settings.

    Example:
    lEmail := TppEmail.Create;
    
    try
      lEmail.AddReport(ppReport1);
    
      lEmail.Send;
    
    finally
      lEmail.Free;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • I have added a report using the AddReport method. However, what I did do that might be causing the problem, is I set all the EmailSettings on the lEmail object directly (i.e. lEmail.EmailSettings) and not on ppReport1.EmailSettings. Just to confirm, the lEmail object is getting the EmailSettings from the report that is added via AddReports and they cannot be set directly on lEmail.EmailSettings.
    Thanks,
    Scott
  • Is there a way to use the TppEmail class to send email without adding a report? It appears that adding a report using the TppEmail.AddReport method is a requirement to send email. I was hoping to be able to use the TppEmail class to send emails without adding a report so that we could send PDF attachments (the PDFs where originally created by a report using PrintToFile method) to clients that request a copy of a previous invoice, letter, etc.
    Thanks,
    Scott
  • edited May 2018
    Hi Scott,

    The TppEmail class requires a report to send an email. If you would like to send and email without a report, you will need to manually create a TppEmailMessage object and TppSMTP class, assign the EmailMessage properties and TppSMTP properties, then call TppSMTP.SendMail.
    var
      lEmailMessage: TppEmailMessage;
      lSMTP: TppSMTPIndy;
    begin
    
      lEmailMessage := TppEmailMessage.Create;
      lSMTP := TppSMTPIndy.Create;
    
      try
        //Define TppEmailMessage properties here (Subject, Body, Attachments, etc...)
    
        //Define TppSMTPIndy properties here (Host Address, User Name, Password, etc...)
    
        lSMTP.SendMail(lEmailMessage);  //Send the message
    
      finally
        lSMTP.Free;
        lEmailMessage.Free;
      end;
    
    end;
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • That's awesome. Thanks so much.
    Thanks,
    Scott
Sign In or Register to comment.