none
adding default signature when creating an email programmatically RRS feed

  • Question

  • Hi

    I am using the following code to create a new email with email address, subject and body filled in

    This works fine, BUT doing it this way means when it adds the body text it is then removing/overwriting my default signature

    How can I modify this code so it leaves my signature intact -  or how can I insert my default signature at the end of the body text?

    Thanks

    Private Sub setEmailSend(sSubject As String, sBody As String, sTo As String)
            Dim oApp As Outlook._Application
            oApp = New Outlook.Application
    
            Dim oMsg As Outlook._MailItem
            oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
    
            oMsg.Subject = sSubject
            oMsg.Body = sBody
    
            oMsg.To = sTo
    
            'oMsg.Send()   ' to send email immediately
            oMsg.Display() ' to show email ready for you to check and click send
        End Sub

    And calling it with

    setEmailSend("Email Support Service", "body text", "test@test.com")


    Darren Rose

    Saturday, October 18, 2014 7:02 PM

All replies

  • Call Display first - Outlook adds the signature when you display a new item or when you touch the GetInspector property. Then merge the existing body (signature) with your data. You might want to use HTMLBody property to make sure you don't wipe out the formatting, but merging of course will be more complex - find the position of the "<body" substring, find the position of the next ">", insert your text after it.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Saturday, October 18, 2014 9:04 PM
  • okay will have a play and see what happens

    I am currently using stringbuilder to create the body of the email - so could always add my signature on the end like that - but trouble is with stringbuilder I can use bold/underline etc or create hyperlinks for url in my signature etc


    Darren Rose

    Saturday, October 18, 2014 9:24 PM
  • Stringbuilder has nothing to do with the fact that you build plain text body. As I mentioned before, you need to read/write the HTMLBody property, not the plain text Body.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Saturday, October 18, 2014 10:17 PM
  • Yes I got and understood that bit - and have tried it, but then I lose all the formatting of my body that I created in the stringbuilder i.e. no line returns etc - and still no signature appearing

    I only asked re stringbuilder to find if way to add formatting such as bold etc- but obviously if I do HTMLbody then I need to do something different than stringbuilder to hold the body text/formatting etc?!?!


    Darren Rose

    Saturday, October 18, 2014 11:11 PM
  • If you have line returns, they needs to be appropriately coded using <br> or <p> tags.

    You can still use string builder to build HTML, but you need to treat the data as HTML, not plain text.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Saturday, October 18, 2014 11:14 PM
  • okay I see - so <b> for bold and <br> for line break etc - that makes sense I had use vbCrLf for line breaks

    But still no signature appearing, so original problem still exists


    Darren Rose

    Saturday, October 18, 2014 11:16 PM
  • has also changed the font? despite calibri being my normal default, using HTMLbody it now appears as Times New Roman - can I change this?

    Darren Rose

    Saturday, October 18, 2014 11:18 PM
  • You need to expliiclty specify the font, e.g.
    <span style="font-size: 9.5pt; font-family: Arial; color: blue;">My text</span>
    Create your text in an HTML editor, then look at its raw HTML text.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Saturday, October 18, 2014 11:33 PM
  • thanks

    will do this to recreate my signature as well then - as its not appearing still


    Darren Rose

    Saturday, October 18, 2014 11:50 PM
  • Are you touching the GetInspector property or calling Display before merging the body and setting it back? What is your latest code?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Sunday, October 19, 2014 12:24 AM
  • no, because I don't fully understand what you mean

    But not really a problem, as my signature is simple enough to recreate in HTML in the body anyway

    Worked out how to bold, set font family, but issues with setting font size - I would really like it to be 11pt but doesn't seem to be way? unless I am missing something to do it in pt sizes?

    The below gives me calibri in 12pt

    sb.AppendLine("<font face='calibri'><font-size='3'>")

    Is there a way to get 11pt?


    Darren Rose

    Sunday, October 19, 2014 12:50 AM
  • That's probably not a question for an Outlook forum, but try to create document in Word with the desired style and save it as HTML.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Sunday, October 19, 2014 4:33 AM