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
0
Question by kUr4m4 · Jan 10, 2014 at 10:56 AM · androidbugmail

Sending email from within Unity using smtp service

Hi am trying to send an email from inside unity on smartphones using the SmtpClient class. I have achieved this quite simple task on iOS but the exact same code does not work on android. Here's the code:

 private IEnumerator sendAutoMail (string textBody,string title)
         {
                 MailMessage mail = new MailMessage();
 
                 mail.From = new MailAddress(sender);
                 mail.To.Add(receiver);
                 mail.Subject = "R4UL " + title;
                 mail.Body = textBody;
 
                 Debug.Log("Connecting to SMTP server");
                 SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
                 smtpServer.Port = 587;
                 smtpServer.Credentials = new System.Net.NetworkCredential(sender, password) as ICredentialsByHost;
 
                 smtpServer.EnableSsl = true;
                 ServicePointManager.ServerCertificateValidationCallback = 
                         delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
                 { return true; };
                 Debug.Log("Sending message");
 
                 smtpServer.Send(mail);
 
 
                 yield return null;
         }

where sender, password and receiver are my gmail account, my gmail password and the person I wish to email respectively.

So this works perfectly on iOS but on android throws the following error:

I/Unity ( 6256): SocketException: No such host is known

I/Unity ( 6256): at System.Net.Dns.GetHostByName (System.String hostName) [0 x00000] in :0 I/Unity ( 6256): at System.Net.Dns.GetHostEntry (System.String hostNameOrAdd ress) [0x00000] in :0 I/Unity ( 6256): at System.Net.Dns.GetHostAddresses (System.String hostNameO rAddress) [0x00000] in :0 I/Unity ( 6256): at System.Net.Sockets.TcpClient.Connect (System.String host name, Int32 port) [0x00000] in :0 I/Unity ( 6256): at System.Net.Sockets.TcpClient..ctor (System.String hostna me, Int32 port) [0x00000] in :0 I/Unity ( 6256): at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail .MailMessage message) [0x00000] in :0 I/Unity ( 6256): at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMes sage message) [0x00000] in :0 I/Unity ( 6256): Rethrow as SmtpException: Message could not be sent. I/Unity ( 6256): at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMes sage message) [0x00000] in :0 I/Unity ( 6256): at FeedbackSender+c__Iterator1.MoveNext () I have managed to pintpoint the error location at the line: smtpServer.Send(mail); Any ideas as to what might be causing this issue? I have both android and iOS pro versions. Cheers
Comment
Add comment · Show 1
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 MohHeader · Sep 13, 2015 at 05:20 PM 0
Share

Dear, I know this is old,

But can you share your findings, :)

Thanks,

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by DiegoSLTS · Sep 13, 2015 at 06:54 PM

I think I had the same problem some time, make sure your android build asks for Internet Access permission.

Go to Android Player Settings, "Other settings" and look for Internet Access. It's "Auto" by default, set it to "Require".

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 ShenYuan · Dec 16, 2015 at 06:30 AM 0
Share

Solved my problem, thx!

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with Sprites in Android. Maybe a bug? 0 Answers

Probuilder throws ArgumentNullException when Extruding ProBuilder object on Android 0 Answers

SendMail from Android simply doesn't work 0 Answers

SkinnedMeshRenderer and android problem 1 Answer

HEADS UP: Android APK icons blurry and horrible! 1 Answer


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