Created
November 11, 2013 22:38
-
-
Save heitortsergent/7421803 to your computer and use it in GitHub Desktop.
Sendgrid - Unity Email using Web 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
public void SendSendgridEmailWebAPI () { | |
string url = "https://sendgrid.com/api/mail.send.json?"; | |
url += "to=" + toEmail; | |
url += "&from=" + fromEmail; | |
//you have to change every instance of space to %20 or you'll get a 400 error | |
string subjectWithoutSpace = subject.Replace(" ", "%20"); | |
url += "&subject=" + subjectWithoutSpace; | |
string bodyWithoutSpace = body.Replace(" ", "%20"); | |
url += "&text=" + bodyWithoutSpace; | |
url += "&x-smtpapi=" + xsmtpapiJSON; | |
url += "&api_user=" + api_user; | |
url += "&api_key=" + api_key; | |
WWW www = new WWW(url); | |
StartCoroutine(WaitForRequest(www)); | |
} | |
IEnumerator WaitForRequest(WWW www) | |
{ | |
yield return www; | |
// check for errors | |
if (www.error == null) | |
{ | |
Debug.Log("WWW Ok! Email sent through Web API: " + www.text); | |
} else { | |
Debug.Log("WWW Error: "+ www.error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment