Adding a signature to a message account (setting properties on message accounts)


For those of you with WIndows Mobile 6.1 devices, you might notice that your Activesync emails all automatically have signatures. We’ve gotten requests from partners wanting to do add/modify the signature to an account as well.  Here is a sample function to update the signature for the Activesync account.  Error checking removed in this sample code :).

#include <atlbase.h>
#include <cemapi.h>

HRESULT AddSignatureToAccount()
    HRESULT hr;

    CComPtr<IMAPITable> ptbl;
    CComPtr<IMAPISession> pSession;
    CComPtr<IMsgStore> pMsgStore;

    // Log onto MAPI
    hr = MAPILogonEx(0, NULL, NULL, 0, static_cast<LPMAPISESSION *>(&pSession));

    // You can open a different message store here instead of the default
    hr = pSession->OpenMsgStore(NULL, 0, NULL, NULL, 0, &pMsgStore);

    SPropValue rgspv[3] = { 0 };

    rgspv[0].ulPropTag      =   PR_CE_SIGNATURE;    // signature content
    rgspv[0].Value.lpszW    =   L”Sent from my personal Windows Mobile phone”;
    rgspv[1].ulPropTag      =   PR_CE_USE_SIGNATURE;    // use the signature in newly composed emails
    rgspv[1].Value.b        =   TRUE;
    rgspv[2].ulPropTag      =   PR_CE_USE_SIGNATURE_REPLY_FORWARD;    // use signature in replied or forwarded emails
    rgspv[2].Value.b        =   TRUE;

    // save the data the properties
    hr = pMsgStore->SetProps (3, rgspv, NULL);
    // Log off
    pSession->Logoff(0, 0, 0);

    return hr;

This should be a good starting point on how to set properties on message accounts as well. You can find a list of valid properties in mapitags.h.  Have fun!

Comments (17)

  1. guojing says:

    this is good for mobile programmer

  2. guojing says:

    Is there any document about How to Use SDK of Windows Mobile 6.0 (doc or pdf)?

  3. Jay says:

    guojing, you can download the Windows Mobile 6 SDK off I don’t think it’s available as a .doc or pdf, but the SDK comes with help files.

  4. SM says:

    What? Write code to change the signature on an email account? I hope Windows Mobile 6.1 also allows a non programmer to change the default signature like the Backberry and Iphone does.

  5. Satya says:

    Really good article. I have been following your blog for last 3 months. You have good knowledge

    on Mobile(cell phone) Industry and happenings. Please continue the good work. Thank you.

  6. jayongg says:

    SM – yes it is possible to do that via the UI. But this is more for ISVs or OEMs who may want to install their own transport, or modify existing ones.

  7. SM says:

    Thanks Jayongg. I get it now and understand the scenario when it will be useful. So HTC (just an example) could default the signature to "Sent from my HTC Diamond touch device" !

  8. Kevin says:

    I just switched from a BB to Windows Mobile 6.1 and was shocked to find you can’t change your own signature like I could on the BB and iPhone. For how advanced WM 6.1 is, it’s still missing some basic features.

  9. JRagan says:

    Kevin – Yes you can certainly change your email signature.  Dig deeper into the options.

  10. jsumedh says:

    How do I create new  SMS account programmtically in Messaging application and use my own Message store and transport.

    I can create POP3 accout with DMConfigProcessXML, but when I try to create SMS account DMConfigProcessXML fails. What exacltly the SERVICETYPE would be in case of SMS.

    Any help is appreciated.

  11. Rob says:

    I’m trying to add the pipe character | in my signature but it isn’t available in the FN-SHIFT additional character screen. Is there a way to get it to appear? I tried copy/past but you can’t utilize paste in the email signature screen. Thanks.

  12. jayongg says:

    jsumedh  – Hi, sorry you can’t add a new SMS account. only one per device.

    Rob – your device should have a method to bring up the symbol table – the pipe should be there.

  13. Bambi Blue says:

    Is there a way to make it so that the signature doesn’t have a carriage return built into it? When ever I type a message on my HTC Kaiser (AT&T Tilt) it automatically adds a reurn on top of the first line for my message. So when typing it looks like this:

    (first line message)


    I would prefer if it looked like this:

    (first line message)


  14. Maybe I’m a dummy – but can’t this just be changed from within the email settings?

  15. Looking for the Vertical Bar character says:

    I can’t find the piple character either.  It’s not under my symbol list.  I’m using a MOTO Qc running Windows Mobile 6.1

  16. schu1538 says:

    * I meant to say "pipe" character (i.e. vertical line)

  17. Chiu Wen says:

    I am a student from temasek poly. I have a huge query that i am struggling. I am doing a project on a HTC tytn 2 phone. May i ask how could I actually include a .cs file with a .vb file into same project? Is there any dll file needed to add for reference?

    I wanted to click a button from a from in .vb. Then is there any specific codes to access a .cs file after clicking the button? The .cs file i have enable it to direct access to the HTC tytn 2 camera.

    Hope to hear from your reply soon.

    Chiu wen,