Using Gmail API to send an email using Invoke-WebRequest in Powershell

Any reasons not to use Send-MailMessage ?. If not you can try this example:

$From = "[email protected]"
$To = "[email protected]"
$Cc = "[email protected]"
$Attachment = "C:\temp\Some random file.txt"
$Subject = "Email Subject"
$Body = "Insert body text here"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
    -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
    -Credential (Get-Credential) -Attachments $Attachment