Guest User

Untitled

a guest
May 17th, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. sFrom = "test@notifications.com"
  2. Dim HttpReqURL As String: HttpReqURL = "https://api.sendgrid.com/api/mail.send.json"
  3. Const adSaveCreateNotExist = 1
  4. Const adSaveCreateOverWrite = 2
  5. Const adTypeBinary = 1
  6. Const adTypeText = 2
  7. Const adModeReadWrite = 3
  8. Dim eUser As String
  9. Dim ePass As String
  10. eUser = "apikey"
  11. ePass = "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"
  12. Dim multiPartUploadBoundary As String
  13. multiPartUploadBoundary = "123456789abc"
  14. Dim outputStream As Object
  15. Dim eTo1() As String
  16. Dim eCC1() As String
  17. Dim intCounter As Integer
  18.  
  19. sTo = "test@mail.com"
  20. eTo1 = Split(sTo, ",")
  21. eCC1 = Split(sCC, ",")
  22. 'For intCounter = LBound(eTo1()) To UBound(eTo1())
  23. 'MsgBox eTo1(intCounter)
  24. 'Next intCounter
  25.  
  26. 'Dim eTo As String
  27. 'Dim eToName As String
  28. 'Dim eSubject As String
  29. 'Dim eBody As String
  30.  
  31. Set outputStream = CreateObject("adodb.stream")
  32. outputStream.Type = adTypeText
  33. outputStream.Mode = adModeReadWrite
  34. outputStream.Charset = "windows-1252"
  35. outputStream.Open
  36.  
  37. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "api_user", eUser
  38. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "api_key", ePass
  39.  
  40. For intCounter = LBound(eTo1()) To UBound(eTo1())
  41. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "to", eTo1(intCounter)
  42. 'MsgBox eTo1(intCounter)
  43. Next intCounter
  44.  
  45. For intCounter = LBound(eCC1()) To UBound(eCC1())
  46. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "cc", eCC1(intCounter)
  47. 'MsgBox eTo1(intCounter)
  48. Next intCounter
  49.  
  50. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "subject", sSubject
  51. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "text", sbody
  52. AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "from", sFrom
  53. Dim filesToAttach As New Collection
  54. 'filesToAttach.Add "C:temptest.jpg"
  55. If Not sFile = "" Then
  56. filesToAttach.Add sFile
  57. End If
  58. 'filesToAttach.Add sFile
  59. AddMultipleFilesToStream outputStream, multiPartUploadBoundary, filesToAttach
  60. outputStream.WriteText "--" + multiPartUploadBoundary + "--" + vbCrLf
  61.  
  62. Dim binaryStream As Object
  63. Set binaryStream = CreateObject("ADODB.Stream")
  64. binaryStream.Mode = 3 'read write
  65. binaryStream.Type = 1 'adTypeText 'Binary
  66. binaryStream.Open
  67. ' copy text to binary stream so xmlHttp.send works correctly
  68. outputStream.Position = 0
  69. outputStream.CopyTo binaryStream
  70. outputStream.Close
  71. binaryStream.Position = 0
  72. Dim xmlHttp As Object
  73. Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
  74. xmlHttp.Open "POST", HttpReqURL, False
  75. xmlHttp.setRequestHeader "Authorization: ", "Bearer " & ePass
  76. xmlHttp.setRequestHeader "Content-Type", "multipart/form-data; boundary=" + multiPartUploadBoundary
  77. xmlHttp.setRequestHeader "Content-Length", Len(binaryStream.Size)
  78. xmlHttp.Send binaryStream.Read(binaryStream.Size)
  79. Dim strXML As String
  80. Dim byteData() As Byte
  81. Dim ReturnSuccess As Integer
  82. ReturnSuccess = 0
  83. byteData = xmlHttp.responseBody
  84. Set xmlHttp = Nothing
  85. strXML = StrConv(byteData, vbUnicode)
  86. ReturnSuccess = InStr(strXML, "success")
  87. 'MsgBox strXML
  88. binaryStream.Close
Add Comment
Please, Sign In to add comment