Email with Mail Merge functionality

snehalppatelsnehalppatel Member Posts: 34
Hello All,

I know of mail merge using Word document to send it as an attachment to multiple recipients, using interaction Template in NAV. But, my client wants to use either SMTP or Outlook to send an email to multiple recipients. He wants to add multiple Contacts from NAV Contacts and send them an email with fields like mail merge, that might contain the recipient's name, address etc. The condition is the mail should be a plain or HTML mail, and it should not go as attachment like Word document mail merge, instead it should go as a simple email. Is there any provision in NAV to do something similar, or is anyone known to a component which can provide this functionality and is compatible with NAV.

Various solutions or work arounds are welcome.

Thanks in advance,
Snehal Kumar Patel
MCTS - Microsoft Dynamics NAV

Comments

  • matttraxmatttrax Member Posts: 2,309
    Never done this exact thing before, but here's an idea.
      Do the standard mail merge with a word document Save the resulting file as an HTML file instead of a word document Open the HTML file and use the text as the body of the email using the Mail codeunit.

    That could work..not sure about the effort level or if something better / easier exists.
  • rsaritzkyrsaritzky Member Posts: 469
    There are a number of SMTP solutions that can easily be integrated into Navision. I haven't used Jmail, but it's listed in the downloads section here on MIBUSO:

    http://www.mibuso.com/dlinfo.asp?FileID=1156

    I've used ANSMTP, which is a commercial product, very good support, moderately priced, available at http://www.emailarchitect.net.

    The technique I've used for mailmerge is to create a table with a column for boilerplate text of your email, plus some columns that contain the names of substitution fields. Then, the message can be "merged" with the STRSUBSTNO command before it is output to the SMTP function.

    The way I've done it is to use the FIELD table and a FieldRef type variable to reference the values in a record.
    Here is a VERY crude example. It assumes you have a message template table with the following fields:
    SubstFieldName1
    SubstFieldName2
    SubstFieldName3
    BodyTemplate

    The first three fields contain the fieldnames that you want to insert into the BodyTemplate message. So in the code below, we're inserting Vendor fields (record variable VendRec): VendRec.Name, VendRec.Address and VendRec."Address 2":

    BodyTemplate := 'This is the body of the message with the Vendor name here %1 then address %2 then address 2 %3';
    SubstFieldName1 := 'Name';
    SubstFieldName2 := 'Address';
    SubstFieldName3 := 'Address 2';
    VendRec.FINDFIRST;
    RecRef.GETTABLE(VendRec);
    Fld.SETRANGE(TableNo, DATABASE::Vendor);
    Fld.SETRANGE(FieldName, SubstFieldName1);
    Fld.FINDFIRST;
    FldRef[1] := RecRef.FIELD(Fld."No.");
    Fld.SETRANGE(FieldName, SubstFieldName2);
    Fld.FINDFIRST;
    FldRef[2] := RecRef.FIELD(Fld."No.");
    Fld.SETRANGE(FieldName, SubstFieldName3);
    Fld.FINDFIRST;
    FldRef[3] := RecRef.FIELD(Fld."No.");

    MessageBody := STRSUBSTNO(SubText,FORMAT(FldRef[1].VALUE), FORMAT(FldRef[2].VALUE), FORMAT(FldRef[3].VALUE) );

    Assuming the Vendor's name and address are:
    Global Manufacturing
    123 Anywhere Street
    Suite A

    After the code above, the variable "MessageBody" will look like:

    This is the body of the message with the Vendor name here Global Manufacturing then address 123 Anywhere Street then address 2 Suite A

    I know the code is crude but it illustrates the use of STRSUBSTNO and use of FieldRef's to get values of fields into a string.

    If you have only one email message you don't have to use a table - you can just create the text in-line with your code. But I favor building the table so that when (not if) a second email has to be composed, you have the structure for it all done.

    Hope this helps.
    Ron
  • snehalppatelsnehalppatel Member Posts: 34
    Thanks to mattrax & rsaritzky both. I will try implementing your solutions, and will get back soon.

    Thanks once again.
    Snehal Kumar Patel
    MCTS - Microsoft Dynamics NAV
  • piercapierca Member Posts: 10
    Hi all guys, have a question for you:
    I use a customized mailmerge to send email to customer. There's a way to change the sender mail adress?
    Thank you in advice and excuse my english.
    Piercarlo
  • rsaritzkyrsaritzky Member Posts: 469
    pierca wrote:
    Hi all guys, have a question for you:
    I use a customized mailmerge to send email to customer. There's a way to change the sender mail adress?
    Thank you in advice and excuse my english.
    Piercarlo

    You should be able to change the sender email address. It depends how your customized mailmerge is built. But the code that specifies the email address would be able to be changed, depending on how you wanted it to work. If you can provide more details how it works, then maybe we can help you.
    Ron
  • davmac1davmac1 Member Posts: 1,283
    Codeunit 400 lets you change it.
    If you use the older codeunit 397, you cannot do it thru code.
Sign In or Register to comment.