Send Email From Your Game - Unity3D

Last updated : May 10, 2017

Posted by: Neel Gajjar

In your game, it might be possible that user directly wants to send an email to feedback or any suggestions to game support.

For that, there is a simple code implementation,


Attach the SendMailClass script to your active game object & use sendEMailToSingleRecipient() for sending mail to single recipient.

Use sendEMailToMultypleRecipient() to send multiple recipient.

In sendEMailToMultypleRecipient() we are using an array of email id which is a string.


Code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class SendMailClass : MonoBehaviour {


   //recipient's email id

    string email_string = "neelg@bitwiseonline.com";

    //recipient's email id array

    string[] email_string_array = new string[]{"neelg@bitwiseonline.com","ankitd@bitwiseonline.com"};

    //email subject

    string subject_string = "Your subject text";

    //email body

    string body_string = "Your body text";


   //for sending mail to single recipient

    public void sendEMailToSingleRecipient(){        

       string email = email_string;

        string subject = EscapeURLFunction(subject_string);

        string body = EscapeURLFunction(body_string);

        //Open the native default app

        Application.OpenURL ("mailto:" + email + "?subject=" + subject + "&body=" + body);

    }


   //for sending mail to multiple recipient

    public void sendEMailToMultypleRecipient(){        

       string email = "";

        foreach (string email_str in email_string_array) {

            email += email_str + ",";

        }

        string subject = EscapeURLFunction(subject_string);

        string body = EscapeURLFunction(body_string);

        //Open the native default app

        Application.OpenURL ("mailto:" + email + "?subject=" + subject + "&body=" + body);

    }


   string EscapeURLFunction (string url){

        return WWW.EscapeURL(url).Replace("+","%20");

    }


   void OnGUI() {

        if (GUI.Button (new Rect (10, 10, 250, 50), "Send mail to single recipient"))

            sendEMailToSingleRecipient ();

        else if (GUI.Button (new Rect (10, 70, 250, 50), "Send mail to multiple recipient"))

            sendEMailToMultypleRecipient ();

    }

}


This code will be useful for Android & iOS game.

Also, see the attachments for APK & Project sample.



Send SMS From Your Game - Unity3D

Send SMS From Your Game - Unity3D

In the game, you can use "prefer the game" feature or invite the friend(s) who...
Send Email From Your Game - Unity3D

Send Email From Your Game - Unity3D

In your game, it might be possible that user directly wants to send an email to...
Reduce a size of APK and IPA – Unity 3d

Reduce a size of APK and IPA – Unity 3d

For reducing APK size:In Unity 5.6.0f3 I have created a simple "Hello world"...
Unity3D vs. Cocos2DX

Unity3D vs. Cocos2DX

License: Unity 3D is paid while Cocos2DX is an open-source game...
You will be amazed to know that these 5 games are developed with Unity 3D

You will be amazed to know that these 5 games are developed with Unity 3D

1. Pokémon GODeveloped & published by Niantic; when both Niantic &...
Integrate Banner Ad for iOS & Android using AdMob

Integrate Banner Ad for iOS & Android using AdMob

Requirements- Unity 4 or higher- To deploy on iOS     ...
Integrate Interstitial Ad for iOS & Android using AdMob

Integrate Interstitial Ad for iOS & Android using AdMob

Requirements- Unity 4 or higher- To deploy on iOS       -...
Submit a Game to AppStore - For beginners

Submit a Game to AppStore - For beginners

Steps to submit a Game to AppStore1. Switch platform as iOS and then make a...
Use Debug.Break() to pause the editor

Use Debug.Break() to pause the editor

Use Debug.Break() in your code to pause the editorDid you know that you can...
AdMob Rewarded Video

AdMob Rewarded Video

Requirements- Unity 4 or higher- To deploy on iOS       -...