title: Microsoft graph send mail android java
body: <p>I've been trying to send an email through an app that I've created in java but I'm getting 424 Error during Http request whenever I try to send the email I'm currently just using Microsoft's demo code for the request.</p>
  <pre><code>IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
  
  Message message = new Message();
  message.subject = &quot;Meet for lunch?&quot;;
  ItemBody body = new ItemBody();
  body.contentType = BodyType.TEXT;
  body.content = &quot;The new cafeteria is open.&quot;;
  message.body = body;
  LinkedList&lt;Recipient&gt; toRecipientsList = new LinkedList&lt;Recipient&gt;();
  Recipient toRecipients = new Recipient();
  EmailAddress emailAddress = new EmailAddress();
  emailAddress.address = &quot;fannyd@contoso.onmicrosoft.com&quot;;
  toRecipients.emailAddress = emailAddress;
  toRecipientsList.add(toRecipients);
  message.toRecipients = toRecipientsList;
  LinkedList&lt;Recipient&gt; ccRecipientsList = new LinkedList&lt;Recipient&gt;();
  Recipient ccRecipients = new Recipient();
  EmailAddress emailAddress1 = new EmailAddress();
  emailAddress1.address = &quot;danas@contoso.onmicrosoft.com&quot;;
  ccRecipients.emailAddress = emailAddress1;
  ccRecipientsList.add(ccRecipients);
  message.ccRecipients = ccRecipientsList;
  
  boolean saveToSentItems = false;
  
  graphClient.me()
      .sendMail(message,saveToSentItems)
      .buildRequest()
      .post();
  </code></pre>
  <p>Any ideas on why I'm getting this error and how I fix this?</p>
  <p>Thanks</p>
  <p>Edit: here is the logcat</p>
  <pre><code>2020-07-17 16:12:22.744 4247-4247/com.brewski.servicecertificatepdf E/global: CoreHttpProvider[sendRequestInternal] - 424Error during http request
  2020-07-17 16:12:22.744 4247-4247/com.brewski.servicecertificatepdf E/global: Throwable detail: com.microsoft.graph.core.ClientException: Error during http request
  2020-07-17 16:12:22.753 4247-4247/com.brewski.servicecertificatepdf E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.brewski.servicecertificatepdf, PID: 4247
      com.microsoft.graph.core.ClientException: Error during http request
          at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:422)
          at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:204)
          at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:184)
          at com.microsoft.graph.http.BaseRequest.send(BaseRequest.java:306)
          at com.microsoft.graph.requests.extensions.UserSendMailRequest.post(UserSendMailRequest.java:43)
          at com.brewski.servicecertificatepdf.MSoft.GraphHelper.sendEmail(GraphHelper.java:103)
          at com.brewski.servicecertificatepdf.Fragments.PreviewFragment$1$1.onSuccess(PreviewFragment.java:93)
          at com.microsoft.identity.client.PublicClientApplication.postAuthResult(PublicClientApplication.java:1659)
          at com.microsoft.identity.client.SingleAccountPublicClientApplication$4.onSuccess(SingleAccountPublicClientApplication.java:264)
          at com.microsoft.identity.common.internal.controllers.ApiDispatcher$4$2.run(ApiDispatcher.java:433)
          at android.os.Handler.handleCallback(Handler.java:907)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:223)
          at android.app.ActivityThread.main(ActivityThread.java:7478)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
       Caused by: android.os.NetworkOnMainThreadException
          at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1598)
          at com.android.org.conscrypt.Platform.blockGuardOnNetwork(Platform.java:426)
          at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:789)
          at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readUntilDataAvailable(ConscryptEngineSocket.java:777)
          at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.read(ConscryptEngineSocket.java:750)
          at okio.Okio$2.read(Okio.java:140)
          at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
          at okio.RealBufferedSource.exhausted(RealBufferedSource.java:57)
          at okhttp3.internal.connection.RealConnection.isHealthy(RealConnection.java:561)
          at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:147)
          at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
          at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
          at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
          at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
          at com.microsoft.graph.httpcore.TelemetryHandler.intercept(TelemetryHandler.java:35)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
          at com.microsoft.graph.httpcore.RedirectHandler.intercept(RedirectHandler.java:123)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
  2020-07-17 16:12:22.756 4247-4247/com.brewski.servicecertificatepdf E/AndroidRuntime:     at com.microsoft.graph.httpcore.RetryHandler.intercept(RetryHandler.java:140)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
          at com.microsoft.graph.httpcore.AuthenticationHandler.intercept(AuthenticationHandler.java:31)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
          at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
          at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
          at okhttp3.RealCall.execute(RealCall.java:92)
          at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:356)
              ... 16 more
  </code></pre>