Skip to content

Instantly share code, notes, and snippets.

@heitortsergent
Created November 11, 2013 22:38
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 heitortsergent/7421803 to your computer and use it in GitHub Desktop.
Save heitortsergent/7421803 to your computer and use it in GitHub Desktop.
Sendgrid - Unity Email using Web API
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