Adding signature to Outlook-mail created through codeunit 397 - nav 2015

jensthomsenjensthomsen Member Posts: 173
Hi
I have created a beautiful email with HTML formatting by use of codeunit 397 - the user should be able to read/modify the email before sending. My problem is that the signature is missing...From my point of view, it should be a simple task to call some kind of .Net add-in that would choose the standard signature (the user can have more than one) and add it to the end of the mail (that is: do the same thing as Outlook does when creating a new email manually). 'Microsoft.Office.Interop.Outlook' assembly has a lot of 'type's but I'm sure which one might do the job (or one of them at all?). I have googled for a solution but without any luck :'(

Answers

  • sradloff@comsol.agsradloff@comsol.ag Member Posts: 6
    Hi,

    this is not that easy to achieve.
    The question was asked in c# forums as well and got some Solutions:

    stackoverflow.com/questions/6442747/add-the-default-outlook-signature-in-the-email-generated

    I used the second solution of this question where they append the Body after displaying the mail:
    //snip ---
    mailItem.Display(mailItem);
    mailItem.HTMLBody = body + mailItem.HTMLBody;
    //snip ---
    
  • jensthomsenjensthomsen Member Posts: 173
    No, not really :'( Where to put the 'Display' and 'HTMLBody' calls? I'm using codeunit 397 from "outside": just calling the 2 functions 'AddBodyline' and 'NewMessage' from another codeunit...But I guess I have to do som modification to codeunit 397??
  • mdPartnerNLmdPartnerNL Member Posts: 802
    Can you show a snippet of your code? how you add html..

    I have tried it but the body never contains html statements, only the text..
  • sradloff@comsol.agsradloff@comsol.ag Member Posts: 6
    The problem is, that microsoft has built a wrapper/helper class around the functionality.
    Therefor you'll not be able to get the signature easily by setting a parameter in codeunit 397.

    I think you'll have to create an own functionality that's using default .net Outlook functions or build you own class.

    I've successfully tested it with:
    lOutlookApp := lOutlookApp.ApplicationClass;
    lMailItem := lOutlookApp.CreateItem(lOutlookItemType.olMailItem);        
    lMailItem."To" := 'test@comsol.ag';          
    lMailItem.CC := '';
    lMailItem.Subject := 'Subject';
    lMailItem.Display(lMailItem);
    lMailItem.HTMLBody := 'Your Body' + lMailItem.HTMLBody;
    

    Use the following DotNet Variables:

    lOutlookApp DotNet Microsoft.Office.Interop.Outlook.ApplicationClass.'Microsoft.Office.Interop.Outlook,
    lOutlookItemType DotNet Microsoft.Office.Interop.Outlook.OlItemType.'Microsoft.Office.Interop.Outlook,
    lMailItem DotNet Microsoft.Office.Interop.Outlook.MailItem.'Microsoft.Office.Interop.Outlook
  • jensthomsenjensthomsen Member Posts: 173
    Hi Bastir81
    IT WORKS!!!!!! Just remember to put 'RunOnClient' = YES on the 3 DotNet variables. My samplecode looks like this (I don't know how to insert a screen-shot):

    lOutlookApp := lOutlookApp.ApplicationClass;

    lMailItem := lOutlookApp.CreateItem(lOutlookItemType.olMailItem);
    lMailItem."To" := 'some@e-mail.com';
    lMailItem.CC := '';
    lMailItem.Subject := 'Subject';
    lMailItem.Display(lMailItem);
    lMailItem.HTMLBody := '<b>Bold line</b>' +
    '<TABLE border="1">' +
    '<TR><TH>Column 1 1<TH>Column 2' +
    '<TR><TH>Value 1<TH>Value 2' +
    '<TR><TH align="right">' + FORMAT(123456789,258) + '<TH>' + 'My name is jens' +
    '</TABLE>'
    + lMailItem.HTMLBody
    ;

    Though it would be nice with the possibility of adding the (HTML) body line-by-line like the 'AddBodyLine' in codeunit 397??

  • mdPartnerNLmdPartnerNL Member Posts: 802
    Can you show a snippet of your code? how you add html..

    I have tried it but the body never contains html statements, only the text..

    @jensthomsen, bump :)
  • jensthomsenjensthomsen Member Posts: 173
    edited 2016-01-26
    Can you show a snippet of your code? how you add html..

    I have tried it but the body never contains html statements, only the text..

    Just adding som HTML code in the 'AddBodyLine' function of codeunit 397 works for me (when opening the Outlook message HTML encoding must be true):

    Mail.AddBodyline('<b>Bold Line</b>');

    I'm not that kind of a "shark" in HTML coding, but I think that codeunit 397 does some of the encoding to HTML for you.
  • mdPartnerNLmdPartnerNL Member Posts: 802
    edited 2016-01-26
    ok, thx.

    <edit>you are working with a different version<edit>
  • jensthomsenjensthomsen Member Posts: 173
    Where can I find information about the version?
  • mdPartnerNLmdPartnerNL Member Posts: 802
    no, forget it, my mistake :)
  • jensthomsenjensthomsen Member Posts: 173
    edited 2016-01-26
    deleted
  • sradloff@comsol.agsradloff@comsol.ag Member Posts: 6
    Hi,

    sorry, that I didn't mention to set the var's for RunOnClient=Yes.

    Did you try to add the html Body to a local var of type Text without length and then assign it to the dotnet-body property?
    Otherwise you'll have to create a simple dotnet class with a method, that takes more body lines.
  • jensthomsenjensthomsen Member Posts: 173
    edited 2016-01-27
    I ended up building the HTML body in a (simple) text-variable, and assigning it to iMailItem.HTMLBody which works fine!
    Thx again for helping me out:-)
Sign In or Register to comment.