开发者

How do I append a User Mail signature in Outlook to an email created programmatically

开发者 https://www.devze.com 2023-01-05 15:24 出处:网络
I have 开发者_运维技巧an OL addin ( c# com using addin express) that is doing something like this

I have 开发者_运维技巧an OL addin ( c# com using addin express) that is doing something like this

mailItem = (Outlook.MailItem)OutlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.To = ReceipientEmailAddress;
mailItem.Subject = "SOME TEXT";
mailItem.Body = NewBody;
mailItem.Display(false);

This is however causing the default signature to disappear i am assuming this is because a newBody is being set I am not able to read the signature in any way or cause the mail creation to include the signature

oh this is OL 2007 .NET 2.0


I had same problem and found no answer, so I decided to solve this by myself getting the signature manually, this is what I did.

       private string ReadSignature()
    {
        string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures";
        string signature = string.Empty;
        DirectoryInfo diInfo = new DirectoryInfo(appDataDir);
        if (diInfo.Exists)
        {
            FileInfo[] fiSignature = diInfo.GetFiles("*.htm");
            if (fiSignature.Length > 0)
            {
                StreamReader sr = new StreamReader(fiSignature[0].FullName, Encoding.Default);
                signature = sr.ReadToEnd();

                if (!string.IsNullOrEmpty(signature))
                {
                    string fileName = fiSignature[0].Name.Replace(fiSignature[0].Extension, string.Empty);
                    signature = signature.Replace(fileName + "_files/", appDataDir + "/" + fileName + "_files/");
                }
            }
        }

        return signature;
    }

Hope this helps.


This one work for me without any additional code.


                            olMail = outlook.CreateItem(0);  
                            olMail.To = toEmailID;
                            olMail.Subject = "Subject";

                            if (attachments != null)
                            {
                                foreach (var path in attachments)
                                {
                                    olMail.Attachments.Add(path);
                                }
                            }

                            olMail.Display();
                            //Display email first and then write body text to get original email template and signature text.

                            if (string.IsNullOrWhiteSpace(htmlBody))
                            {
                                if (!string.IsNullOrWhiteSpace(body))
                                {
                                    olMail.Body = body + olMail.Body;
                                }
                            }
                            else
                            {
                                olMail.HTMLBody = htmlBody + olMail.HTMLBody;
                            }

Hope this helps.

0

精彩评论

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