17

When I send an email using the GMail API, I get an Access Token for the user to whom the message is to be sent and then when sending the message, I put some value in the From Field.

But no matter what I put in the from field, the message in the email shows as From "Me" and is in the Sent mails as well as Inbox.

Is there a way, I could use the Service Account to send the email, so that it does not show up as From "Me" and is also not in the Sent Mails.

davejagoda
  • 2,420
  • 1
  • 20
  • 27
ND003
  • 726
  • 1
  • 8
  • 22
  • https://developers.google.com/gmail/api/guides/sending ? – uksz Oct 20 '15 at 10:05
  • long story short - you can not do this with GMail. You can not do this even if you are using Google App and paying for the service. – Nick Sep 23 '20 at 13:01

3 Answers3

10

You cannot use a service account to impersonate a free gmail account. I spent a lot of time confirming this after reading a reply that was here before. Maybe it worked at some point, but it doesn't anymore.

There is no way to share / grant another user permission to access your standard gmail account. So there is no way for you go delegate the permissions for bob@mycompany.com to access bob@gmail.com.

and

you can impersonate G-Suite accounts but not Gmail accounts

These quotes are from Google's official C# Auth repo:
https://github.com/googleapis/google-api-dotnet-client/issues/1561

VSO
  • 11,546
  • 25
  • 99
  • 187
  • 1
    My "personal account" is in fact a paid G-suite account. Apologies for the confusion. I'll have to get some code up to demo till then I'm deleting that answer – BenKoshy May 15 '20 at 21:52
  • Sorry, I didn't mean to call you out explicitly. I just went down a rabbit hole and didn't want anyone else to do the same. Thanks for you reply. – VSO May 15 '20 at 22:52
  • no issues, i was VERY sloppy with my words so can understand how this would confuse a lot of people. If I had put the code there, it would have solved a lot of headaches for everyone, myself included. – BenKoshy May 16 '20 at 08:35
  • You can use service accounts to impersonate only G-suite accounts, earlier known as Google for work, of your domain – ND003 May 17 '20 at 11:20
  • For anyone reading this later, this is what worked for me: https://stackoverflow.com/questions/19766912/how-do-i-authorise-an-app-web-or-installed-without-user-intervention – VSO May 18 '20 at 13:08
9

No. The Gmail API is for Gmail users and service accounts are just for doing auth to a real Gmail account, they don't have their own Gmail account, etc.

If you want to send the email from some service, you need some bulk-sending email service like at: https://cloud.google.com/compute/docs/tutorials/sending-mail/ or something you run yourself or from some other provider.

Eric D
  • 6,901
  • 1
  • 15
  • 26
-1

No, what you are looking for is a bulk email sending service. Checkout sendgrid , Amazon AWS SES, mandrill or if you want to stick with Google, this. You could of course run your own postfix server (although I'm assuming you were using gmail api for deliverability in the first place.

Jake Sylvestre
  • 936
  • 3
  • 14
  • 39