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 26, 2018 at 05:25 AM · androidemail

unable to send email from android device

Hello friends. I am desperate for an answer please

I am using a lenovo headset to send emails. it works on android. The email is sent from my editor but not from the headset. her is my code. I have tried ti change the label text and see, the code seems to work until the code for setting the email address.

What do you think may be going wrong after this point.

using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; //using System.Net; //using System.Net.Mail; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using UnityEngine; using EASendMail; using System.Text; using UnityEngine.SceneManagement; using UnityEngine.UI;

public class mailme : MonoBehaviour {

 SmtpMail oMail = new SmtpMail("TryIt");
 SmtpClient oSmtp = new SmtpClient();
 private string mtcid;
 private string mtclevel;
 private string mailscore;
 private Text vtitle;
 Dropdown m_Dropdown;
 string m_level;
 int m_DropdownValue;
 public Text labeltext;
   


 public void SendMail()
 {
     if ((GameObject.Find("InputField").GetComponent<InputField>().text == "") || (GameObject.FindGameObjectWithTag("dropdown").GetComponentInChildren<Dropdown>().value == 0))
     {
         Debug.Log("Enter MTC ID");

         labeltext.text = "Enter ID and Level!";

     }
     else if (GameObject.FindGameObjectWithTag("dropdown").GetComponentInChildren<Dropdown>().value == 0)
     {
         labeltext.text = "Enter ID and Level!";
         Debug.Log("Select a level");
     }
     else
     {
         m_Dropdown = GameObject.FindGameObjectWithTag("dropdown").GetComponentInChildren<Dropdown>();
         Debug.Log("Starting Dropdown Value : " + m_Dropdown.value);
         m_DropdownValue = m_Dropdown.value;
         m_level = m_Dropdown.options[m_DropdownValue].text;
         Debug.Log(m_level);
         mtcid = GameObject.Find("InputField").GetComponent<InputField>().text;
         //  mtclevel = GameObject.Find("KeyboardPanel").GetComponentInChildren<Dropdown>().options[index].text.ToString();
         mtclevel = m_level;
         mailscore = GameObject.Find("Textscore").GetComponent<Text>().text.ToString();
         vtitle = GameObject.Find("VidTitle").GetComponent<Text>();
         Debug.Log(vtitle.text);
     **//The code works in headset until this comment below
        //labeltext.text = "Check3";**
     // Set sender email address, please change it to yours
        oMail.From = "sender@gmail.com";
     // Set recipient email address, please change it to yours
        oMail.To = "receiver@abc.com";
     // Set email subject
        oMail.Subject = "LRC VR Video Result for MTC ID " + mtcid;
       
         // Set email body
         oMail.TextBody = "Hi, \n Please find the Score of the VR Video for user with MTC ID " + mtcid + " below:\n\n Video Title: " + vtitle.text + "\n\nMTC ID: " + mtcid + "\nLEVEL: " + mtclevel + "\n" + mailscore;
    
     // Your SMTP server address
     SmtpServer oServer = new SmtpServer("smtp.gmail.com");
     
     // User and password for ESMTP authentication, if your server doesn't require
     // User authentication, please remove the following codes.
     oServer.User = "sender@gmail.com";
         oServer.Password = "password";

     // If your smtp server requires TLS connection, please add this line
         oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
         oServer.Port = 465;
         oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

     try
     {
         Console.WriteLine("start to send email ...");
         oSmtp.SendMail(oServer, oMail);
         Debug.Log("email was sent successfully!");

         SceneManager.LoadScene("SelectLevel");

     }
     catch (Exception ep)
     {
         labeltext.text = "Failed!";
         Console.WriteLine("failed to send email with the following error:");
         Console.WriteLine(ep.Message);
         SceneManager.LoadScene("SelectLevel");
     }

 }


} }

Comment
Add comment
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

2 Replies

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

Answer by juhainamtc · Jan 10, 2019 at 06:55 AM

