You might all having the difficult time in finding a Classic ASP Email function to send emails with SendGrid API. We made a basic function which can be used to send using SendGrid API JSON request. It is hard to find a good object to create JSON document.
- Sending Email using SendGrid API
- Sending Email using SendGrid SMTP
1. Sending Email using SendGrid API
Creating SendGridMail Function
Replace <APIKEY> value with your SendGrid API Key
You can include more JSON object from here
Contact ccs.rentacoder (at) gmail.com for API SendGrid function
Sending email
mailto="david@example.com"
mailtoname="David"
mailsubject="<}sending mail"
mailcontent="<}If it helped you make a PayPal donation to us "
sendgridmail mailto,mailtoname,mailsubject,mailcontent
2. Sending Email using SMTP
SMTP Server password will be your SendGrid API Key
smtp.sendgrid.net – SMTP server
SMTP Server username – apikey
<%
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
'Set and update CDO Configuration
With objCDOSYSCon
' Specify the authentication mechanism to basic (clear-text) authentication cdoBasic = 1
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'SMTP Server username
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "apikey"
'SMTP Server password
.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "API-KEY HERE"
'Out going SMTP server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.sendgrid.net"
'SMTP port
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
'TLS Encryption
.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = 1
'CDO Port (1=localhost 2=network)
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
'Update CDO Configuration
.Fields.Update
End With
'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
With objCDOSYSMail
'Who the e-mail is from, this needs to be the same as your SMTP Server username
.From = "from@example.com"
'Who the e-mail is sent to
.To = "to@example.com"
'Who to reply-to when replying to the email
.ReplyTo = "replyto@example.com"
'The subject of the e-mail
.Subject = "Link tracking - Website Enquiry"
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
.HTMLBody = "this is the body <a href='example.com'>click here</a>"
'.TextBody = "this is the body"
'Send the e-mail
.Send
End with
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>