I am trying to cuild a client to send mails using the Gmail API. I have taken the send mail code from the developer website.
https://developers.google.com/gmail/api/SendEmail.java
I believe I have included all the required libraries to do this process.
I am getting an error in this method :
public static Message sendMessage(Gmail service,
String userId,
MimeMessage emailContent)
throws MessagingException, IOException {
Message message = createMessageWithEmail(emailContent);
message = service.users().messages().send(userId, message).execute();
System.out.println("Message id: " + message.getId());
System.out.println(message.toPrettyString());
return message;
}
The error occurs in this line exactly :
message = service.users().messages().send(userId, message).execute();
I am not able to figure out what is wrong here. I tried the other questions in stackoverflow, but there still seems to be a floating question with the same subject without an answer for a long time.
send mail using gmail api in android
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:299)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.googleUtils.SendEmail.sendMessage(SendEmail.java:78)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.googleUtils.GmailHelper.sendMail(GmailHelper.java:126)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.SendMailActivity$MakeRequestTask.doInBackground(SendMailActivity.java:397)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.SendMailActivity$MakeRequestTask.doInBackground(SendMailActivity.java:359)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.lang.Thread.run(Thread.java:818)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: Caused by: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd$1.zzar(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd$1.zzas(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.zza(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.zzc(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.getToken(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.getToken(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.getToken(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
10-26 00:56:45.600 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:269)
10-26 00:56:45.615 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:294)
10-26 00:56:45.616 30338-30753/com.mail.dinesh.mailapplication W/System.err: ... 14 more
Android Drive API: getting Sys.err UserRecoverableAuthIOException if i merge code to other projects solves a bit of the problem. The error changes to 400 bad request.