Finally it works! So I removed all references to the EASendMail form my project and replaced the code with the code to use what .Net has to provide and the mail is being sent from my VR headset. using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Net; using System.Net.Mail; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using UnityEngine; using System.Text; using UnityEngine.SceneManagement; using UnityEngine.UI;

public class mailme : MonoBehaviour { private string mtcid; private string mtclevel; private string mailscore; private Text vtitle; Dropdown m_Dropdown; string m_level; int m_DropdownValue; public Text labeltext;

 public void SendMail()
 {



     if ((GameObject.Find("InputField").GetComponent<InputField>().text == "") || (GameObject.FindGameObjectWithTag("dropdown").GetComponentInChildren<Dropdown>().value == 0))
     {
         Debug.Log("Enter MTC ID");

         labeltext.text = "Enter ID and Level!";

     }
     else if (GameObject.FindGameObjectWithTag("dropdown").GetComponentInChildren<Dropdown>().value == 0)
     {
         labeltext.text = "Enter ID and Level!";
         Debug.Log("Select a level");
     }
     else
     {
         m_Dropdown = GameObject.FindGameObjectWithTag("dropdown").GetComponentInChildren<Dropdown>();
         Debug.Log("Starting Dropdown Value : " + m_Dropdown.value);
         m_DropdownValue = m_Dropdown.value;
         m_level = m_Dropdown.options[m_DropdownValue].text;
         Debug.Log(m_level);
         mtcid = GameObject.Find("InputField").GetComponent<InputField>().text;
         mtclevel = m_level;
         mailscore = GameObject.Find("Textscore").GetComponent<Text>().text.ToString();
         vtitle = GameObject.Find("VidTitle").GetComponent<Text>();
         Debug.Log(vtitle.text);
         var smtp = new SmtpClient()
         {
             Host = "mail.mtc.edu.om",
             Port = 25,
             EnableSsl = false,
             DeliveryMethod = SmtpDeliveryMethod.Network
         };

         var credentials = new NetworkCredential();

         smtp.UseDefaultCredentials = false;
         smtp.Credentials = credentials;
         var from = new MailAddress("senderemail", "Sendernametoappear");
         var to = new MailAddress("receiveremail", "Receivername");
         var msg = new MailMessage(from, to)
         {
             Subject = "LRC VR Video Result for MTC ID " + mtcid,
             Body = "Hi, <br> Please find the Score of the VR Video for user with MTC ID<b> " + mtcid + " </b>below:<br/><br/><b> Video Title:</b> " + vtitle.text + "<br><b>MTC ID: </b>" + mtcid + "<br><b>Level:</b> " + mtclevel + "<br><h1><font color='red'>" + mailscore +"</font></h1>",
             IsBodyHtml = true,
             Priority = MailPriority.Normal
         };

         smtp.Send(msg);
         SceneManager.LoadScene("SelectLevel");
     }
 }

}

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

Answer by Sabre-Runner · Jan 06, 2019 at 05:59 AM

First of all, you do a lot of object finds. That is a very expensive operation that can be handled at start up or simply by setting references in the inspector.

Secondly, check out Native Share. It does most of the work for you.

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 juhainamtc · Jan 07, 2019 at 04:45 AM 0
Share

thanks. but I am looking for a solution to my problem of sending email which contains text body.

avatar image Sabre-Runner juhainamtc · Jan 07, 2019 at 07:47 AM 0
Share

It's what it does. Did you try it?

avatar image juhainamtc Sabre-Runner · Jan 08, 2019 at 04:27 AM 0
Share

I have just imported it. but honestly i did not understand how to use it. if you have used this,m then pls let me know how it works. Do I have to change my script? or will my script work now with this?

Show more comments

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

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

HTML Email Android 1 Answer

Sending email with Smtp client not working on Android 0 Answers

Send email works in Editor, not on tablet 2 Answers

Unity Android Streaming Assets Save/Recall w/ WWW class? 0 Answers

Application.OpenURL for email on mobile 4 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