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
3
Question by Alayna · Feb 12, 2013 at 03:55 PM · editordllstandaloneemail

Sending Email From Unity Works In Editor, Not In Standalone?

Hello Everyone, I have been trying my hand at sending simple emails out from Unity. The account doing the sending would be a dummy account that is just used for sending maybe one email a day from Unity and nothing else, so security isn't a huge issue for me. This script works fine and is an amalgamation of other scripts found on here and the forums(with contact info taken out of course).

   using UnityEngine;
     using System.Net.Mail;
     using System.Net;
     
  
 
 public class SendEmail : MonoBehaviour {
 
 
     private MailMessage message;
 
  
 
     // ########################
 
     void Update()
 
     {
 
         //send your mail just typing space
 
         if (Input.GetKeyDown(KeyCode.Space))
 
         {
 
             SendMail();
 
         }
 
     }
 
     // ########################
 
     private void SendMail()
 
     {
 
        
 
         message = new MailMessage();
 
         message.To.Add("EmailAddressToGoTo");
        
 
         message.Subject = "SubjectTitle";
 
         message.Body = "Message test:<br>Test Message";
 
         message.IsBodyHtml = true;
 
 message.Attachments.Add(new Attachment("something.jpg"));
 
 
         message.From = new MailAddress("EmailAddress", "SenderName");
 
  
 
         SmtpClient smtp = new SmtpClient("smtp.mail.yahoo.com", 587);
 
         smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 
  
 
         //If you dont need authentication, just leave the next fields
 
         // =========================================================
 
         // Enable Secure Socket Layer (SSL) for connection encryption
 
         smtp.EnableSsl = false;
 
         // Do not send the DefaultCredentials with requests
 
         smtp.UseDefaultCredentials = false;
 
         // Create a System.Net.NetworkCredential object and set
 
         // the username and password required by your SMTP account
 
         smtp.Credentials = new NetworkCredential("username", "password") as ICredentialsByHost;
 
         smtp.Timeout = 20000;
 
         // =========================================================
 
  
 
         smtp.Send(message);
 
         Debug.Log("Mail sent");
 
     }
 
 }

Now, as I said, everything works great in the editor (though for some reason trying to use anything other than a yahoo account with Ssl on always gives me a cant find certificate error). When I try to go into standalone it doesnt send an email at all, Ive tried to comment out the attachment part just in case it was looking for an image that wasn't in the correct place, but it still isn't getting anything through.

I looked around a bit and I think it's to do with a missing DLL that is in the editor but not included in the built standalone. However I dont know which DLL includes system.net.mail or where to put it even if I had the file.

Some help would be greatly appreciated!

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 Tomleung · Jan 07, 2015 at 01:24 PM 0
Share

Hi! When I tried to use your codes in my demo project. I got this error:

SmtpException: 530 5.7.1 Authentication required 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)

Do you know how to fix it? Thank you!

2 Replies

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

Answer by Alayna · Feb 12, 2013 at 06:04 PM

I found out I had to set Api Compatibility Level to ".NET 2.0" instead of ".NET 2.0 Subset" under player settings. Now everything is working great! Such a strange thing to have to change, hope someone else can be helped by this as well.

Comment
Add comment · Show 4 · 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 luis_cristovao · Jun 16, 2017 at 05:10 PM 0
Share

Thank you, for your answer, it works perfectly!

avatar image Andergraw · Jun 22, 2018 at 03:52 PM 0
Share

O$$anonymous$$G thank you SO $$anonymous$$UCH!

avatar image NarkoCat · Aug 08, 2018 at 05:30 PM 0
Share

This answer was the the thing I was looking for. Thank you.

avatar image datoneguy246 · Oct 29, 2019 at 07:13 PM 0
Share

Thank you so much, I would have never found this out on my own.

avatar image
0

Answer by Dave-Carlile · Feb 12, 2013 at 04:07 PM

There should be a log file in the *_Data folder of your game. This might display error messages that will indicate what's going on.

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 Alayna · Feb 12, 2013 at 04:27 PM 0
Share

It's giving me this error every time I try "SmtpException: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html" I had this for a bit before I got it working in editor, but it was because I had accidentally typed the email wrong, but I checked right before I built it and it was fine. Is there some extra step that standalone requires for authentication?

avatar image Dave-Carlile · Feb 12, 2013 at 04:35 PM 0
Share

Odd. Sounds like something Yahoo doesn't like about the request. Not sure why it would be different standalone vs. in the editor. Probably not something really realted to Unity. I would suggest searching for that error along with System.Net.$$anonymous$$ail. There's probably just some configuration missing somewhere.

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

15 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

Related Questions

Why does Assembly-CSharp reference UnityEditor.dll 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Works in the editor, but not when I publish it.. what's wrong..? 0 Answers

How to edit a enumerator in the editor? 2 Answers

How do I reference variables from one editor script in another 0 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