I have the following SharePoint CSOM code inside my c# console application to send an email using the office 365 admin username and password using the
client.Credentials = new NetworkCredential(username, passWord);, as follow :-
static private void sendemail(ClientContext context, string subject, string body, FieldUserValue to, string username, SecureString passWord)
using (MailMessage mail = new MailMessage())
mail.From = new MailAddress("sharepoint@***.com");
mail.Subject = subject;
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("***-com.mail.protection.outlook.com", 25);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(username, passWord);
client.EnableSsl = true;
mail.Body = body;
string approvalemailTo = "";
foreach (var t in to)
approvalemailTo = approvalemailTo + t.Email + ";";
catch (Exception e)
but to make my code more secure, how i can authenticate the SmtpClient using AppID and APPSecret instead of passing the username and password?
Get this bounty!!!
I am making requests to the Microsoft Graph REST api (beta), specifically to the sign-in event endpoint: https://graph.microsoft.com/beta/auditLogs/signIns
I am making batch requests that retrieve sign-ins for a particular user in batches of 1000. Starting around the 25th of september, these requests would fail after roughly 10-50 batches, with the following response, with a 400 (Invalid Request) HTTP error code:
"message": "Token not found: token is either invalid or expired",
However, if I retry the requests after waiting ~1s, with the very same JWT access token, the requests succeed and I’m able to complete all the batch requests for the job I’m running. The access token I receive when initially authenticating expires in 1 hour, but this error crops up ~1-15 minutes after I receive the token (I’ve confirmed the unix timestamp expiry date I get w/ the token).
I’m wondering what could be the cause of this error, and how I could avoid it, other than hard-coding the specific response message and retrying. I was unable to find any matches on google for the error message, either. Has anyone seen this error before from the Microsoft Graph API?
Get this bounty!!!