title: Outlook REST API SendMail - Http failure response for https://outlook.office.com/api/v2.0/me/sendmail: 401 Unauthorized
body: <p>I am working on an app that uses my token generated by msgraph v.1.0 to send emails through outlook api v2.0. It was working until a couple of weeks ago (for what I can tell), but since last Wednesday I tried it and it is not working (not sending emails)! I thought it was my code but I reversed it for my previous code that had it working and still I am getting this error:</p>
  
  <p>I have registered my app in the Microsoft developer site with the Mail.Send permission as well and went back there just to make sure.
  My app also access SharePoint and it is working normally.. When I login I print my token and it looks fine. It was sending emails before.. I have no idea of what happened.</p>
  
  <pre><code>"headers": {
  
  "normalizedNames": {},
  
  "lazyUpdate": null
  
  },
  
  "status": 401,
  
  "statusText": "Unauthorized",
  
  "url": "https://outlook.office.com/api/v2.0/me/sendmail",
  
  "ok": false,
  
  "name": "HttpErrorResponse",
  
  "message": "Http failure response for https://outlook.office.com/api/v2.0/me/sendmail: 401 Unauthorized",
  
  "error": null
  
  }
  </code></pre>
  
  <p>The code I am using to send the email is:</p>
  
  <pre><code>private serverUrl =
  "https://outlook.office.com/api/v2.0/me/sendmail";
  
  constructor(private
  http: HttpClient) {}
  
  postData(data:
  any, token:
  any) {
  
  let options =
  this.createRequestOptions(token);
  
  return this.http.post(this.serverUrl,
  data, { headers:
  options })
  
  .map(res
  =&gt; res);
  
  }
  
  private createRequestOptions(token:
  any) {
  
  let headers =
  new HttpHeaders({
  
  "Authorization":
  "Bearer " + 
  token,
  
  "Content-Type":
  "application/json"
  
  });
  
  return headers;
  
  }
  </code></pre>
  
  <p>And I am passing the values:</p>
  
  <pre><code>this.mailService
  
  .postData(this.data,
  this.token)
  
  .subscribe(
  
  () =&gt; {
  
  dialogs.alert("Email sent. Thank you!").then(function () {
  
  let page =
  topmost().currentPage;
  
  page.modal.closeModal();
  
  });
  
  },
  
  (e) =&gt; {
  
  console.log(e);
  
  alert({
  
  message: "An error occurred while sending your contact helpdesk.",
  
  okButtonText: 
  "OK"
  
  });
  
  }); 
  </code></pre>
  
  <p>Has anyone faced this issue?</p>