r/PowerShell • u/Roman1410S • Nov 22 '21
Send an E-Mail using the MS-Graph PowerShell Commandlets in 3 steps
https://www.powershell.co.at/send-an-e-mail-using-the-ms-graph-powershell-commandlets-in-3-steps/3
u/logicalmike Nov 22 '21
2
u/Roman1410S Nov 23 '21
Great ! Do you know if it is possible to set an X-Header with those cmdlets?
1
2
Jun 23 '22 edited Jun 16 '23
Edited in protest of Reddit's actions.
2
u/logicalmike Jun 23 '22 edited Jun 23 '22
Thanks for the feedback. I'll have to look later to see how that post can be enhanced/fixed. In the meantime, you can look at the new example Microsoft has added to the documentation (example 3):
It wants a nested hash table (or
[Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAttachment]) where theContentBytesare the file in base 64 (grab the tobase64 line from my script)edit - something like this
$MyFilePath = "C:\tmp\test.txt" $ContentBytes = [convert]::ToBase64String((Get-Content $MyFilePath -Encoding byte)) [Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAttachment]$MyAttachment = @{ "@odata.type" = "#microsoft.graph.fileAttachment" Name = "test.txt" ContentType = "text/plain" ContentBytes = $ContentBytes } $Attachments = @($MyAttachment)2
9
u/ITGuyThrow07 Nov 22 '21
Awesome, thank you. I know they're trying to push people away from Send-MailMessage, but the only "replacement" I came across was some insane 75-line monstrosity.
9
Nov 22 '21
Yeah, I've found it pretty annoying that Microsoft is like, "Don't use Send-MailMessage. SMTP with basic authentication is no good."
And I ask, "Ok, what should we be doing then?"
And it's crickets. No solutions.
I'll give this approach a try.
5
u/enforce1 Nov 22 '21
3
4
1
u/Mental_Patient_1862 Nov 23 '21
Is there a US-based mirror to this? Boss here has blocked everything that's not in USA (with few exceptions) -- argh.
4
u/randomadhdman Nov 22 '21
Awesome little blog. What if the client doesnt have permissions for mail.send. what if mail.readwrite is a no go with security. How do you do this without the modules?
Does using the modules create random permissions apps or anything like that? Anything needed on the back end before doing this?