Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GMail API - Can I send email using the Service Account?

Tags:

gmail-api

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.

like image 421
ND003 Avatar asked Oct 20 '15 10:10

ND003


People also ask

Can I use Gmail to send email from my domain?

Luckily, it's possible to use Gmail with your own domains for free. That way, you can have the best of both worlds — a custom domain email with the convenience of Gmail's interface. You also don't have to log in to different platforms to manage your personal and business emails.

What can I do with Gmail API?

The Gmail API is a RESTful API that can be used to access Gmail mailboxes and send mail. For most web applications the Gmail API is the best choice for authorized access to a user's Gmail data and is suitable for various applications, such as: Read-only mail extraction, indexing, and backup.


2 Answers

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.

like image 61
Eric D Avatar answered Sep 23 '22 08:09

Eric D


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 [email protected] to access [email protected].

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

like image 21
VSO Avatar answered Sep 23 '22 08:09

VSO