- Home /
Question by
dovelavittoria · Jul 06, 2017 at 09:24 AM ·
c#scripting probleminputfieldsocketemail
How do I implement ServicePoint into my feedbackpage
I wanted to make use of this codes to send email to a gmail account after filling up all of the input fields. However, I have been encountering SocketException: No connection could be made because the target machine actively refused it. I have checked the error by adding breakpoint in my visual studio 2017, I have checked that there is error in ServicePoint. What can I do about it?
Codes:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine.SceneManagement;
public class FeedbackForm : MonoBehaviour {
public InputField senderemail;
public InputField subject;
public InputField message;
public Text error;
public void sendmail_start()
{
StartCoroutine(sendmail());
}
public IEnumerator sendmail()
{
yield return new WaitForSeconds(0.0f);
if (message.text == "" || subject.text == "" || senderemail.text == "")
error.text = "Please fill in all the fields";
else
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(senderemail.text);
mail.To.Add("*******@gmail.com");
mail.Subject = subject.text;
mail.Body = "Mail from : " + senderemail.text + " \n----------------------------------- \n \n" + message.text;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)
{
Timeout = 10000,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("*******@gmail.com", "*********") as ICredentialsByHost,
EnableSsl = true
};
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.Send(mail);
error.text = "The mail is sent successfully";
}
}
public void OnBackToMainMenuClick()
{
SceneManager.LoadScene("Mainpage");
}
public void OnClearButtonClick()
{
senderemail.text = "";
subject.text = "";
message.text = "";
}
}
Thanks for your willingness to help if you know how to solve it etc. It would be greatly appreciated.
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Send inputfield entries via email 2 Answers
Coroutine are making my code architecture miserable 1 Answer
Why the player is keep moving sometimes out of the grid area ? 0 Answers