Skip to content

Instantly share code, notes, and snippets.

@heitortsergent
Last active December 28, 2015 01:39
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/7421779 to your computer and use it in GitHub Desktop.
Save heitortsergent/7421779 to your computer and use it in GitHub Desktop.
Sendgrid - Unity Email via SMTP
MailMessage mail = new MailMessage();
mail.From = new MailAddress(fromEmail);
mail.To.Add(toEmail);
mail.Subject = subject;
mail.Body = body;
mail.Headers.Add("X-SMTPAPI", xsmtpapiJSON);
SmtpClient smtpServer = new SmtpClient("smtp.sendgrid.net");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(api_user, api_key) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
Debug.Log("Success, email sent through SMTP!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment