MailMerge object

NavRas
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);
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.

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);
0
Comments
-
Hi Navras,
Did you ever solve your problem? This is exactly what we need to do also.
Cheers..0 -
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 earlier0 -
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 activated0 -
vicky dada wrote:wdDoc := wdApp.Documents.Open(AttachmentPath);
in my nav there is no wdApp.Documents.Openit dont work
and
Automation 'Microsoft Word 14.0 Object Library'.Document
i find only 'Microsoft Outlook 14.0 Object Library'.DocumentItem0 -
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;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions