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

Email-groups - adding attachments

edited September 2011 in General
Hi

Is it possible to add individual attachments to automatic emails upon
group-break ?
I figure there might be some hook / event where I can add attachments to the
email before sending.
I am Using Rb12.02 and Indy10.

Ren? / SSV

Comments

  • edited September 2011
    Hi Rene,

    You can use the Group.OnGetEmailSettings event to access the
    TppEmailSettings object used to send each group file. The
    TppEmailSettings object has an attachments property that can be added to.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2011

    Hi Nico
    Thanks alot. I figured it might be that simple, I just couldn't find the
    right place to look for it.

    Regards
    René
    Den 20-09-2011 16:15, Nico Cizik (Digital Metaphors) skrev:
  • edited November 2012
    Hi
    I implemented this feature one year ago (adding extra attachments, see
    email below) and it has been working fine until recently.

    Suddenly the extra attachments is not delivered. I have been debugging
    and I can solve the problem this way:


    procedure TMyForm.ppGroup1GetEmailSettings(Sender, aEmailSettings: TObject);
    begin
    inherited;

    // By changing this line:
    // TppEmailSettings(aEmailSettings).attachments.add(MyFile);

    // to this
    TppEmailSettings(ppMyReport.EmailSettings).attachments.add(MyFile);
    // it is working again.

    end;

    The parameter object aEmailsettings is Empty - not nil but points to an
    empty object ().


    I tried setting a breakpoint in the event and inspected the call stack -
    and what I find is this very strange :

    (ppBands)
    procedure TppGroupHeaderBand.ProcessEmailFile(aBreakValue: string);
    var
    lParams: TraParamList;
    lEmailSettings: TppEmailSettings;
    begin

    lEmailSettings := TppEmailSettings.Create;

    try
    lEmailSettings.Assign(Report.EmailSettings);

    if Group.GroupFileSettings.EmailField <> '' then

    lEmailSettings.Recipients.Add(Report.DataPipeline[Group.GroupFileSettings.EmailField]);

    lEmailSettings.Subject := lEmailSettings.Subject + ' ' + aBreakValue;

    // The lEmailsettings object here is well defined and contains whaT I
    // expect. But when my event (above) is triggered the event recceives //
    an empty object.
    // HOW IS THAT POSSIBLE ??????

    //Fire OnGetEmailAddress Event
    if Assigned(Group.OnGetEmailSettings) then
    Group.OnGetEmailSettings(Group, lEmailSettings);


    lParams := TraTppGroupRTTI.GetParams('OnGetEmailSettings');
    lParams.CreateValuePointer(0, lEmailSettings);
    Group.SendEventNotify(Self, ciGroupGetEmailSettings, lParams);
    lParams.Free;

    Report.Engine.Page.EmailSettings := lEmailSettings;
    Report.Engine.Page.EmailFile := True;

    finally
    lEmailSettings.Free;
    end;

    end; {function, ProcessEmailFile}

    I am using Delphi 2010 - Rb12.02 and Indy10 and I have not been updating
    any Delphi, ReportBuilder (or Indy) components since implementing the
    feature.

    Regards René


    Den 21-09-2011 10:08, René Laursen - SSV skrev:
  • edited November 2012
    Hi Rene,

    We have not seen this behavior before. If you are using the same
    version of Delphi, RB, and Indy, there must be another item that was
    changed that is causing this behavior. At some point did you alter the
    report itself? Have the groups been changed at any time (renamed, new
    groups added, reordered)? Are there multiple groups in your report?

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2012
    Hi Nico

    No changes that I am aware of. I don't think reports have changed in any
    way. This happens in 2 different applications using same technique but
    not sharing some reports or reporting code.
    And this happens in applications compiled on 2 different PC's (with same
    Delphi and RB installed).

    Also - and this may be interesting -
    My hack - accessing TppEmailSettings(ppMyReport.EmailSettings) does not
    work either. When the printjob generates 2 or more reports (due to
    group-breaks) EACH mail contains ALL attachments !!!

    When I tested this I actually expected that this would not work
    correctly, I expected the 1. mail to contain the 1. extra attachment,
    the 2. to contain the 1. and 2. attachment and so on (as I am repeatedly
    adding to the reports emailsettings.attachment).

    It seems that the mails somehow are hold back and are not sent until the
    job finishes and then uses the current contents of
    TppEmailSettings(ppMyReport.EmailSettings).

    How can this be ?
    Can you think of any property that I may have changed by accident?

    Regards
    René / SSV



    Den 05-11-2012 15:40, Nico Cizik (Digital Metaphors) skrev:
  • edited November 2012
    Hi again Nico.

    I don't know if I can ask you to look further into this.
    It is driving me crazy.

    2 years ago I developed pdf/mail in our pay-check-application.
    The application is old and is still using paradox/BDE.
    Back then I had some (other) problems and I made a little
    example-project using some of the tables from the application (so field-
    and tablenames etc are in danish).

    In this example-project I have now added attachments to the emails - the
    same way I have been using in our real applications.
    The extra attachments are not delivered. The parameter aMailsettings for
    OnGetEmailSettings has lost its content !?


    I have uploaded a zip-file to www.ssv.dk\test\rbmailexample.zip - unzip
    this file to your c:\ - this will create a directory c:\rbmailexample
    with sourcecode and paradox-tables.

    I am very curios to hear how this works. It HAS been working 6 months
    ago - and I just don't know what is going on now.

    Best regards
    René / SSV
  • edited November 2012
    Hi Rene,

    I will take a look at your example. In the mean time, try running the
    Group-Email example we have and see if you get the same behavior. If
    not, we will know that something in your specific app is causing this issue.

    http://www.digital-metaphors.com/rbWiki/Output/Email/How_To...Email_Groups

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.