title: Microsoft graph email attachment status code 405. Method not allowed
body: <p>I'm getting Status Code 405, Method not allowed error when sending email that has an attachment. I'm using HttpClient to post my request to the API rather Microsoft Graph Client. Don't want to have dependency of Microsoft Graph library. My send email without attachment works fine but not with the attachment.</p>
  <pre><code>        try
          {
              const string url = &quot;https://graph.microsoft.com/v1.0/users/myemail@outlook.com/sendMail&quot;;
  
              var path = &quot;C:\\Attachments\\image1.jpg&quot;;
  
              using (HttpClient client = new HttpClient())
              {
                  client.BaseAddress = new Uri(url);
                  client.DefaultRequestHeaders.Accept.Clear();
                  client.DefaultRequestHeaders.Add(&quot;Authorization&quot;, &quot;Bearer &quot; + accessToken);
  
                  byte[] bytes = File.ReadAllBytes(path);
                  string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
  
                  var email = new Email
                  {
                      Message = new Message
                      {
                          Subject = &quot;Test subject&quot;,
                          Body = new Body
                          {
                              ContentType = &quot;Text&quot;,
                              Content = &quot;message&quot;
                          },
                          ToRecipients = new List&lt;Recipients&gt;
                          {
                              new Recipients
                              {
                                  EmailAddress = new EmailAddress
                                  {
                                      Address = &quot;testemail@outlook.com&quot;
                                  }
                              }
                          },
                          Attachments = new List&lt;Attachment&gt;
                          {
                              new Attachment
                              {
                                  Name = &quot;image1.jpg&quot;,
                                  ContentBytes = base64String,
                                  ContentType = &quot;image/jpeg&quot;
                              }
                          }
                      }
                  };
  
                  var jsonMessage = JsonConvert.SerializeObject(email);
                  var content = new StringContent(jsonMessage, Encoding.UTF8, &quot;application/json&quot;);
  
                  HttpResponseMessage response = client.PostAsync(url, content).Result;
                  response.EnsureSuccessStatusCode();
              }
          }
          catch (HttpRequestException e)
          {
              Console.WriteLine(e.Message);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
  </code></pre>