- Home /
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<mpl=default<mplcache=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? that I've been struggling about it for 3 days
today I've went in to www thingy
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.
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
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/)
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?
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..
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.
Your answer
Follow this Question
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