gmail api option.
In order to use service accounts with your workspace domain you need to set up the service account and enable domain wide deligation
Google has sevral very good guidles on how to set it up. The best IMO beingPerform Google Workspace Domain-Wide Delegation of Authority
You will just need to rember to set the scope https://www.googleapis.com/auth/gmail
, instead of https://www.googleapis.com/auth/admin.directory.user
, https://www.googleapis.com/auth/admin.directory.group
shown in the example
After that its simply a matter of using the standard service account code and adding the user that you wish to deligate as
var credential = GoogleCredential.FromFile(serviceAccountCredentialFilePath)
.CreateScoped(scopes);
var gsuiteUser = "noreply@yourdomain.com";
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
This is a previous question related to this. How to use gmail api with service accounts or google Oauth in C# for sending mails? However im not sure if you are looking for a smtp answer or a Gmail api answer.
smtp / imap option.
If you want to go though the SMTP / IMAP you need to check Xoauth2. The procedure is the same you will need to set up domain wide delegation to your domain account but the scope changes you need to use https://www.googleapis.com/auth/gmail.imap_admin
I am not aware of any .net examples of this.