public void RemoveSendAs(string id) { id.ThrowIfNotEmailAddress(); GmailService service = this.GetService(id); ListSendAsResponse result = service.Users.Settings.SendAs.List(id).ExecuteWithRetry(RetryEvents.BackoffOAuth, this.RetryCount); if (result.SendAs != null) { foreach (SendAs item in result.SendAs.Where(t => !t.IsPrimary ?? false)) { service.Users.Settings.SendAs.Delete(id, item.SendAsEmail).ExecuteWithRetry(RetryEvents.BackoffOAuth, this.RetryCount, 5); } } }
public IEnumerable <string> GetSendAsAddresses(string id) { try { id.ThrowIfNotEmailAddress(); GmailService service = this.GetService(id); UsersResource.SettingsResource.SendAsResource.ListRequest request = service.Users.Settings.SendAs.List(id); ListSendAsResponse result = request.ExecuteWithRetry(RetryEvents.BackoffOAuthNotFound | RetryEvents.Timeout, this.RetryCount); return(result.SendAs?.Select(t => t.SendAsEmail) ?? new List <string>()); } catch (GoogleApiException ex) { if (ex.HttpStatusCode == HttpStatusCode.BadRequest && ex.Message != null && ex.Message.IndexOf("Mail service not enabled", StringComparison.OrdinalIgnoreCase) >= 0) { return(new List <string>()); } else { throw; } } }