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 /
avatar image
0
Question by juhainamtc · Dec 16, 2018 at 11:33 AM · email

Send email with Unity

Hi. I am using Unity 5.6.1f1 and I want ot send an email from unity on the Click of a button, I do not have any email form to be filled in, the message body and Subject are aall hard coded. I am unable toi send the email. I have tried several times, also changed player settings APi to 2.0. I get the error IOException Connection closed when I use Send(mail)n method, but with SendAsync I dont get that message but the email is not sent to the recepient email. this is my script which I have attached to an ampty game object and then assigned that game object to a a button in the scene and selected the function name of the script for the Onclick event of the button.I get the message "Sending Email..."in my console but no email is sent.

         public void SendMail()
 {


     MailMessage mail = new MailMessage();

     mail.From = new MailAddress("sender@gmail.com");
     mail.To.Add("receiver@mtc.edu.om");
     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("sender@gmail.com", "senderpassword") as ICredentialsByHost;
     smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
     smtpServer.EnableSsl = true;
     ServicePointManager.ServerCertificateValidationCallback =
       delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
       { return true; };
     smtpServer.SendCompleted += new SendCompletedEventHandler(MailDeliveryComplete);
     smtpServer.Send(mail);
     Debug.Log("success");
 }

 static void MailDeliveryComplete(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     Console.Write("Message \"{0}\".", e.UserState);

     if (e.Error != null)
         Console.WriteLine("Error sending email.");
     else if (e.Cancelled)
         Console.WriteLine("Sending of email cancelled.");
     else
         Console.WriteLine("Message sent.");
 }
 }


If I use port 587 Unity freezes. I have tried the SMTP server and port for yahoo mail also, and get the same error. Please help.

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 RobAnthem · Dec 16, 2018 at 03:05 PM 0
Share

This is not a Unity problem, Unity's managed environment has no control over .NET frameworks, this is a .NET question and sorry but I don't know the answer to why it freezes. You should ask on Stackoverflow.

Although don't forget to dispose of your mail object when finished.

avatar image juhainamtc · Dec 17, 2018 at 03:51 AM 0
Share

@RobAnthem thanks for your reply. I am new to unity and still developing my program$$anonymous$$g skills. COuld oyu please xplain what you mean by dispose the mail object?

avatar image SunnyChow · Dec 17, 2018 at 05:45 AM 0
Share

out of topic, i hear that if you use your computer as server to send email. There is a huge chance your email will be counted as spam

3 Replies

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

Answer by juhainamtc · Dec 19, 2018 at 04:08 AM

Ok so I have found a solution to it through this link: https://www.emailarchitect.net/easendmail/ex/c/7.aspx#c-send-email-using-queue-service-example

and https://www.emailarchitect.net/easendmail/kb/csharp.aspx#send-email-in-a-simple-c-project-using-smtp-protocol (this has the script for sending the email)

the first link guides you through the steps. Finally I am able to send emails without any issues! I have replaced the emailarchitect.net in the script in links above with gmail.com wherever required: oMail.From = "senderemail@gmail.com"; SmtpServer oServer = new SmtpServer("smtp.gmail.com"); oServer.User = "senderemail@gmail.com"; Just make sure to change the gmail settings to allow less secure apps and also to enable access .

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 juhainamtc · Dec 19, 2018 at 05:21 AM 0
Share

also, Add the EASend$$anonymous$$ail20.dll and SecurityInterface.dll into your project for the script to work fine.

avatar image
2

Answer by sushanta1991 · Oct 07, 2021 at 06:28 AM

Check this solution, It is working fine with unity 2021.

https://sushanta1991.blogspot.com/2021/10/how-to-send-email-from-unity-using.html

Comment
Add comment · Show 2 · 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 ChisaiDev · Oct 20, 2021 at 10:32 AM 0
Share

There seems to be an error when i change the values. Im getting the message: SendMessage has no receiver!

avatar image ChisaiDev ChisaiDev · Oct 19, 2021 at 05:01 PM 1
Share

Issue is fixed i had to disable 2nd step security in Gmail first

avatar image
1

Answer by codemaker2015 · Dec 21, 2021 at 03:08 PM

There is a demo application created for sending mail from Unity3D. Checkout the following git repo.

https://github.com/codemaker2015/vmailer

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

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

Related Questions

Sending a string via email from Unity? 2 Answers

Is there any way to change my email address attached to my Unity Answers account? 0 Answers

How to avoid Unity from reloading the game when completing a share function from android? 0 Answers

How can i talk to a person on the asset store? 1 Answer

Emailing from within Unity iPhone or Android 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