-
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.
+MimeMessage handling using MimeKit and -ParseMessage switch to Get-G…
…SGmailMessageInfo
- Loading branch information
Nate Ferrell
committed
Feb 11, 2017
1 parent
725cd85
commit e09b1dd
Showing
22 changed files
with
182 additions
and
33 deletions.
There are no files selected for viewing
Binary file not shown.
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,89 @@ | ||
function New-MimeMessage { | ||
[cmdletbinding()] | ||
Param | ||
( | ||
[parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string[]] | ||
$To, | ||
[parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[String] | ||
$From, | ||
[parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$Subject, | ||
[parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$Body, | ||
[parameter(Mandatory=$false)] | ||
[string[]] | ||
$CC, | ||
[parameter(Mandatory=$false)] | ||
[string[]] | ||
$BCC, | ||
[parameter(Mandatory=$false)] | ||
[ValidateScript({Test-Path $_})] | ||
[string[]] | ||
$Attachment, | ||
[parameter(Mandatory=$false)] | ||
[switch] | ||
$BodyAsHtml | ||
) | ||
#[System.Reflection.Assembly]::LoadFrom("$ModuleRoot\nuget\MimeKit.1.10.1\lib\net451\MimeKit.dll") | Out-Null | ||
[System.Reflection.Assembly]::LoadFrom("C:\GDrive\PSModules\PSGSuite\nuget\MimeKit.1.10.1\lib\net451\MimeKit.dll") | Out-Null | ||
$message = [MimeKit.MimeMessage]::new() | ||
$message.From.Add($From) | ||
$message.Subject = $Subject | ||
foreach ($T in $To) | ||
{ | ||
$message.To.Add($T) | ||
} | ||
if ($CC) | ||
{ | ||
foreach ($C in $CC) | ||
{ | ||
$message.Cc.Add($C) | ||
} | ||
} | ||
if ($BCC) | ||
{ | ||
foreach ($B in $BCC) | ||
{ | ||
$message.Bcc.Add($B) | ||
} | ||
} | ||
if ($BodyAsHtml) | ||
{ | ||
$TextPart = [MimeKit.TextPart]::new("html") | ||
} | ||
else | ||
{ | ||
$TextPart = [MimeKit.TextPart]::new("plain") | ||
} | ||
$TextPart.Text = $Body | ||
if ($Attachment) | ||
{ | ||
[System.Reflection.Assembly]::LoadWithPartialName('System.IO') | Out-Null | ||
$Multipart = [MimeKit.Multipart]::new("mixed") | ||
$Multipart.Add($TextPart) | ||
foreach ($Attach in $Attachment) | ||
{ | ||
$MimeType = (Get-MimeType -File $Attach) -split "/" | ||
$MimePart = [MimeKit.MimePart]::new($MimeType[0], $MimeType[1]) | ||
$MimePart.ContentObject = [MimeKit.ContentObject]::new([IO.File]::OpenRead($Attach), [MimeKit.ContentEncoding]::Default) | ||
$MimePart.ContentDisposition = [MimeKit.ContentDisposition]::new([MimeKit.ContentDisposition]::Attachment) | ||
$MimePart.ContentTransferEncoding = [MimeKit.ContentEncoding]::Base64 | ||
$MimePart.FileName = [IO.Path]::GetFileName($Attach) | ||
$Multipart.Add($MimePart) | ||
} | ||
$message.Body = $Multipart | ||
} | ||
else | ||
{ | ||
$message.Body = $TextPart | ||
} | ||
return $message | ||
} |
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,47 @@ | ||
function Read-MimeMessage { | ||
[cmdletbinding(DefaultParameterSetName="String")] | ||
Param | ||
( | ||
[parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,ParameterSetName="String")] | ||
[ValidateNotNullOrEmpty()] | ||
[string[]] | ||
$String, | ||
[parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,ParameterSetName="EmlFile")] | ||
[ValidateScript({Test-Path $_})] | ||
[string[]] | ||
$EmlFile | ||
) | ||
Begin | ||
{ | ||
[System.Reflection.Assembly]::LoadFrom("$ModuleRoot\nuget\MimeKit.1.10.1\lib\net451\MimeKit.dll") | Out-Null | ||
$results = @() | ||
} | ||
Process | ||
{ | ||
if ($PSCmdlet.ParameterSetName -eq "String") | ||
{ | ||
$Guid = (New-Guid).Guid | ||
$String | Set-Content "$env:TEMP\Mime$Guid.eml" -Force | ||
$results += [MimeKit.MimeMessage]::Load("$env:TEMP\Mime$Guid.eml") | ||
do | ||
{ | ||
try | ||
{ | ||
Remove-Item "$env:TEMP\Mime$Guid.eml" -Force | ||
} | ||
catch | ||
{} | ||
} | ||
until | ||
(!(Test-Path "$env:TEMP\Mime$Guid.eml")) | ||
} | ||
else | ||
{ | ||
$results += [MimeKit.MimeMessage]::Load($EmlFile) | ||
} | ||
} | ||
End | ||
{ | ||
return $results | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+752 KB
...it.1.10.1/lib/portable-net45+win+wp80+MonoAndroid10+Xamarin.iOS10+MonoTouch10/MimeKit.dll
Binary file not shown.
Binary file added
BIN
+969 KB
...ortable-net45+win+wp80+MonoAndroid10+Xamarin.iOS10+MonoTouch10/Portable.Text.Encoding.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.