I have created a macro for outlook which opens up a userform, asks a few questions to select from, and then there's a submit button to send the message and the userform data to a POST url (our ticketing system). I am stuck on the last part of attachments. I can see the attachments list and loop through the attachment item objects, but I don't know which object call to make to send the actual file data to the POST form... all i can see is file size, file name, etc.
Any ideas where i would get the file contents and mime type for adding them to the URL post action as a form var?
Public senderaddress As String
Public thisEmailContent As String
Public thisEmailTEXT As String
Public thisStaffMember As Integer
Public emailAttachments As String
Sub MacroName()
thisStaffMember = 1
Set objItem = GetCurrentItem()
senderaddress = objItem.SenderEmailAddress
thisEmailContent = objItem.HTMLBody
thisEmailTEXT = objItem.Body
emailAttachments = objItem.Attachments
UserformName.Show
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = _
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = _
objApp.ActiveInspector.CurrentItem
Case Else
End Select
End Function
Then here's the last part of the Userform code where it actually sends the data to our ticket system when the Send Now button is clicked...
Public Function encodeURL(str As String)
Dim ScriptEngine As Object
Dim encoded As String
Set ScriptEngine = CreateObject("scriptcontrol")
ScriptEngine.Language = "JScript"
encoded = ScriptEngine.Run("encodeURIComponent", str)
encodeURL = encoded
End Function
Private Sub SendNow_Click()
Set sendReq = CreateObject("MSXML2.XMLHTTP")
With sendReq
.Open "POST", "https://ticketsystemurl.whatever/outlookinterface.php?action=openticket&fromEmail=" & encodeURL(senderaddress) & "&selectedCustomer=" & encodeURL(CustomerSelect.Value) & "&selectedContact=" & encodeURL(ContactSelect.Value), False
.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
.Send ("notifyCustomer=" & NotifyCustomer.Value & "&staffID=" & thisStaffMember & "&emailContent=" & encodeURL(thisEmailContent) & "&emailTEXT=" & encodeURL(thisEmailTEXT) & "&appendTicket=" & AppendToTicket.Value & "&createNewTicket=" & CreateNewTicket.Value & "&selectedTicket=" & encodeURL(SelectTicket.Value) & "&attachments=" & encodeURL(emailAttachments))
End With
Unload Me
End Sub
so far that submits everything except i cant figure out how to populate the post var "attachments" with the actual attachment filedata. Is this even possible?