Skip to content

Improvement suggestions #5

@nicowitteman

Description

@nicowitteman

Combining your code with suggestion by @ddavisso4, forcing NO signature for accounts that are not listed, also if they reply to a signed message, and forcing signature for listed accounts even if "sign" was already set to ON manually:

        void OutlookApplication_ItemSend(object Item, ref bool Cancel)
        {
            // loop registry 
            foreach (string value in Registry.CurrentUser.OpenSubKey("SignatureManager").GetValueNames())
            {
                // check if current sender is set in registry to send signature
                if (((Outlook.MailItem)Item).SendUsingAccount.DisplayName == value)
                {
                    string PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003";
                    int currentSecurityFlags = ((Outlook.MailItem)Item).PropertyAccessor.GetProperty(PR_SECURITY_FLAGS);

                    int updatedSecurityFlags = currentSecurityFlags;

                    updatedSecurityFlags |= 1 << 0x1; // set bit 2 ON - forces signing

                    ((Outlook.MailItem)Item).PropertyAccessor.SetProperty(PR_SECURITY_FLAGS, updatedSecurityFlags);
                }
                 else
                {
                    string PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003";
                    int currentSecurityFlags = ((Outlook.MailItem)Item).PropertyAccessor.GetProperty(PR_SECURITY_FLAGS);

                    int updatedSecurityFlags = currentSecurityFlags;

                    updatedSecurityFlags &= ~(1 << 0x1); // set bit 2 OFF - forces no signing

                    ((Outlook.MailItem)Item).PropertyAccessor.SetProperty(PR_SECURITY_FLAGS, updatedSecurityFlags);
                }
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions