Deleting Gmail Emails via Google API using Powershell v2.0

前端 未结 1 1680
深忆病人
深忆病人 2021-01-22 05:08
$user = \"example@gmail.com\"
$pass= \"examplepassword\" 
$secpasswd = ConvertTo-SecureString $user -AsPlainText -Force
$cred = New-Object System.Management.Automation.P         


        
相关标签:
1条回答
  • 2021-01-22 05:40

    The GMail API is going to require Oauth2 authentication unless this is a gsuit / domain admin / GMail account in which case you can use a service account for authentication. In either case you cant use login and password.

    My powershell knowledge is very limited have you considered doing this directly though the mail server IMAP and SMTP and not using the API. No idea if that's possible or not with powershell

    Update:

    I was able to do it using Invoke-WebRequest you will still need to get an access token first.

    Invoke-WebRequest -Uri "https://www.googleapis.com/gmail/v1/users/me/messages/0?access_token=$accesstoken"-Method Get | ConvertFrom-Json
    

    seams to also work

    Invoke-RestMethod -Uri "https://www.googleapis.com/gmail/v1/users/me/messages/0?access_token=$accesstoken"-Method Get 
    

    Put up a the code for OAuth on GitHub if your interested: Google Oauth Powershell

    0 讨论(0)
提交回复
热议问题