Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sFrom = "test@notifications.com"
- Dim HttpReqURL As String: HttpReqURL = "https://api.sendgrid.com/api/mail.send.json"
- Const adSaveCreateNotExist = 1
- Const adSaveCreateOverWrite = 2
- Const adTypeBinary = 1
- Const adTypeText = 2
- Const adModeReadWrite = 3
- Dim eUser As String
- Dim ePass As String
- eUser = "apikey"
- ePass = "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"
- Dim multiPartUploadBoundary As String
- multiPartUploadBoundary = "123456789abc"
- Dim outputStream As Object
- Dim eTo1() As String
- Dim eCC1() As String
- Dim intCounter As Integer
- sTo = "test@mail.com"
- eTo1 = Split(sTo, ",")
- eCC1 = Split(sCC, ",")
- 'For intCounter = LBound(eTo1()) To UBound(eTo1())
- 'MsgBox eTo1(intCounter)
- 'Next intCounter
- 'Dim eTo As String
- 'Dim eToName As String
- 'Dim eSubject As String
- 'Dim eBody As String
- Set outputStream = CreateObject("adodb.stream")
- outputStream.Type = adTypeText
- outputStream.Mode = adModeReadWrite
- outputStream.Charset = "windows-1252"
- outputStream.Open
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "api_user", eUser
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "api_key", ePass
- For intCounter = LBound(eTo1()) To UBound(eTo1())
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "to", eTo1(intCounter)
- 'MsgBox eTo1(intCounter)
- Next intCounter
- For intCounter = LBound(eCC1()) To UBound(eCC1())
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "cc", eCC1(intCounter)
- 'MsgBox eTo1(intCounter)
- Next intCounter
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "subject", sSubject
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "text", sbody
- AddParameterAndValueToStream outputStream, multiPartUploadBoundary, "from", sFrom
- Dim filesToAttach As New Collection
- 'filesToAttach.Add "C:temptest.jpg"
- If Not sFile = "" Then
- filesToAttach.Add sFile
- End If
- 'filesToAttach.Add sFile
- AddMultipleFilesToStream outputStream, multiPartUploadBoundary, filesToAttach
- outputStream.WriteText "--" + multiPartUploadBoundary + "--" + vbCrLf
- Dim binaryStream As Object
- Set binaryStream = CreateObject("ADODB.Stream")
- binaryStream.Mode = 3 'read write
- binaryStream.Type = 1 'adTypeText 'Binary
- binaryStream.Open
- ' copy text to binary stream so xmlHttp.send works correctly
- outputStream.Position = 0
- outputStream.CopyTo binaryStream
- outputStream.Close
- binaryStream.Position = 0
- Dim xmlHttp As Object
- Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
- xmlHttp.Open "POST", HttpReqURL, False
- xmlHttp.setRequestHeader "Authorization: ", "Bearer " & ePass
- xmlHttp.setRequestHeader "Content-Type", "multipart/form-data; boundary=" + multiPartUploadBoundary
- xmlHttp.setRequestHeader "Content-Length", Len(binaryStream.Size)
- xmlHttp.Send binaryStream.Read(binaryStream.Size)
- Dim strXML As String
- Dim byteData() As Byte
- Dim ReturnSuccess As Integer
- ReturnSuccess = 0
- byteData = xmlHttp.responseBody
- Set xmlHttp = Nothing
- strXML = StrConv(byteData, vbUnicode)
- ReturnSuccess = InStr(strXML, "success")
- 'MsgBox strXML
- binaryStream.Close
Add Comment
Please, Sign In to add comment