Skip to content

Instantly share code, notes, and snippets.

@expressmailing
Created December 15, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expressmailing/57b76a70e0bf92215ca08c75bfc4865b to your computer and use it in GitHub Desktop.
Save expressmailing/57b76a70e0bf92215ca08c75bfc4865b to your computer and use it in GitHub Desktop.
Exemple en VB 4/5/6 d'envoi de fax unitaire
Private Sub Form_Load()
' Récupération du document en base64
' ---------------------------------------
Dim filename As String, file() As Byte, filnum As Integer, binary As String
filename = "test-fax.doc"
filnum = FreeFile()
Open filename For Binary As filnum
file = InputB(LOF(filnum), #filnum)
Close filenum
binary = EncodeBase64(file)
' Création du XML à poster
' --------------------------
Dim xml As String
xml = "<request login=""your-login"" password=""your-password"">" & _
"<push media=""fax"" type=""on_demand"" name=""Test API Fax VB6"">" & _
"<message type=""doc"">" & binary & "</message>" & _
"<recipients>" & _
"<add target=""+33 170248254"" />" & _
"</recipients>" & _
"</push>" & _
"</request>"
' Construction et envoi de la requête HTTP
' ------------------------------------------
Dim postURL As String
postURL = "http://api.express-mailing.com/transac/api.ashx"
With CreateObject("MSXML2.XMLHTTP")
.open "POST", postURL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send (xml)
response = .responseText
End With
MsgBox (response)
End Sub
Private Function EncodeBase64(ByRef binary() As Byte) As String
Dim objXML, objNode
Set objXML = CreateObject("Microsoft.XMLDOM")
Set objNode = objXML.createElement("doc")
objNode.dataType = "bin.base64"
objNode.nodeTypedValue = binary
EncodeBase64 = objNode.Text
Set objNode = Nothing
Set objXML = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment