简体   繁体   English

发件人以发送邮箱为条件

[英]Reply body conditioned by mailbox it is sent from

So I have multiple mailboxes under my Outlook account and I am trying to get them to generate reply template based on the mailbox I am replying from (one is private, one is shared). 因此,我的Outlook帐户下有多个邮箱,我试图让它们根据我要回复的邮箱生成回复模板(一个是私有的,一个是共享的)。 I have tried to base the condition on SenderName and SenderEmailAddress , but to no avail (reply email gets generated with the contents of the previous email retrieved but the text I intend to put in front of it is not there; the cause is that the value of oReply.SenderEmailAddress is empty as Else clause will write the stuff as intended). 我试图将条件基于SenderNameSenderEmailAddress ,但无济于事(回复的电子邮件是使用检索到的先前电子邮件的内容生成的,但是我要放在其前面的文本不存在;原因是该值oReply.SenderEmailAddress的字段为空,因为Else子句将按预期写入内容。

(and yes, there are snippets from code enabling reply with attachments) (是的,代码中有一些片段可以对附件进行回复)

Sub ReplyWithAttachments()
    Dim oReply As Outlook.MailItem
    Dim oItem As Object
    Dim sSignature As String

    Set oItem = GetCurrentItem()
    If Not oItem Is Nothing Then
        Set oReply = oItem.Reply

        If oReply.SenderEmailAddress = "mailbox.private@something.com" Then
            sSignature = "Hello and welcome!"
        ElseIf oReply.SenderEmailAddress = "mailbox.shared@something.com" Then
            sSignature = "Go to hell!"        
        End If

        CopyAttachments oItem, oReply
        oReply.HTMLBody = sSignature & oReply.HTMLBody
        oReply.Display
        oItem.UnRead = False
    End If

    Set oReply = Nothing
    Set oItem = Nothing
End Sub

Edit: so I managed to get somewhere with 编辑:所以我设法与某处

Set oReply = oItem.Reply
sMailBox = oReply.Sender.GetExchangeUser.Address

If sMailBox = "mailbox.private@something.com" Then
    sSignature = "whatever"
ElseIf sMailBox = "mailbox.shared@something.com" Then
    sSignature = "bla bla bla"
Else
    sSignature = "Something"

The code works as intended for the shared mailbox but for the private one, it errors out with Object variable or With block variable not set pointing to . 该代码按预期的方式用于共享邮箱,但对于专用邮箱,由于Object变量或Block变量未设置为指向,它会出错。 Sender 发件人

sMailBox = oReply.Sender.GetExchangeUser.Address

I have something that I use to get sender email (as its dependent on your email exchange) 我有一些东西可以用来获取发件人电子邮件(取决于您的电子邮件交换)

Dim strSendersEmailAddress As String

If oItem.SenderEmailType = "EX" Then
    strSendersEmailAddress = oItem.Sender.GetExchangeUser.PrimarySmtpAddress
Else
    strSendersEmailAddress = oItem.SenderEmailAddress
End If

You will have to get the email address before you Set oReply = oItem.Reply Set oReply = oItem.Reply之前,您必须获取电子邮件地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM