Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to get the message using Gmail API's. I am able to fetch the messages which are smaller in size. But when try to get large size message, it throws exception as 'Task was cancel'.
As per google
documentation
I tried to get message as RAW as well as FULL formats. Also I tried with increased timeout for request.
But having same result.
Is there any other way by which I can read large messages?
Here is my sample code:
GmailServiceObj = new GmailService(new BaseClientService.Initializer()
ApplicationName = _appname,
HttpClientInitializer = _userCredentials
UsersResource.MessagesResource.GetRequest MessageGetRequestObj;
MessageGetRequestObj= GmailServiceObj.Users.Messages.Get(UserEmailID, ItemID);
MessageGetRequestObj.Service.HttpClient.Timeout = new TimeSpan(0, 5, 0);
MessageGetRequestObj.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
var _message = MessageGetRequestObj.Execute(); // throws exception
catch(Exception e)
{ //The request was aborted: The request was canceled.
// trying to read same message in parts
MessageGetRequestObj.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
var _message = MessageGetRequestObj.Execute();
string res = Readparts(Emailobj.Payload.Parts, ItemID);
private String Readparts(IList<MessagePart> parts, string msgid)
StringBuilder mime = new StringBuilder();
foreach (var part in parts)
if (part != null && part.Body != null)
mime.Append(part.Body.Data);
if (part.Body != null && part.Body.AttachmentId != null)
var resource = GmailServiceObj.Users.Messages.Attachments.Get("me", msgid, part.Body.AttachmentId);
MessagePartBody attachPart = resource.Execute(); // Throws exception
// Converting from RFC 4648 base64 to base64url encoding
// see http://en.wikipedia.org/wiki/Base64#Implementations_and_history
String attachData = attachPart.Data.Replace('-', '+');
attachData = attachData.Replace('_', '/');
mime.Append(attachData);
if (part.Parts != null && part.Parts.Count > 0)
mime.Append(Readparts(part.Parts, msgid));
catch (Exception er) { }
catch (Exception ex)
return mime.ToString();
Thanks in advance.
EDIT: Comlpete LOG
-----------------------------------------------------------------------------------------MAIN EXEPTION------------------------------------------------
Error while copying content to a stream.
System.Net.Http.HttpContent.d__49.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Net.Http.HttpClient.d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
Google.Apis.Requests.ClientServiceRequest
1.<ExecuteUnparsedAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
Google.Apis.Requests.ClientServiceRequest
1.Execute()
-----------------------------------------------------------------------------------------INNER EXEPTION------------------------------------------------
Received an unexpected EOF or 0 bytes from the transport stream.
at System.Net.GZipWrapperStream.EndRead(IAsyncResult asyncResult)
at System.IO.Stream.<>c.b__43_1(Stream stream,
IAsyncResult asyncResult) at
System.Threading.Tasks.TaskFactory
1.FromAsyncTrimPromise
1.Complete(TInstance
thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean
requiresSynchronization)
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.IO.Stream.d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Net.Http.StreamToStreamCopy.<>c.b__1_0(Task
completed, Object innerSource) at
System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() at
System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Net.Http.HttpContent.d__49.MoveNext()
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.