Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by UltraTechX · Aug 23, 2015 at 11:19 PM · c#unity 5issuesemail

how to send an email in unity C#

so, i looked around for a proper c# emailing script, it just needs to send text. And i could not find anything that sent the email, i am now stuck with this code:

 using System;
 using UnityEngine;
 using System.Net;
 using System.Net.Mail;
 using System.Net.Security;
 using System.Security.Cryptography.X509Certificates;
 
 
     public class mono_gmail : MonoBehaviour
     {
         public static void Main (string[] args)
         {
             MailMessage mail = new MailMessage();
             
             mail.From = new MailAddress("email@gmail.com");
             mail.To.Add("email@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 = 465;
             smtpServer.Credentials = new System.Net.NetworkCredential("email@gmail.com", "password");
             smtpServer.EnableSsl = true;
             ServicePointManager.ServerCertificateValidationCallback = 
                 delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
             { return true; };
             smtpServer.Send(mail);
         }
     }
 


also, the email and password fields are filled in, but just not here for security purposes.

And i did the 465 port since that is the outgoing mail server port for ssl.

PS : nothing is printing errors either.

I hope you can help, thanks!

Comment
Add comment · Show 7
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 Umresh · Aug 24, 2015 at 06:47 AM 0
Share

You can try this

avatar image Andres-Fernandez · Aug 24, 2015 at 09:48 AM 0
Share

Duplicated question. Check here (or just google "unity send email smtp").

avatar image UltraTechX · Aug 24, 2015 at 01:57 PM 0
Share

@Umresh nothing happens when it runs, im not exactly sure what is supposed to happen when sendmail is called, but i know it runs.

avatar image UltraTechX · Aug 24, 2015 at 02:01 PM 0
Share

@Andres Fernandez I tried that solution, and it definitely runs, but gives me this error :

SmtpException: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 b47sm11270994qge.44 - gsmtp System.Net.$$anonymous$$ail.SmtpClient.Authenticate (System.String Username, System.String Password) System.Net.$$anonymous$$ail.SmtpClient.Authenticate () System.Net.$$anonymous$$ail.SmtpClient.SendCore (System.Net.$$anonymous$$ail.$$anonymous$$ail$$anonymous$$essage message) System.Net.$$anonymous$$ail.SmtpClient.SendInternal (System.Net.$$anonymous$$ail.$$anonymous$$ail$$anonymous$$essage message) System.Net.$$anonymous$$ail.SmtpClient.Send (System.Net.$$anonymous$$ail.$$anonymous$$ail$$anonymous$$essage message)

avatar image Andres-Fernandez · Aug 25, 2015 at 06:34 AM 0
Share

From the exception, it looks like the client doesn't accept either the name or the password. I'm sorry, but other than that I can't help any further (I've only sent mail from unity within android apps).

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NeverHopeless · Aug 25, 2015 at 06:53 AM

I faced these error while sending email from gmail, try sending by changing these two parameters:

          smtpServer.Port = 587;
          smtpServer.EnableSsl = true; // try toggling this value as well

and make sure the credentials are correct there shouldn't be any encryption to the data when passing to smtp object.

Also, wrap your code in try-catch block to catch the exception message.

Comment
Add comment · Show 3 · 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 UltraTechX · Aug 28, 2015 at 05:25 PM 0
Share

@NeverHopeless thanks for the response, it is the exact same code as the two lines inside it, but toggling EnambleSsl gives me this error :

$$anonymous$$ust issue a STARTTLS command first.

avatar image Yuriy-Ivanov UltraTechX · Jun 18, 2017 at 07:06 PM 0
Share

Hi @UltraTechX ,

Unfortunately, Unity uses an outdated and buggy $$anonymous$$ono 2.0 SmtpClient, which doesn't fully support STARTTLS protocol used my many modern S$$anonymous$$TP servers. We've recently published a new asset UT$$anonymous$$ail - Email Composition and Sending Plugin, which doesn't have that issue and so works well with most S$$anonymous$$TP servers (we've tested it with number of popular ones, including Gmail). It also allows not only directly sending emails with S$$anonymous$$TP, but also composing emails using a system email client, with a content defined by your app. It works on multiple platforms and supports attachments and HT$$anonymous$$L / text messages.

Best regards,

Yuriy, Universal Tools $$anonymous$$m.

avatar image clarHandsome · Aug 06, 2018 at 03:26 PM 0
Share

What if google doesn't let me sign in? @NeverHopeless

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

32 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 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

UNET: Network.isServer/isClient = False; PeerType = Disconnected but accepting connections? 0 Answers

[Android] how can I access picture in sdcard ? 0 Answers

Turning Off Tag After Collision 0 Answers

how can i control scale speed ? 1 Answer

list.contains problem 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