【问题标题】:how to automatically trigger a link in outlook email using VSTO如何使用 VSTO 自动触发 Outlook 电子邮件中的链接
【发布时间】:2016-11-28 09:46:01
【问题描述】:

我正在尝试以编程方式单击一个链接,该链接创建一封电子邮件,其中包含预定义的主题、收件人、抄送、密件抄送和电子邮件正文内容。我的要求是,如果我选择 Outlook 邮件项目并单击“批准方式”邮件”在我的插件中,代码将在邮件正文中搜索超链接“单击此处批准”并自动单击超链接。 超链接“单击此处批准”创建一封电子邮件,其中包含预定义的主题、收件人、抄送、密件抄送和电子邮件的正文内容。 我不确定如何使用 VSTO 来实现,因为所有其他解决方案都建议使用 JQuery 和 Javascript

Object selObject = this.Application.ActiveExplorer().Selection[1];
        Outlook._MailItem eMail = (Outlook._MailItem)
        this.Application.CreateItem(Outlook.OlItemType.olMailItem);
        eMail = ((Outlook._MailItem)selObject);
        if(eMail.HTMLBody.Contains("Approve"))
        {

        }

我不确定我可以在代码的IF段中写什么。请建议。

【问题讨论】:

  • 试试这个答案:link

标签: c# vsto outlook-addin


【解决方案1】:

Outlook 不提供任何用于打开超链接的功能。您可以使用以下代码 (Process.Start) 在默认 Web 浏览器中打开它们:

Process.Start("your_hyperlink");

或者只是根据单击“批准”按钮的信息在 Outlook 中以编程方式创建一个邮件项目。

 Outlook.MailItem mail = null;
Outlook.Recipients mailRecipients = null;
Outlook.Recipient mailRecipient = null;
try
{
    mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
       as Outlook.MailItem;
    mail.Subject = "A programatically generated e-mail";
    mailRecipients = mail.Recipients;
    mailRecipient = mailRecipients.Add("Eugene Astafiev");
    mailRecipient.Resolve();
    if (mailRecipient.Resolved)
    {
        mail.Send();
    }
    else
    {
        System.Windows.Forms.MessageBox.Show(
            "There is no such record in your address book.");
    }
}
catch (Exception ex)
{
    System.Windows.Forms.MessageBox.Show(ex.Message,
        "An exception is occured in the code of add-in.");
}
finally
{
    if (mailRecipient != null) Marshal.ReleaseComObject(mailRecipient);
    if (mailRecipients != null) Marshal.ReleaseComObject(mailRecipients);
    if (mail != null) Marshal.ReleaseComObject(mail);
}

有关更多信息和示例,请查看以下文章:

【讨论】:

  • 感谢您的回答..但超链接只是一个新的电子邮件窗口,带有自动填充的主题行、密件抄送、抄送和收件人选项..对我来说,没有办法知道所有这些字段..这就是为什么我在想是否还有其他方法
猜你喜欢
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 2016-11-20
  • 2020-09-03
  • 2021-03-08
  • 1970-01-01
相关资源
最近更新 更多