question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gmailService.Users.Messages.Send Error while copying content to a stream.

See original GitHub issue

Error when trying to send a message with an attachment in it. note: total attachment file size is around 15mb

System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Security.SslStreamInternal.<WriteSingleChunk>g__CompleteAsync|36_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn)
   at System.Net.Security.SslStreamInternal.WriteAsyncChunked[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
   at System.Net.Security.SslStreamInternal.<WriteAsyncInternal>g__ExitWriteAsync|35_0[TWriteAdapter](ValueTask task)
   at System.
Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory`1 source)
   at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask)
   --- End of inner exception stack trace ---
   at Google.Apis.Http.ConfigurableMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in C:\\Apiary\\2019-08-05.16-52-01\\Src\\Support\\Google.Apis.Core\\Http\\ConfigurableMessageHandler.cs:line 486
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Google.Apis.Requests.ClientServiceRequest`1.ExecuteUnparsedAsync(CancellationToken cancellationToken) in C:\\Apiary\\2019-08-05.16-52-01\\Src\\Support\\Google.Apis\\Requests\\ClientServiceRequest.cs:line 231
   at Google.Apis.Requests.ClientServiceRequest`1.Execute() in C:\\Apiary\\2019-08-05.16-52-01\\Src\\Support\\Google.Apis\\Requests\\ClientServiceRequest.cs:line 167

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
jskeetcommented, Sep 14, 2019

I’m afraid I don’t know on that front. I suspect it’s just not designed to work like that.

Most of this is really about “the GMail API in general” rather than the .NET client libraries… while I know a bit about some of the APIs, there are far too many for me to be an expert in all of them. I suggest using one of the options listed in the support page for more API-specific information. I’m going to close this issue now as I don’t believe there’s an issue with the .NET client library itself, which is what this specific repository is for. Good luck with your application.

1reaction
jskeetcommented, Sep 14, 2019

Right, I suspect that’s the problem - I believe there’s a 25MB limit for that upload field. I suggest:

  • Try with a smaller message (e.g. at 24MB) to validate that that really is the issue
  • Try uploading the attachments separately as I suggested before
Read more comments on GitHub >

github_iconTop Results From Across the Web

Receiving 403 error with Users.Messages.Send in Gmail API
I'm trying to call Send on the GmailService from a C# .NET MVC app. and I keep getting a 403 error when I...
Read more >
Error while copying content to a stream.
I am trying to do a simple post with SendAsync off of the HttpClient and it fails with the following execptions: Message=One or...
Read more >
Sending Email | Gmail
The high-level workflow to send an email is to: Create the email content in some convenient way and encode it as a base64url...
Read more >
Re: Seeing 400 error while trying to send a mail
I'm trying to send a mail from my App engine application. I've authenticatied to Gmail API using my service account's key file.
Read more >
How to Send and Read Emails with Gmail API
Gmail API is a safe and flexible way to send emails from your app. Here is a full guide on how to access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found