Outlook-根据收件人插入文本 [英] Outlook - insert text based on recipient

查看:115
本文介绍了Outlook-根据收件人插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据收件人自动将文本插入待发电子邮件中.我在另一个看起来很有希望的问题(归功于76Mel)的答案中找到了一些代码.看来我可以将代码附加到ThisOutlookSession中的ItemSend

I need to automatically insert text into an outgoing email depending on the recipient. I found some code in an answer to another question (credit to 76Mel) that looks promising. It seems that I could attach the code to ItemSend in ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   If Item.MessageClass = "IPM.Note" Then
       For Each myRecipient In Item.Recipients
           If myRecipient.Address = "<EMAIL ADDRESS TO FIND>" Then 
           <code to add text>
           End If
       Next
   End If
End Sub 

将文本添加到电子邮件正文的代码是什么-甚至可以工作吗?此代码会在发送电子邮件之前触发,还是为时已晚?

What would the code be that adds the text to the body of the email - and would this even work? Would this code fire before the email is sent, or is it already too late?

我确实需要将其自动化(创建按钮或手动运行宏并不是真正的选择;这是一种记忆力:如果我记得运行宏,则可以手动添加文本)

I do need it to be automated (creating a button or running the macro manually isn't really an option; it's a memory thing: if I could remember to run the macro, I could just add the text manually)

推荐答案

这是您要尝试的吗?我已经添加了评论,所以您理解它应该没有任何问题:)如果您还有问题,只需问...

Is this what you are trying? I have added the comments so you shouldn't have any problem understanding it :) If you still have a question, simply ask...

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    '~~> Check if it is an email
    If TypeName(Item) <> "MailItem" Then Exit Sub

    Dim srchString As String, NewText As String

    '~~> Email Address which you want to search for
    srchString = "abc@gmail.com"

    '~~> New text that you want to add
    NewText = "Blah Blah"

    '~~> Search To, CC, BCC Fields
    If InStr(1, Item.To, srchString, vbTextCompare) Or _
    InStr(1, Item.CC, srchString, vbTextCompare) Or _
    InStr(1, Item.BCC, srchString, vbTextCompare) Then
        '~~> Add the relevant text to the body
        Item.Body = Item.Body & vbNewLine & NewText
    End If
End Sub

我会推荐此MSDN链接.

I would recommend this MSDN Link.

主题:MailItem对象成员

Topic: MailItem Object Members

链接: http://msdn.microsoft.com/zh-cn/library/bb176688%28v=office.12%29.aspx

从上方链接引用

表示收件箱文件夹中的一封邮件.

Represents a mail message in an Inbox folder.

列出MailItem对象的所有方法/属性

Lists all Methods / Properties for a MailItem Object

这篇关于Outlook-根据收件人插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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