Skip to content

Instantly share code, notes, and snippets.

@ReGaSLZR
Last active February 21, 2024 13:39
Show Gist options
  • Save ReGaSLZR/295bdff767544830cc9223af44aaa254 to your computer and use it in GitHub Desktop.
Save ReGaSLZR/295bdff767544830cc9223af44aaa254 to your computer and use it in GitHub Desktop.
(Unity C#) Email Sender (redirects to Email App)
using UnityEngine;
using UnityEngine.Networking;
public class EmailSender : MonoBehaviour
{
public const string USER_SUBJECT = "Email Subject";
public const string USER_RECIPIENT = "receipient_email@gmail.com";
public const string PREFIX_MAIL_TO = "mailto:";
#region Public API
public void SendEmail_UserRequest()
{
var body = EscapeString("Hi there!\n\n " +
"This is a sample email for you.\n\n " +
"Hope you're doing great.\n\n " +
"--------------------------");
Debug.Log($"{GetType().Name}.SendEmail_UserRequest() sending email...", gameObject);
Application.OpenURL(PREFIX_MAIL_TO + USER_RECIPIENT
+ "?subject=" + USER_SUBJECT
+ "&body=" + body);
}
#endregion //Public API
#region Client Impl
private string EscapeString(string URL) =>
UnityWebRequest.EscapeURL(URL).Replace("+", "%20");
#endregion //Client Impl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment