Last active
December 6, 2021 13:17
-
-
Save adamalesandro/e7821356128a551e7211 to your computer and use it in GitHub Desktop.
Sample Classic ASP function to send email through mail gun's api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
'---- 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
hi there,
I am trying to use mailguns smtp service with a classic asp website do you have any examples.. my code is as follows: