locked
Outlook automation (email signature) RRS feed

  • Question

  • Hi,

    I’m using an email automation to prepare email messages to be sent by outlook.
    It works 100% well, but with one problem I can’t control.
    If the email has no body the default signature is present, if the email has a body the default email signature does is not present.
    How can I build an email with body and the default signature?

    Thursday, December 28, 2017 8:40 PM

Answers

  • Reason for that is when Outlook adds the default signature. ItÄs not done in CreateItem() - where it should be done - but in Display - unless the HTMLBody is not empty.

    So what you do is directly after CreateItem() you Display the new mail item:

    oOutlook = CREATEOBJECT("outlook.application")
    oMail=oOutlook.CreateItem(0)
    oMail.Display()
    lcSignatureHTML = oMail.HTMLBody

    You'll see the signature HTML now is in the htmlbody, which also means you need to deal with the CSS and other stuff already used for it, to add your message your strategy has to change from creating a full HTML document to changing an existing one. This sounds harder than it is, it should just tell you to check your code about creating the html skeleton. Your main message should be HTML you put into the <body></body> section of the HTML already containinig the signature at the begin of the <body>, So only create that part in some variable lcHTML and finally use STUFF() to put it into lcSginatureHTML and then replace the oMail.HTMLBody.

    Bye, Olaf.


    Olaf Doschke - http://www.doschke.name

    • Marked as answer by CNT LM Tuesday, January 16, 2018 5:28 PM
    Friday, December 29, 2017 6:28 AM

All replies

  • Reason for that is when Outlook adds the default signature. ItÄs not done in CreateItem() - where it should be done - but in Display - unless the HTMLBody is not empty.

    So what you do is directly after CreateItem() you Display the new mail item:

    oOutlook = CREATEOBJECT("outlook.application")
    oMail=oOutlook.CreateItem(0)
    oMail.Display()
    lcSignatureHTML = oMail.HTMLBody

    You'll see the signature HTML now is in the htmlbody, which also means you need to deal with the CSS and other stuff already used for it, to add your message your strategy has to change from creating a full HTML document to changing an existing one. This sounds harder than it is, it should just tell you to check your code about creating the html skeleton. Your main message should be HTML you put into the <body></body> section of the HTML already containinig the signature at the begin of the <body>, So only create that part in some variable lcHTML and finally use STUFF() to put it into lcSginatureHTML and then replace the oMail.HTMLBody.

    Bye, Olaf.


    Olaf Doschke - http://www.doschke.name

    • Marked as answer by CNT LM Tuesday, January 16, 2018 5:28 PM
    Friday, December 29, 2017 6:28 AM
  • Hi Olaf,

    It worked more less… that is: I used that code to capture the e-mail signature and then “merge it” with the HTM contents of my e-mail.

    The problem was the signature contains images, and the images do not show in the composed e-mail.

    Here is the example:

    <v:shape id="Imagem_x0020_1" o:spid="_x0000_s1026" type="#_x0000_t75"

     alt="cid:image003.png@01D23C99.37A8ADF0" href="http://www.somesite.com/" style='width:65.25pt;

     height:90.75pt;"t">

     <v:imagedata src="" o:title="image003"/>

    </v:shape>

    Friday, December 29, 2017 4:38 PM
  • Images must be attached, if their src is "cid:..." The part is defining the mime content name.

    What happens if you don't merge anything, just display the mailitem and send it?

    Bye, Olaf.


    Olaf Doschke - http://www.doschke.name

    Friday, December 29, 2017 10:54 PM
  • You can also try

    oMail.GetInspector
    In place of .Display  to bring in the standard signature.


    The English Bob

    Saturday, December 30, 2017 5:29 PM
    Answerer
  • Again:

    What happens if you don't merge anything, just display the mailitem and send it?

    Just do that and you'll see the message gets send with images. Display (or .GetInspector() as given by EnglishBob) don't just add the HTML, but also add mime parts with the image(s).

    Turning it around and merging in the signature HTML into your own HTML might break one of two things: a) tags ensuring the reference of the images working or b) these mime parts not coming in.

    One thing I know for sure: If you first set HTMLBody and then Display()/GetInspector() or never Display()/GetInspector() before Send() the images are not added to the mail item. 

    Anyway, if you just took out the HTML of the signature you don't understand the nature of HTML. Images are not HTML, an image HTML tag just refers to a separate image file as source so you never get a signature with images just by the HTML alone.

    Bye, Olaf.


    Olaf Doschke - http://www.doschke.name

    Sunday, December 31, 2017 6:48 AM