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
1
Question by sdgd · Apr 07, 2013 at 05:04 PM · c#wwwgooglesearchrequest

how to enter another request from www with c#

after 2-3 days struggling I started to go force through wall if I can't do it normal way and at last I'm getting little success

after 2-3 days I stoped thinking this way how to send email with C# as it seems even community doesn't know the answer after 2 days

so I went new approach and YES I did manage to read the page after 12 hours struggling BUT they are all read only Manual how can I make another request than?

with this code:

 using UnityEngine;
 using System.Net;
 using System.Net.Mail;
 using System.Collections;
 
 public class SendEmail : MonoBehaviour {
     UpdateYield WAIT;
     private bool start = true;
     
     string url = "";
     WWW www;
     void Start(){
         // I load the page in to www
         url = "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&hl=en";
         url = "google.com";
         www = new WWW(url);
     }
     void Update () {
         FindWWWF();
         
     }
     private void FindWWWF(){
         // I wait till the loading is done witch must be 1 second and than I have access to the inside
         Debug.Log(""+www.progress);
         if (WAIT.UWaitForSecondsF(www.progress,1)){
             // we do a final check if it's loaded since it can happen we cannot acces the page and progress stays at 0 for 1 second so it could pass in here
             if (www.isDone){
                 Debug.Log(www.text);
             }
         }
     }
 }

allso to note I did my own structure UpdateYield.UWaitForSecondsF if first argument is same than after 1 second it returnes true

I did manage to get this for email:

EDIT: ok I've found I can't write this long question so I'm cutting email debug out

(here was Email Debug.Log)

and for google:

(here was google Debug.Log) - don't understand why does not let me do it correctly

how would I make a simple request from google to search what ever string forward this would give me basic idea how to fill user/password at Email and go through, compose the mail, ... ... ...

and maybe I'll need to learn a cache later but first another request from that site

Comment
Add comment · Show 2
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 Loius · Apr 07, 2013 at 07:30 PM 0
Share

no idea

here's a thing: http://answers.unity3d.com/questions/46752/unity-3-sending-email-with-c.html

avatar image sdgd · Apr 07, 2013 at 07:38 PM 0
Share

yeah I know I've been there and easyer method - Q was a

How To send Email with C# on Unity 3D 4.1.2? that I've been struggling about it for 3 days

today I've went in to www thingy

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by ByteSheep · Apr 07, 2013 at 08:28 PM

If all you want to do is send an email over the web from within unity, then the easiest way to do it is to create a php file that sends an email which you load using the WWW class.
This may not be the usual way to do it (not sure if there is a C# function to handle this in unity), but it works quite well.

http://www.leedsmusicscene.net78.net/webplayer/SendEmail/SendEmail.html

This is something i threw together as an example.. To and From parameters are the sender and receiver email address, while Title and Body are the title and main text of the email.

To do this simply:

Attach this script to a game object in unity:

 var mygui : GUIText;
 
 var from : String = "Your Email";
 var to : String = "Receivers Email";
 var title : String = "Title";
 var body : String = "Body";
 var pword : String = "send"; //a simple security meassure
 
 function OnGUI () {
 
   GUILayout.BeginArea (Rect (Screen.width/2-60, Screen.height/2 - 80, 120, 160));
 
   GUILayout.BeginHorizontal ();
 
     //Rect(Screen.width/2 - 50, Screen.height/2 - 20,100,40),
       if (GUILayout.Button("Send Email"))
       {
         sendEmail();
       }
   
   GUILayout.EndHorizontal ();
   GUILayout.BeginHorizontal ();
   
     from = GUILayout.TextField (from);
     
   GUILayout.EndHorizontal ();
   GUILayout.BeginHorizontal ();
   
     to = GUILayout.TextField (to);
     
   GUILayout.EndHorizontal ();
   GUILayout.BeginHorizontal ();
   
     title = GUILayout.TextField (title);
     
   GUILayout.EndHorizontal ();
   GUILayout.BeginHorizontal ();
   
     body = GUILayout.TextField (body);
     
   GUILayout.EndHorizontal ();
   GUILayout.EndArea ();
 
 }
  
 function sendEmail() {
  
     Debug.Log("Send Email!");

     //edit the url value to your php files location on your server
     var url = "http://www.yourdomain.com/yourdirectory/yourfilename.php?to="+to+"&from="+from+"&title="+title+"&body="+body+"&pword="+pword;
     
     Debug.Log("Url: "+url);
 
     // Post the URL to the site and create a download object to get the result.
     var email_send = WWW(url);
     yield email_send; // Wait until the download is done
     if(email_send.error) {
         print("There was an error sending the email: " + email_send.error);
         mygui.text = "Error: " + email_send.error;
     }
     else
     {
        mygui.text = "Email Sent!";
     }
 }


And then create a .php file with this code:

 <?php
 
 if(isset($_GET['pword']))
 {
 
   if($_GET['pword'] == "send")
   {
     if(isset($_GET['to']) && isset($_GET['from']) && isset($_GET['title']) && isset($_GET['body']))
     {
       mail("".$_GET['to']."", "".$_GET['title']."", "".$_GET['body']."", "FROM: ".$_GET['from']."");
     }
   }
   else
   {
     echo("<p>Wrong or invalid password!</p>");
   }
 
 }
 
 
 ?>


If you need a more detailed explanation of how it works just let me know ;)
The first script is in javascript but you should be able to easily convert it to C# if you need to.. PS you will need a server to host the php file.

