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

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

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?][1] that I've been struggling about it for 3 days today I've went in to www thingy [1]: http://answers.unity3d.com/questions/433283/how-to-send-email-with-c.html

1 Answer

1

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 :wink:
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.

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/)

hmmmmm, ... and if I'd want to ask google through script anything? (witch fits this question?) Do I understand correctly with this way I'm creating my own Email system like Gmail system?

I have never tried passing information to and from google, but i will have a look into it. I understand why you don't want to change your code after having worked on it, but if all else fails the method above is really pretty simple to implement..

no actually for this thing I've done a totally new project send email in witchone I'm experimenting this stuff atm I have only camera and 4 scripts - php - java - C# mine provided at the top and in other Q there's another functon inside it - and my updateyield structure I actually haven't worked on my code too much if I'll understand what's going on I can write it in 5 min on my own but to get it working I've used 12 hours huh :( and yeah after 3 days I started thinking why can't I go force through so I started thinking how to pass info to google, ... ... witch fits this Q

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?