简体   繁体   中英

VotingOptions Response Reply with Custom Body

I have a macro that runs when I accept specific emails. It replies to the email with a voting option of either "Approved" or "Rejected".

When the recipient of the voting option responds with their choice, the received "choice" email does not have a body. Is there a way to retain the body?

I've tried this so far:

With objMsg
    .To = strEmail
    .HTMLBody = Item.HTMLBody
    .Subject = "Is This Approved?"
    .VotingOptions = "Approved;Rejected"
    .VotingResponse = "Yes"
    .Attachments.Add Item
    .Display
    .Send
End With

I believe this is only affecting the initial email and not the responses.

I looked at the MailItem Object , but didn't see any options for Voting outside of .VotingOptions and .VotingResponse .

I would be open to ideas outside of Voting buttons (such as a Task or something like that) as long as it can include the body in the response.

As I mentioned in the comments above, I think adding a small hash to the subject is the only way you can track message thread replies. Below is some code for generating a hash based on the date and time to add as a prefix to the subject

Sub TestHash()
    Dim lDate As Date: lDate = Now
    MsgBox DateTimeHash(lDate)
End Sub

Function DateTimeHash(lDate As Date) As String
    DateTimeHash = "#" & fBase36Encode(DateValue(lDate)) & _
    fBase36Encode(60 * (60 * Hour(lDate) + Minute(lDate)) + Second(lDate)) & "#"
End Function

Function fBase36Encode(ByRef lngNumToConvert As Long) As String
    'Will Convert any Positive Integer to a Base36 String
    fBase36Encode = "0"
    If lngNumToConvert = 0 Then Exit Function

    Dim strAlphabet As String: strAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    fBase36Encode = vbNullString
    Do While lngNumToConvert <> 0
        fBase36Encode = Mid(strAlphabet, lngNumToConvert Mod 36 + 1, 1) & fBase36Encode
        lngNumToConvert = lngNumToConvert \ 36
    Loop
End Function

* EDIT *

Using a reversible base 64 hash instead:

Sub TestHash()
    Dim lDate As Date: lDate = Now
    Debug.Print DateTimeHash(lDate)
    Debug.Print DateTimeUnhash(DateTimeHash(lDate))
End Sub

Function DateTimeHash(ByRef lDate As Date) As String
    Dim Secs As String: Secs = Encode64(60 * (60 * Hour(lDate) + Minute(lDate)) + Second(lDate))
    DateTimeHash = "#" & Encode64(DateValue(lDate)) & String(3 - Len(Secs), "0") & Secs & "#"
End Function

Function DateTimeUnhash(ByRef Hash As String) As Date
    Hash = Replace(Hash, "#", "")
    Dim Days As Long: Days = Decode64(Left(Hash, Len(Hash) - 3))
    Dim Secs As Long: Secs = Decode64(Right(Hash, 3))
    DateTimeUnhash = DateAdd("d", Days, "0") + DateAdd("s", Secs, "0")
End Function

Function Encode64(ByRef Value As Long) As String
    'Will Convert any Positive Integer to a Base64 String
    Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

    Encode64 = IIf(Value > 0, vbNullString, "0")
    If Encode64 = "0" Then Exit Function
    Do While Value <> 0
        Encode64 = Mid(Base64, Value Mod 64 + 1, 1) & Encode64
        Value = Value \ 64
    Loop
End Function

Function Decode64(ByRef Value As String) As Long
    'Will Convert any Base64 String to a Positive Integer
    Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

    Decode64 = IIf(Value = "", -1, 0)
    Dim i As Long: For i = 1 To Len(Value)
        If Decode64 = -1 Then Exit Function ' Error detected with Value string
        Decode64 = Decode64 * 64
        Decode64 = IIf(InStr(Base64, Mid(Value, i, 1)) > 0, _
            Decode64 + InStr(Base64, Mid(Value, i, 1)) - 1, -1)
    Next i
End Function

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