Guides Tutorial

Open Link URL and Send Email from Unity-New Tab

Human
January 22, 2015
0 Comments
Home
Guides
Tutorial
Open Link URL and Send Email from Unity-New Tab

Opening URL and send Email from Unity


Most of game developers want players to see their site,credits,team and portfolio, and want feedback by sending e mails.
Today we are giving some ways to open links URL in unityscr and send email from unity,



URL Open:


if(GUILayout.Button("Visit Web Site"))
{
 Application.OpenURL("https://unity3diy.blogspot.com");
}

Or Create and attach this java script code to any object you want to click,

var links : String = "Paste your links here...";
function OnMouseDown(){
 Application.OpenURL(links);
}



URL Open In New Tab:


Application.ExternalEval("window.open('http://www.google.com','_blank')");


Reference
http://www.w3.org/TR/2004/WD-css3-hyperlinks-20040224/#target-new



Sending email:

void SendEmail ()

    {

    string email = "MY EMAIL ADDRESS";

    string subject = MyEscapeURL("My Subject");

    string body = MyEscapeURL("My Body\r\nFull of non-escaped chars");
     

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

    }  

    string MyEscapeURL (string url)

    {

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

    }



Another C# example

Must check that under player settings Api Compatibility Level is set to ".NET 2.0" and not ".NET 2.0 Subset"
otherwise it doesn't work


         using UnityEngine;
    using System.Collections;

    using System;

    using System.Net;

    using System.Net.Mail;

    using System.Net.Security;

    using System.Security.Cryptography.X509Certificates;

     

    public class mono_gmail : MonoBehaviour {

     

    void Main ()

    {

    MailMessage mail = new MailMessage();

     

    mail.From = new MailAddress("youraddress@gmail.com");

    mail.To.Add("youraddress@gmail.com");

    mail.Subject = "Test Mail";

    mail.Body = "This is for testing SMTP mail from GMAIL";

     

    SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");

    smtpServer.Port = 587;

    smtpServer.Credentials = new System.Net.NetworkCredential("youraddress@gmail.com", "yourpassword") as ICredentialsByHost;

    smtpServer.EnableSsl = true;

    ServicePointManager.ServerCertificateValidationCallback =

    delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

    { return true; };

    smtpServer.Send(mail);

    Debug.Log("success");

     

    }

}






If you like and never wants to miss our articles then just subscribe us,
And join our Facebook group with Lots of great developers.

Blog authors

No comments