简体   繁体   中英

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). 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).

(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 . 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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