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("SenderEmail@gmail.com");
mail.To.Add(new MailAddress("RecieverEmail@gmail.com"));
mail.Subject = "Report";
mail.Body = "This is a report.";
System.Net.Mail.Attachment att;
System.Net.Mail.Attachment att2;
System.Net.Mail.Attachment att3;
att = new Attachment(GameManager.CSVFile1.GetFilePath());
att2 = new Attachment(GameManager.CSVFile2.GetFilePath());
att3 = new Attachment(GameManager.CSVFile3.GetFilePath());
mail.Attachments.Add(att);
mail.Attachments.Add(att2);
mail.Attachments.Add(att3);
SmtpServer.Credentials = new System.Net.NetworkCredential("SenderEmail@gmail.com", "EmailPassword") 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);
Hello,
I have been developing an application for the Oculus Quest 2 for a while now and I was using the code shown here to to send out emails with CSV files as attachments.
Previously during testing I had no issues with my VR app login into my gmail to send out these emails. However, this was all done when my Oculus device was connected to the same network as my work computer (which I use for development).
Recently I tried to use this function remotely, as in away from my work computer with my oculus being connected to another network. This time I ran into an issue were my game is stuck on the scene were the email would be sent, and I get a notification on my gmail that a suspicious login attempt has been blocked (the code in my game does not proceed because it cannot access my email).
The âLess secure app accessâ option has been enabled on my gmail during this test and the âclear cacheâ suggestion is not an option given that the user needs to send emails freely.
If anyone has any suggestions on how I can get around this it would be much appreciated. Also, I am currently looking into using a server to save CSVs and send out emails that way but I am not sure if this is the way to go.
Yes I did, I had to use a third party software called âSendGridâ, which is essentially a server that handles the distribution of emails. They have a free subscription deal and they have a guide on how to integrate their service into any Unity project (https://sendgrid.com/blog/send-email-unity-game/).
Hopefully this can help anyone else with my previous issue :).
I already figured it out, Iâll post the solution to my problem in case someone else needs it:
smtpServer.Credentials = new System.Net.NetworkCredential(api_user, api_key) as ICredentialsByHost;
In this line I changed the value of api_user to the string âapikeyâ and the value of api_key to the API key you get when you create a new one and SendGrid tells you to store it somewhere safe (you wonât be able to see it again after you create it). In the end it looked like this:
smtpServer.Credentials = new System.Net.NetworkCredential("apikey", "ThisIsWhereYouPasteYourAPIKey") as ICredentialsByHost;