Question by
aryanhimanshu · Nov 06, 2020 at 10:50 AM ·
unity 2dvisual studiosendmessageemail
Email send via unity with single click button.
Hi i am trying to send a email from unity application but it says username and password not accepted. I have two filed sender email-Id and body. I have made new gmail account for this.
using UnityEngine; using UnityEngine.UI; using System.Net; using System.Net.Mail; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public class emailsend : MonoBehaviour { public InputField bodyMessage; public InputField recipientEmail;
public void SendEmail()
{
MailMessage mail = new MailMessage();
SmtpClient SmtpSever = new SmtpClient("smtp.gmail.com");
SmtpSever.Timeout = 10000;
SmtpSever.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpSever.UseDefaultCredentials = false;
SmtpSever.Port = 587;
mail.From = new MailAddress("xyz@gmail.com");
mail.To.Add(new MailAddress(recipientEmail.text));
mail.Subject = "Test Email through C sharp App";
mail.Body = bodyMessage.text;
SmtpSever.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "xyz") as ICredentialsByHost;SmtpSever.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain,SslPolicyErrors sslPolicyErrors)
{
return true;
};
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpSever.Send(mail);
}
public void SendText(string phoneNumber)
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.Timeout = 10000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
mail.From = new MailAddress("xyz@gmail.com");
mail.To.Add(new MailAddress(phoneNumber + "@txt.att.net"));
mail.Subject = "Subject";
mail.Body = "";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "xyz") as ICredentialsByHost;SmtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
SmtpServer.Send(mail);
}
}
Comment
Your answer
Follow this Question
Related Questions
assembly csharp error 0 Answers
Animator scripting error C# - Only WalkingRight Movement Animates 0 Answers
Unity Gradle Build Error 2019.3.10f 0 Answers
Unity 2D Build Error 0 Answers
Spawn and drag on spawn multiple objects with android multiouch 0 Answers