-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 2.23.0 * [Issue #152](#152) * Added full coverage of `Gmail.Settings.SendAs` resource (where signatures are managed with the newer Gmail API): * Added: `Get-GSGmailSendAsAlias` * Added: `Update-GSGmailSendAsAlias` * Added: `Get-GSGmailSignature` (aliased to `Get-GSGmailSendAsAlias`) * Added: `Update-GSGmailSignature` (aliased to `Update-GSGmailSendAsAlias` with some additional convenience parameters) * Added: `Get-GSGmailSendAsSettings` (aliased to `Get-GSGmailSendAsAlias`) * Added: `Update-GSGmailSendAsSettings` (aliased to `Update-GSGmailSendAsAlias`) * Added: `Remove-GSGmailSendAsAlias` * Added: `New-GSGmailSendAsAlias` * Added: `Send-GSGmailSendAsConfirmation`
- Loading branch information
Showing
60 changed files
with
780 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
function Get-GSGmailSendAsAlias { | ||
<# | ||
.SYNOPSIS | ||
Gets SendAs alias settings for a user. | ||
.DESCRIPTION | ||
Gets SendAs alias settings for a user. | ||
.PARAMETER SendAsEmail | ||
The SendAs alias to be retrieved. | ||
If excluded, gets the list of SendAs aliases. | ||
.PARAMETER User | ||
The email of the user you are getting the information for | ||
.EXAMPLE | ||
Get-GSGmailSendAsSettings -User [email protected] | ||
Gets the list of SendAs Settings for Joe | ||
#> | ||
[OutputType('Google.Apis.Gmail.v1.Data.SendAs')] | ||
[cmdletbinding()] | ||
Param ( | ||
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)] | ||
[Alias("SendAs")] | ||
[string[]] | ||
$SendAsEmail, | ||
[parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] | ||
[Alias("PrimaryEmail","UserKey","Mail")] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$User = $Script:PSGSuite.AdminEmail | ||
) | ||
Process { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/gmail.settings.basic' | ||
ServiceType = 'Google.Apis.Gmail.v1.GmailService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
if ($PSBoundParameters.ContainsKey('SendAsEmail')) { | ||
foreach ($sendAs in $SendAsEmail) { | ||
try { | ||
if ($sendAs -notlike "*@*.*") { | ||
$sendAs = "$($sendAs)@$($Script:PSGSuite.Domain)" | ||
} | ||
$request = $service.Users.Settings.SendAs.Get($User,$sendAs) | ||
Write-Verbose "Getting SendAs settings of alias '$sendAs' for user '$User'" | ||
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
try { | ||
$request = $service.Users.Settings.SendAs.List($User) | ||
Write-Verbose "Getting SendAs List for user '$User'" | ||
$request.Execute() | Select-Object -ExpandProperty SendAs | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
function New-GSGmailSendAsAlias { | ||
<# | ||
.SYNOPSIS | ||
Creates a new SendAs alias for a user. | ||
.DESCRIPTION | ||
Creates a new SendAs alias for a user. | ||
.PARAMETER User | ||
The user to create the SendAs alias for. | ||
.PARAMETER SendAsEmail | ||
The email address that appears in the "From:" header for mail sent using this alias. | ||
.PARAMETER DisplayName | ||
A name that appears in the "From:" header for mail sent using this alias. | ||
For custom "from" addresses, when this is empty, Gmail will populate the "From:" header with the name that is used for the primary address associated with the account. | ||
If the admin has disabled the ability for users to update their name format, requests to update this field for the primary login will silently fail. | ||
.PARAMETER IsDefault | ||
Whether this address is selected as the default "From:" address in situations such as composing a new message or sending a vacation auto-reply. | ||
Every Gmail account has exactly one default send-as address, so the only legal value that clients may write to this field is true. | ||
Changing this from false to true for an address will result in this field becoming false for the other previous default address. | ||
.PARAMETER ReplyToAddress | ||
An optional email address that is included in a "Reply-To:" header for mail sent using this alias. | ||
If this is empty, Gmail will not generate a "Reply-To:" header. | ||
.PARAMETER Signature | ||
An optional HTML signature that is included in messages composed with this alias in the Gmail web UI. | ||
.PARAMETER SmtpMsa | ||
An optional SMTP service that will be used as an outbound relay for mail sent using this alias. | ||
If this is empty, outbound mail will be sent directly from Gmail's servers to the destination SMTP service. This setting only applies to custom "from" aliases. | ||
Use the helper function Add-GmailSmtpMsa to create the correct object for this parameter. | ||
.PARAMETER TreatAsAlias | ||
Whether Gmail should treat this address as an alias for the user's primary email address. | ||
This setting only applies to custom "from" aliases. | ||
.EXAMPLE | ||
$smtpMsa = Add-GSGmailSmtpMsa -Host 10.0.30.18 -Port 3770 -SecurityMode none -Username mailadmin -Password $(ConvertTo-SecureString $password -AsPlainText -Force) | ||
New-GSGmailSendAsAlias -SendAsEmail [email protected] -User [email protected] -Signature "<div>Thank you for your time,</br>Joseph Wiggum</div>" -SmtpMsa $smtpMsa | ||
Creates a new SendAs alias for Joe's formal/work address including signature and SmtpMsa settings. | ||
#> | ||
[OutputType('Google.Apis.Gmail.v1.Data.SendAs')] | ||
[cmdletbinding()] | ||
Param ( | ||
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] | ||
[Alias("PrimaryEmail","UserKey","Mail")] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$User, | ||
[parameter(Mandatory = $true)] | ||
[string] | ||
$SendAsEmail, | ||
[parameter(Mandatory = $false)] | ||
[string] | ||
$DisplayName, | ||
[parameter(Mandatory = $false)] | ||
[switch] | ||
$IsDefault, | ||
[parameter(Mandatory = $false)] | ||
[string] | ||
$ReplyToAddress, | ||
[parameter(Mandatory = $false)] | ||
[string] | ||
$Signature, | ||
[parameter(Mandatory = $false)] | ||
[Google.Apis.Gmail.v1.Data.SmtpMsa] | ||
$SmtpMsa, | ||
[parameter(Mandatory = $false)] | ||
[switch] | ||
$TreatAsAlias | ||
) | ||
Process { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
if (-not $PSBoundParameters.ContainsKey('SendAsEmail')) { | ||
$SendAsEmail = $User | ||
} | ||
elseif ($SendAsEmail -notlike "*@*.*") { | ||
$SendAsEmail = "$($SendAsEmail)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = @( | ||
'https://www.googleapis.com/auth/gmail.settings.sharing' | ||
) | ||
ServiceType = 'Google.Apis.Gmail.v1.GmailService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
try { | ||
$body = New-Object 'Google.Apis.Gmail.v1.Data.SendAs' | ||
foreach ($prop in $PSBoundParameters.Keys | Where-Object {$body.PSObject.Properties.Name -contains $_}) { | ||
$body.$prop = $PSBoundParameters[$prop] | ||
} | ||
$request = $service.Users.Settings.SendAs.Create($body,$User) | ||
Write-Verbose "Creating new SendAs alias '$SendAsEmail' for user '$User'" | ||
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.