Outlook加载项将文本添加到邮件正文 [英] Outlook Add-on to Add Text to Mail Body

查看:113
本文介绍了Outlook加载项将文本添加到邮件正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小的Outlook加载项,如果电子邮件主题包含某个字符串,则将链接添加到电子邮件正文中.当前,仅当(双击)打开邮件时,才会添加链接.有没有一种方法可以添加链接而无需用户先打开消息?还是我要问的是不可能的?如果是这样,为什么?

I've created a small Outlook add-on to add a link into the body of an email if the email subject contains a certain string. Currently, the link will only be added if the mail is (double-clicked) opened. Is there a way to add the link without the user opening the message first? Or is what I'm asking impossible? And if so, why?

void inspectors_NewInspector(Inspector Inspector)
{
  Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
  if (mailItem != null)
  {
     if (mailItem.Subject.StartsWith("ABCDE"))
     {
        mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
        mailItem.HTMLBody = "<html><body>Click <a href='www.google.com'>here</a>.<br><br></body></html>" + mailItem.HTMLBody;
        mailItem.Save();
     }
  }
}

推荐答案

我实际上是自己找到了答案,以后会在任何需要的人下面发布.我使用了答案作为指南.

I actually found the answer to this on my own and will post it below for anyone needing it in the future. I used THIS answer as a guide.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
   this.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(olApp_NewMail);
}

private void olApp_NewMail(String entryIDCollection)
{
   Outlook.NameSpace outlookNS = this.Application.GetNamespace("MAPI");
   Outlook.MAPIFolder mFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
   Outlook.MailItem mail;

   try
   {
      mail = (Outlook.MailItem)outlookNS.GetItemFromID(entryIDCollection, Type.Missing);
      if (mailItem.Subject.StartsWith("ABCDE"))
      {
         mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
         mailItem.HTMLBody = "<html><body>Click <a href='www.google.com'>here</a>.<br><br></body></html>" + mailItem.HTMLBody;
         mailItem.Save();
      }
   }
   catch
   {}
}

这篇关于Outlook加载项将文本添加到邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