- Home /
Question by
ayushshreshthi41 · Dec 23, 2020 at 02:07 PM ·
unity 5exceptionmail
SmtpException: 535-5.7.8 Username and Password not accepted
I am developing a project for android with unity 2020.1 first I have made a function that sends a mail with some code to let the user login. and it worked fine. but now after some days(4-5 days), I keep getting this error SmtpException: 535-5.7.8 Username and Password not accepted
then I changed my password again I got this error then I created a new Gmail account and used it but still getting this error
note - I am using my credentials correctly.
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.Timeout = 10000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Port = 587;
mail.From = new MailAddress("mygmail");
mail.To.Add(new MailAddress(emailInput.text));
emailToDb = emailInput.text.ToString();
mail.Subject = " ";
int randNom = UnityEngine.Random.Range(1111, 999999);
codeLogin = randNom;
mail.Body = randNom.ToString();
SmtpServer.Credentials = new System.Net.NetworkCredential("mygmail", "mypassword") 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