MailMerge object

NavRasNavRas Member Posts: 11
Hi there,

My client has a request to instead of emailing a merged word document at the end of the Interaction Wizard straight away they wish to open the mail in outlook, therefore they can have more control of the email before it is being sent, e.g. defer the mail and send it at a later day by setting up the delivery option, adding more recipients from outlook contacts etc.

The following is the standard code in the WordManagement codeunit where it embeds the merged word doc in the email body and send it right away, but the wrdDoc.MailMerge does not seem to have any method to stop the email being send straight away (I want something like OSendMail.OpenDialog := true)

wrdDoc.MailMerge.Destination := 2;
wrdDoc.MailMerge.MailAddressFieldName := Text015;
wrdDoc.MailMerge.MailSubject := TempDeliverySorter.Subject;
wrdDoc.MailMerge.MailAsAttachment :=
wrdDoc.MailMerge.MailAsAttachment OR TempDeliverySorter."Send Word Docs. as Attmt.";
wrdDoc.MailMerge.Execute;

I have tried to do the following (i.e. let the wrdDoc do the mail merge and save the merged file at a temp location, then use the Mail codeunit to send the email), however the word document no long embeded and becomes an attachment which is not quite what my client wants. :( Does anyone have any suggestions to meet my client's requirement? many thanks

wrdDoc.MailMerge.Destination := 0;
wrdDoc.MailMerge.MailAsAttachment := FALSE;
wrdDoc.MailMerge.Execute;

FileName := STRSUBSTNO(ENVIRON('TEMP') + Text50000,Attachment."File Extension");
IF ERASE(FileName) THEN;
wrdApp.ActiveDocument.SaveAs(FileName);
ParamBln := FALSE;
wrdApp.ActiveDocument.Close(ParamBln);

Mail.NewMessage(
AttachmentManagement.InteractionEMail(InteractLogEntry),'',
TempDeliverySorter.Subject,'',FileName,TRUE);

Comments

  • TimSimmondsTimSimmonds Member Posts: 47
    Hi Navras,

    Did you ever solve your problem? This is exactly what we need to do also.

    Cheers..
  • vicky_dadavicky_dada Member Posts: 106
    I have written this code for one of the function

    wrdDoc.MailMerge.Destination := 2;
    wrdDoc.MailMerge.MailAddressFieldName := Text015;
    wrdDoc.MailMerge.MailSubject := TempDeliverySorter.Subject;
    wrdDoc.MailMerge.MailAsAttachment :=
    wrdDoc.MailMerge.MailAsAttachment OR TempDeliverySorter."Send Word Docs. as Attmt.";
    wrdDoc.MailMerge.Execute;

    the mail merging is working fine, but I want to send an attachement in this mail. That is I have a report, I am saving as PDF and want to attach that report as PDF to the above mailmerge.execute.

    Please let me know if anyone has tried this earlier
  • vicky_dadavicky_dada Member Posts: 106
    I have re written this code for one of the function

    wrdDoc.MailMerge.Destination := 2;
    wrdDoc.MailMerge.MailAddressFieldName := Text015;
    wrdDoc.MailMerge.MailSubject := TempDeliverySorter.Subject;
    wrdDoc.MailMerge.MailAsAttachment :=
    wrdDoc.MailMerge.MailAsAttachment OR TempDeliverySorter."Send Word Docs. as Attmt.";
    //wrdDoc.MailMerge.Execute; - commented

    Name DataType Subtype Length
    objMail Automation 'Microsoft Outlook 14.0 Object Library'.MailItem
    wdDoc Automation 'Microsoft Word 14.0 Object Library'.Document
    wdApp Automation 'Microsoft Word 14.0 Object Library'.Application
    AttachmentPath Text 250
    filename Text 250



    AttachmentPath := wrdDoc.Path;
    filename := wrdDoc.Name;

    AttachmentPath := AttachmentPath+'\'+filename;

    wdDoc := wdApp.Documents.Open(AttachmentPath);


    objMail := wdDoc.MailEnvelope.Item;

    objMail.Display(FALSE);

    objMail.BodyFormat := 2;
    objMail.Subject := 'this is test subject';
    objMail."To" := mailid;
    objMail.Attachement.Add('C:\test.pdf');
    objMail.Send;

    The mail is sent, PDF is also sent as attachment, the mail body has the merge fields but they are not activated. that is the word merge fields are

    Hello <Customer.Name>, the expected mail to be sent as Hello Mr.Franics but the mail body is Hello <Customer.Name>

    the fields are not activated
  • SpycoclownSpycoclown Member Posts: 13
    vicky dada wrote:
    wdDoc := wdApp.Documents.Open(AttachmentPath);


    in my nav there is no wdApp.Documents.Open :( it dont work

    and

    Automation 'Microsoft Word 14.0 Object Library'.Document
    i find only 'Microsoft Outlook 14.0 Object Library'.DocumentItem
  • LekrayLekray Member Posts: 4
    Thanks for sample, i have a bit modify.

    I see you using it in codeunit 5054:


    TempDeliverySorter."Correspondence Type"::"E-Mail":
    BEGIN
    wrdDoc.MailMerge.Destination := 2;
    wrdDoc.MailMerge.MailAddressFieldName := Text015;
    wrdDoc.MailMerge.MailSubject := TempDeliverySorter.Subject;
    wrdDoc.MailMerge.MailAsAttachment :=
    wrdDoc.MailMerge.MailAsAttachment OR TempDeliverySorter."Send Word Docs. as Attmt.";
    // DD >>
    //wrdDoc.MailMerge.Execute;

    wrdDoc.MailMerge.Destination := 0;
    wrdDoc.MailMerge.Execute;

    wrdApp.Visible(FALSE);
    wrdApp := wrdDoc.MailMerge.Application;
    ParamBln := FALSE;
    wrdDoc.Close(ParamBln);
    wrdDoc := wrdApp.ActiveDocument;

    objMail := wrdDoc.MailEnvelope.Item;
    objMail.Display(FALSE);
    objMail.BodyFormat := 2;
    objMail.Subject := TempDeliverySorter.Subject;
    InteractLogEntry.GET(TempDeliverySorter."No.");
    objMail."To" := AttachmentManagement.InteractionEMail(InteractLogEntry);
    objMail.Attachments.Add('c:\temp\1.xlsx');
    objMail.Send;
    // DD <<
    END;
Sign In or Register to comment.