开发者

Using Redemption, How can I add a default Signature to an outgoing Email Message?

开发者 https://www.devze.com 2023-01-04 21:22 出处:网络
Here is the code that I am using. I have spent some time looking at the Redemption objects, but, nothing jumps out at me:

Here is the code that I am using. I have spent some time looking at the Redemption objects, but, nothing jumps out at me:

    public static bool PopEmail(string domainUserName, string mSubject, string mBody, string mTo, string mCc = "", string mBcc = "", List<String> fileAttachments = null)
    {
        log.Info("Starting to Pop Outlook Email Message");
        RDOSession oSession = new RDOSession();
        try
        {
            oSession.LogonExchangeMailbox(domainUserName, string.Empty);
            if (oSession.LoggedOn)
            {
                RDOMail oMail = oSession.GetDefaultFolder(rdoDefaultFolders.olFolderOutbox).Items.Add("IPM.Note");
                oMail.Subject = mSubject;
                oMail.Body = mBody;
                oMail.To = mTo;
                oMail.CC = mCc;
                oMail.BCC = mBcc;
                if (fileAttachments != null)
                {
                    foreach (string file in fileAttachments)
                    {
                        object newFile = file;
                        oMail.Attachments.Add(newFile, Type.Missing, Type.Missing,开发者_开发技巧 Type.Missing);
                        newFile = null;
                    }
                }
                oMail.Display();
                Marshal.FinalReleaseComObject(oMail);
                oMail = null;
            }
            oSession.Logoff();
            Marshal.FinalReleaseComObject(oSession);
            oSession = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            log.Info("Outlook Email has been Popped.");
            return true;
        }
        catch (Exception)
        {
            log.Error("Outlook Pop Email Failed.");
            throw;
        }
    }

Thank you,


The signature is actually inserted by the Outlook inspector object on instantiation, so if your code is running inside an Outlook addin you could probably try saving the item and then reopening it from the OOM as a _MailItem via _Namespace.GetItemFromId and then calling its GetInspector method (you don't actually have to do anything with the returned inspector reference).

Note that I haven't tried this with an item initially created via RDO. I usually create the items in OOM and then create an RDO wrapper.

If your code is running outside of Outlook you'd have to use OLE to get a reference to its _Application object and then pull the _Namespace object from there. If you are using standalone MAPI without Outlook installed the signature functionality is completely unavailable.


I have added code to append to the oMail.HTMLBody which reads the signature from the C:\Users\UserName\AppData\Roaming\Microsoft\Signatures folder. This file is generated via a plug in written by one of our developers that reads information from Exchange to determine User Name, Title, Phone, Fax, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号