Comment
Add comment · Show 12 · 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 sdgd · Apr 07, 2013 at 08:46 PM 0
Share

ok first of all I don't know how to read write JS so I just copied your code and put it inside uJS

don't even know what do do with php code. I've made a new .php file in same assets folder used a force to write inside it and pasted your code

but I get millions of errors for java:

 Assets/JSSendEmail.js(56,9): BCE0005: $$anonymous$$ identifier: 'email_send'.


 Assets/JSSendEmail.js(57,15): BCE0005: $$anonymous$$ identifier: 'email_send'.


 Assets/JSSendEmail.js(58,12): BCE0005: $$anonymous$$ identifier: 'email_send'.


 Assets/JSSendEmail.js(59,58): BCE0005: $$anonymous$$ identifier: 'email_send'.


 Assets/JSSendEmail.js(60,34): BCE0005: $$anonymous$$ identifier: 'email_send'.


I'm sorry I know you've tried your best but when I see java my brain just fizzles and I get totally confused in labyrinth

I'll be looking for hours what's going on for errors or what's missing, ...

  • I don't even understand www or mail system in scripting so this is all a totally new field of view for me and I'm totally confused

I don't have a server that's the point why I went in to Gmail

otherwise I'd go trying to make my own email thingy witch I saw

and yes if you look in to my 2 questions that are linking to each other yes I do need a detailed explanation for this

avatar image ByteSheep · Apr 07, 2013 at 08:54 PM 1
Share

Ok I updated the code, that should have fixed it. There was a missing 'var' before email_send.
Don't worry about the js too much for now, it will be easy to convert once you have got it setup..
The php file however is not meant to be inside of unity - It is a webpage file (like a html file) and must be put on a server.
If you don't have a website where you can upload your file to, then you might want to consider creating a free domain (e.g. from http://www.000webhost.com/)

avatar image ByteSheep · Apr 07, 2013 at 09:25 PM 1
Share

Ok just to be sure, what you are trying to do is simply send an email right?

The web player example i posted above (http://www.leedsmusicscene.net78.net/webplayer/SendEmail/SendEmail.html) is a good option if you want to be able to retrieve your emails from your inbox.
The limitations are that you cannot retrieve your email account inbox with this code (so you won't be able to get emails in your email account).
So do you need the ability to check your inbox aswell or will being able to send an email be enough?

avatar image ByteSheep · Apr 07, 2013 at 09:39 PM 1
Share

Ok here is my project so you can test it. SendEmail.zip

I guess I will research how to connect to gmail or other ways to send an email..

sendemail.zip (98.5 kB)
avatar image ByteSheep · Apr 07, 2013 at 10:49 PM 1
Share

This finally worked for me: (adapted from http://stackoverflow.com/questions/4148019/authentication-or-decryption-has-failed-when-sending-mail-to-gmail-using-ssl)

 using UnityEngine;
 using System.Collections;
 using System;
 using System.Net;
 using System.Net.$$anonymous$$ail;
 using System.Net.Security;
 using System.Security.Cryptography.X509Certificates;
 
 public class mono_gmail : $$anonymous$$onoBehaviour {
 
         void $$anonymous$$ain ()
         {
             $$anonymous$$ail$$anonymous$$essage mail = new $$anonymous$$ail$$anonymous$$essage();
 
             mail.From = new $$anonymous$$ailAddress("youraddress@gmail.com");
             mail.To.Add("youraddress@gmail.com");
             mail.Subject = "Test $$anonymous$$ail";
             mail.Body = "This is for testing S$$anonymous$$TP mail from G$$anonymous$$AIL";
 
             SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
             smtpServer.Port = 587;
             smtpServer.Credentials = new System.Net.NetworkCredential("youraddress@gmail.com", "yourpassword") as ICredentialsByHost;
             smtpServer.EnableSsl = true;
             ServicePoint$$anonymous$$anager.ServerCertificateValidationCallback = 
                 delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
                     { return true; };
             smtpServer.Send(mail);
             Debug.Log("success");
         
         }
 }

This will send an email to a gmail account. Create a c# file in unity and name it 'mono_gmail'.
Don't forget to replace the email address with your own and of course add your password :) This solution uses smtp sockets whereas the answer I gave above works using a http request with Get/Post data.

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

13 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

Related Questions

Help searching google! 1 Answer

How to get specific data from CURL in unity 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Post Reqest with dictionary 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