Send Email From Your Unity Game

Send Email From Your Unity Game

There’s a huge opportunity for email games, as I wrote in a previous post. There’s also a need for email within games. Unity is a popular tool for publishing multi-platform games. But what about sending email from Unity? I decided to share how I did this with SendGrid.

When you’re developing in Unity you can use either C#, Javascript, or Boo. I’m going to show an example using C# to send email through SMTP using SendGrid’s SMTP API and by making a simple HTTP request using the Web API.

First, to send using SMTP is really simple. You can use the System.Net.Mail library to use the MailMessage and SmtpClient classes:

As with SMTP, using the SMTP API with the Web API only takes one line:url += "&amp;x-smtpapi=" + xsmtpapiJSON;

I created a sample project with two buttons, clicking one them will send an email either using SMTP, or the Web API.

One way to make use of email inside your game could be, for example, tracking how much time the user spends playing with a character, and sending him an email with a desktop screenshot of it. Or sending an email with a nice screenshot the moment the player gets an achievement.