Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
13
Question by ina · Apr 30, 2011 at 05:05 AM · androidmobileiphonenativeemail

Application.OpenURL for email on mobile

Does Application.OpenURL("mailto:address@domain.com") work for popping up a native email prompt on mobile? doco


It's well worth noting that if you just want to send a very simple one with NO dynamic text, no body, no unusual characters, just replace the spaces with %20 manually like so:

 public void LinkHelpEMAIL()
  {
  string t =
  "mailto:blah@blah.com?subject=Question%20on%20Awesome%20Game";
  Application.OpenURL(t);
  }

exactly like that (do not escape the at symbol). saves typing, tested on both.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Dec 04, 2013 at 06:32 PM 0
Share

much related: http://answers.unity3d.com/questions/358635/how-do-i-send-an-email-on-ios-using-applicationope.html

avatar image maria-dev · Oct 14, 2014 at 03:01 PM 2
Share

@ina This can also help you > Opening URL and send Email from Unity

avatar image Voxel-Busters · Aug 12, 2015 at 09:41 AM 0
Share

For complex actions, Cross Platform Native Plugins allows option to send nicely formatted HT$$anonymous$$L body and attachments. This plugin is free to use and supports iOS and Android.

4 Replies

· Add your reply
  • Sort: 
avatar image
35
Best Answer

Answer by cregox · Dec 04, 2013 at 06:42 PM

I'll just organize in one post what's already written around...

Yes, it does work! But it has to be sanitized or else it will crash silently.

 void SendEmail ()
 {
  string email = "me@example.com";
  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");
 }

This works both on iOS and Android.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 27, 2014 at 02:36 PM 0
Share

(PS I "think" you can also use Uri.EscapeDataString(body); .. not sure)

avatar image Ali-hatem · Nov 19, 2015 at 09:55 AM 0
Share

PS : you can leav string email = ""; empty and the user will decide later

avatar image sudhir_kotila · Aug 12, 2016 at 11:43 AM 0
Share

Thank you.

It is working for Android and iOS both.

avatar image quizcanners · Oct 24, 2018 at 11:09 AM 0
Share

In case someone wants to make function as tiny as possible:

   public static void SendEmail(string email, string subject, string body) =>
         Application.OpenURL("mailto:{0}?subject={1}&body={2}".F(email, subject.$$anonymous$$yEscapeURL(), body.$$anonymous$$yEscapeURL()));
         
         static string $$anonymous$$yEscapeURL(this string url) => UnityWebRequest.EscapeURL(url).Replace("+", "%20");

And then you can call it like

 ExternalCommunication.SendEmail("somebody@gmail.com", "About stuff", 
             "Something to talk about"); 
avatar image Conferno · May 31, 2019 at 06:02 PM 0
Share

2019: It seems it doesn't work on the latest unity 2019 1 4 1 Have tried on iOS and Android. The xcode log writes Filtering mail sheet accounts for bundle ID: com.xxx.xxx, source account management: 1 2019-05-31 20:56:42.158166+0300 appname[3637:1425152] [$$anonymous$$ailShare] can send mail: 1 mail send

And nothing happend

avatar image
1

Answer by David · May 06, 2011 at 05:14 PM

Note, this explanatory example code, does not literally work, as you must escape certain strings. Teaching code only.


Yes. Using Application.OpenURL() you could open safari, maps, phone, sms, mail, youtube, itunes, app store and books store. You could find all the url schemes you could need here These are for Objective-C but if you get the idea of the url scheme it would be really easy to do it on Unity. Here you have an example of a simple script to send a mail with address, subject and body.

C# mail example:

  public string email;
 public string subject;
 public string body;
 // Use this for initialisation .. EXAMPLE ONLY, DOES NOT WORK
 void Start () {
     Application.OpenURL("mailto:" + email + "?subject:" + subject + "&body:" + body);
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Waz · Jun 03, 2012 at 11:33 PM 0
Share

There is nothing iPhone-specific about these schemes. They work fine with Android (and web, and standalone).

avatar image shinriyo_twitter · Jun 15, 2012 at 12:10 PM 3
Share

hey

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

not :, correct is =

avatar image Bunny83 shinriyo_twitter · Jun 15, 2012 at 12:14 PM 0
Share

It's not a very well written answer and looks even more like it should be a comment to david's answer, but it's correct ;)

avatar image OP_toss shinriyo_twitter · Nov 22, 2013 at 08:00 PM 0
Share

This answer worked for me:

http://answers.unity3d.com/questions/341147/encode-string-to-url-friendly-format.html

Basically you use WWW.EscapeURL, then you replace "+" with "%20". Worked like a charm!

avatar image VamshiKrishnaP · Nov 25, 2014 at 11:29 AM 0
Share

$$anonymous$$y application went to suspend mode.

Once i send the email, native email setup should off! How it is possible to restrict to Go suspend mode ?

avatar image
0

Answer by slake_it · Oct 29, 2015 at 09:55 AM

this is the same code of @cawas created as a class with static functions for easy usage

using UnityEngine;

 /// <summary>
 /// - opens the mail app on android, ios & windows (tested on windows)
 /// </summary>
 public class SendMailCrossPlatform
 {
     


     /// <param name="email"> myMail@something.com</param>
     /// <param name="subject">my subject</param>
     /// <param name="body">my body</param>
     public static void SendEmail (string email,string subject,string body)
     {
         subject = MyEscapeURL(subject);
         body = MyEscapeURL(body);
         Application.OpenURL("mailto:" + email + "?subject=" + subject + "&body=" + body);
     }

     public static string MyEscapeURL (string url)
     {
         return WWW.EscapeURL(url).Replace("+","%20");
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Oct 29, 2015 at 03:11 PM 0
Share

Don't take my word for it, but something about making "static functions for easy usage" rubs me the wrong way and re$$anonymous$$ds me of this: http://etodd.io/2015/09/28/one-weird-trick-better-code/

$$anonymous$$aybe, and just maybe, you rather use the Toolbox pattern design for doing easy to use global access things like this: http://programmers.stackexchange.com/a/218322/4261

I think it's just important to be aware of what static means, what it should be used for and I'm pretty confident using it as globals is not it. That being said, do go ahead and make whatever works! ;P

avatar image
0

Answer by Yuriy-Ivanov · Jun 18, 2017 at 06:56 PM

Please note that there is no reliable way to add any attachments with mailto, you'll have to use underlying platforms email API with native plugins to achieve that.

We've recently published a new asset UTMail - Email Composition and Sending Plugin, which supports composing emails with attachments and also sending them directly with SMTP. It works on multiple platforms and provides a convenient API.

Best regards,

Yuriy, Universal Tools team.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sending Mobile Email via Unity 2 Answers

Optimal # of Faces for many mesh scene for mobile 1 Answer

Help improving performance with 40-80 rigid bodies. 1 Answer

Joystick trouble... 0 Answers

Unity Cloth on Mobile? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges