0

I've set up a URL for a web hook in the Mailgun control panel and have set up a script to append a txt file with the HTTP Post from Mailgun to the URL when a bounce occurs. I've tested it by submitting a HTTP Post from a test page submitting a form and the form data gets written to the txt file fine - however when I trigger the test from Mailgun a new line gets written but the Request.Form collect appears to be empty.

Am I missing something in the HTTP Post from Mailgun and the way I'm trying to get the request.form collection from it?

<%
strWebhookData = "///// New Entry ///" & vbnewline
For Each Item In Request.Form
        fieldName = Item
        fieldValue = Request.Form(Item)
        Response.write fieldName & " " & fieldValue
        strWebhookData =  strWebhookData & fieldName &" = " & fieldValue & vbnewline        
    Next 
Response.write strWebhookData

set fs=Server.CreateObject("Scripting.FileSystemObject")
    set f=fs.OpenTextFile(Server.MapPath("bounces.txt"),8,true)
    f.WriteLine(vbnewline & strWebhookData)
    f.Close
set f=Nothing
set fs=Nothing

%>
Craig Ray
  • 83
  • 1
  • 8

3 Answers3

0

Not sure if this will work but try

For Each x In Request.Form
    fieldName = x
    fieldValue = Request.Form(x)
    Response.write fieldName & " " & fieldValue
    strWebhookData =  strWebhookData & fieldName &" = " & fieldValue & vbnewline        
Next
pee2pee
  • 3,619
  • 7
  • 52
  • 133
  • Thanks for that - but the script does capture form variables from a test page I am using to post to that page but not capturing anything from the Mailgun HTTP Post. I'll try what you suggest anyhow. – Craig Ray Sep 23 '14 at 09:41
  • What's the Mailgun HTTP Post code look like? Can you inspect if anything is actually being transferred with developer tools (chrome) or Firebug (FireFox) – pee2pee Sep 23 '14 at 09:43
  • Here's the output from HTTP_RAW if that helps. Content-Length: 4230 Content-Type: multipart/form-data; boundary=2adc9741-1b71-4442-9377-170f6562daea Accept-Encoding: gzip User-Agent: mailgun/treq-0.2.1 – Craig Ray Sep 23 '14 at 10:10
0

I´m using this code, i really don´t remember where i find it:

Response.Expires=0
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest  RequestBin

'Some example variables

strEvent    = UploadRequest.Item("event").Item("Value")
strEmail    = UploadRequest.Item("recipient").Item("Value")

'You can find all variables on mailgun Log tab

Sub BuildUploadRequest(RequestBin)
    'Get the boundary
    PosBeg = 1
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    boundaryPos = InstrB(1,RequestBin,boundary)
    'Get all data inside the boundaries
    Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
        'Members variable of objects are put in a dictionary object
        Dim UploadControl
        Set UploadControl = CreateObject("Scripting.Dictionary")
        'Get an object name
        Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
        Pos = InstrB(Pos,RequestBin,getByteString("name="))
        PosBeg = Pos+6
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
        Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
        PosBound = InstrB(PosEnd,RequestBin,boundary)
        'Test if object is of file type
        If  PosFile<>0 AND (PosFile<PosBound) Then
            'Get Filename, content-type and content of file
            PosBeg = PosFile + 10
            PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
            FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
            'Add filename to dictionary object
            UploadControl.Add "FileName", FileName
            Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
            PosBeg = Pos+14
            PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
            'Add content-type to dictionary object
            ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
            UploadControl.Add "ContentType",ContentType
            'Get content of object
            PosBeg = PosEnd+4
            PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
            Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
            Else
            'Get content of object
            Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
            PosBeg = Pos+4
            PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
            Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        End If
        'Add content to dictionary object
    UploadControl.Add "Value" , Value   
        'Add dictionary object to main dictionary
    UploadRequest.Add name, UploadControl   
        'Loop to next object
        BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
    Loop

End Sub

'String to byte string conversion
Function getByteString(StringStr)
 For i = 1 to Len(StringStr)
    char = Mid(StringStr,i,1)
    getByteString = getByteString & chrB(AscB(char))
 Next
End Function

'Byte string to string conversion
Function getString(StringBin)
 getString =""
 For intCount = 1 to LenB(StringBin)
    getString = getString & chr(AscB(MidB(StringBin,intCount,1))) 
 Next
End Function

user2200620
  • 41
  • 1
  • 1
  • 4
0

the data is multipart/form-data; - i used aspUpload to read the variables from their form

Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.Save

strEvent        = Upload.Form("event")
sBounceEmail    = Upload.Form("recipient")