1

When I am sending mail through gmail service account using gmailapi it is showing the following error.

Errors [ Message[Precondition check failed.] Location[ - ] Reason[failedPrecondition] Domain[global] ] My Gmail service account is a free gmail account. Authentication with service account is working but send mail is not working and showing above error. Please suggest me how to resolve the issue. Here is code i am using to send mail

'''

 MimeMessage email = createEmail(to, from, subject, body);// calling the createEmail Function to create the mail message
                Message message = new Message();
                message.Raw = StringToBase64url(email.ToString());
                var sa1 = service.Users.Messages.Send(message, userId).Execute();
                return sa1;'''
Rob
  • 14,746
  • 28
  • 47
  • 65
  • try this seems like a similar issue https://stackoverflow.com/questions/29327846/gmail-rest-api-400-bad-request-failed-precondition – Ricky Gummadi Aug 04 '20 at 21:27
  • 1
    Service accounts cannot send emails. They can impersonate regular accounts and send emails on behalf of them, but they cannot send them by themselves. Take a look at https://stackoverflow.com/a/29328258 for how to impersonate another account. – Iamblichus Aug 05 '20 at 08:36
  • Does this answer your question? [Gmail REST API : 400 Bad Request + Failed Precondition](https://stackoverflow.com/questions/29327846/gmail-rest-api-400-bad-request-failed-precondition) – Rob Aug 06 '20 at 09:33

1 Answers1

1

try to activated option allow less secure app access in your google account