Skip to content

Instantly share code, notes, and snippets.

@fagnerdireito
Forked from adamalesandro/sendMailSample.asp
Created December 6, 2021 13:17
Show Gist options
  • Save fagnerdireito/9d7542d37f427806a7bee843f39f0336 to your computer and use it in GitHub Desktop.
Save fagnerdireito/9d7542d37f427806a7bee843f39f0336 to your computer and use it in GitHub Desktop.
Sample Classic ASP function to send email through mail gun's api
<%
'---- Sample code to send email though MailGun
'---- You must populate your base url and api-key below
Function SendMailSync(toAddress, fromAddress, subject, body, htmlBody)
Dim httpPostData
Dim mailGunMessageUrl
Const MAILGUN_BASE_URL = "https://api.mailgun.net/v3/{DOMAIN HERE}"
Const MAILGUN_API_KEY = "key-{API_KEY}"
httpPostData = "from=" & fromAddress
httpPostData = httpPostData & "&to=" & toAddress
httpPostData = httpPostData & "&subject=" & subject
httpPostData = httpPostData & "&text=" & body
httpPostData = httpPostData & "&html=" & htmlBody
set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
mailGunMessageUrl = MAILGUN_BASE_URL & "/messages"
http.Open "POST", mailGunMessageUrl, false, "api", MAILGUN_API_KEY
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Authorization", "Basic AUTH_STRING"
http.Send httpPostdata
If http.status <> 200 Then
Response.Write "An error occurred: " & http.responseText
End If
SendMailSync = http.responseText
Set http = Nothing
End Function
SendMailSync "[email protected]", "No Reply [email protected]", "Test", "Test Mail", ""
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment