Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Example of using TppSMTPPlugIn from code to launch an email outside of a report.

edited May 2008 in General
Hi,

Hoping somebody could get me started in the correct direction, so as to be
able to use the SMTPPlugin, to create and send an email, without a ppReport
being on the form, ie using it standalone?
ie
uses
ppSMTPMapi, ppSMTPCustom;
....
procedure....
TppSMTPPlugIn.RegisterClass(TppSMTPMapi);
....
then .. add recipients
fromaddress
messagetext
attachments
....
set preview in mail client,
then send mail.

Note no ppReport on the form.

Please any help will be appreciated.

Regards

Adrian

Comments

  • edited May 2008
    Hi Adrian,

    The TppEmail object is designed to be used in two ways.

    1. A report can easily be sent via email using the TppReport.SendMail;
    routine. This routine will automatically create a TppEmail object, add
    itself to the reports list and send it using the Report.EmailSettings
    properties defined. (See the help topic for TppProducer.SendMail)

    2. A stand alone TppEmail object can be created and used to send one or
    many reports at the same time. This involves creating the object, adding
    the reports to the list using the AddReport() routine, then calling Send;.
    See the TppEmail topic in the RBuilder help.

    You will need to use the TppReport.EmailSettings property to define the
    details about the email in code. These properties are also documented in
    the RBuilder help file. See the TppEmailSettings topic.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2008
    Thanks.

    There is no more info at the help, than what you have allready given me.

    I tried:
    var
    ssEmail: TppEmail;
    begin
    ssEMail := tppEmail.Create;
    ppReport1.EmailSettings.ShowEmailDialog := False;
    ppReport1.EmailSettings.PreviewInEmailClient := True;

    ppReport1.EmailSettings.Body.Text := 'Testing 123';
    ppReport1.EmailSettings.Attachments.Append('D:\SS\Reports\CertificateRep20080221.pdf');
    ssEmail.AddReport(ppReport1);
    ssEmail.Send;
    end;

    This works, but if I add the line:
    ppReport1.EmailSettings.Attachments.Append('D:\SS\Reports\CertificateRep20080221.pdf');
    then no attachments appear at all.

    If I comment it out, then Report.Txt is added as an attachment. .. what am I
    doing wrong here?

    I don't want to send the ppReport1 as an attachment, but a previously
    created report stored on the drive as per the path above, that is why I
    asked if we could do away with the ppReport Component on the form. I don't
    mind it being there, I could just add some text to the Report to Identifiy
    the sender, and then there will be two attachments, ie one the
    Report.txt(created in ppReport1) and then two the CertificateReport Located
    on the hard drive .. ie previously generated.
    It is the second one I actually want to send. For that matter I would like
    to be able to attach any file under the sun, without hving the Report.txt in
    the attachments.

    Thanks for all you help so far

    Regards

    Adrian Wreyford

  • edited May 2008
    Placing the following code in a button onclick event worked successfully for
    me. Are you certain the file defined exists?

    procedure TForm1.Button1Click(Sender: TObject);
    var
    lEmail: TppEmail;
    begin

    lEmail := TppEmail.Create;

    try

    ppReport1.EmailSettings.Recipients.Add('support@digital-metaphors.com');
    ppReport1.EmailSettings.Subject := 'ReportBuilder email test';
    ppReport1.EmailSettings.Body.Add('ReportBuilder email test');
    ppReport1.EmailSettings.Attachments.Append('C:\Users\ncizik\Desktop\Test.txt');

    lEmail.AddReport(ppReport1);
    lEmail.Send;

    finally
    lEmail.Free;

    end;

    end;

    I'm sorry but the email feature is not designed to be used as a stand-alone
    emailer. There is no way to send an email with RB without generating and
    attaching at least one report. The purpose behind it is to generate a
    report or reports to file then attach and send it via email in a single
    step.

    If you would like to simply attach files to an email and send, you might
    consider using one of the Delphi email components such as Indy or Synapse.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2008
    Thanks .. I suspected as much, but was hopefull.
    Previously used MAPI from scalenum, but not working with Vista.
    I will just add a report, almost as a certificate to the intended email,
    with the actual attachment, until I get it sorted out.

    Thanks, and sorry for taking so much of your time!

    Adrian Wreyford
    PS .. the path was the problem!

This discussion has been closed.