Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send-MgUserMail: Send a new message using MIME format #844

Closed
Viajaz opened this issue Sep 3, 2021 · 4 comments
Closed

Send-MgUserMail: Send a new message using MIME format #844

Viajaz opened this issue Sep 3, 2021 · 4 comments

Comments

@Viajaz
Copy link

Viajaz commented Sep 3, 2021

Support for sending a new message using MIME format with Send-MgUserMail

https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http#example-4-send-a-new-message-using-mime-format

@ghost ghost added the ToTriage label Sep 3, 2021
@ghost ghost added this to Issues to triage in Graph SDK - Triage Sep 3, 2021
@Viajaz
Copy link
Author

Viajaz commented Sep 6, 2021

For those in the same position, use Invoke-MgGraphRequest for now:

Delegated Mail.Send permission

Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/me/sendMail" -Body $RequestBody -ContentType 'text/plain'

Application level Mail.Send permission

Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/users/$($UserId)/sendMail" -Body $RequestBody -ContentType 'text/plain'

An example using Mailkit (DE0005)

Add-Type -Path MailKit.dll
$Message = [MimeKit.MimeMessage]::new()
$Message.From.Add([MimeKit.InternetAddress]'sender@example.com')
$Message.To.Add([MimeKit.InternetAddress]'receiver@example.com')
$Message.Subject = 'Test'
$BodyBuilder = [MimeKit.BodyBuilder]::new()
$BodyBuilder.TextBody = 'This is a test message'
$Message.Body = $BodyBuilder.ToMessageBody()
$MessageStream = [System.IO.MemoryStream]::new()
$Message.WriteTo($MessageStream)
$MessageStream.Position = 0
$MessageStreamReader = [System.IO.StreamReader]::new($MessageStream, [System.Text.Encoding]::UTF8)
$MessageMIME = $MessageStreamReader.ReadToEnd()
$RequestBody = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($MessageMIME))
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/me/sendMail" -Body $RequestBody -ContentType 'text/plain'

@peombwa peombwa self-assigned this Sep 8, 2021
@ghost ghost removed the ToTriage label Sep 8, 2021
@peombwa peombwa removed their assignment Jul 7, 2023
@ddyett
Copy link
Contributor

ddyett commented Jul 19, 2023

@peombwa is this something implemented in V2.

@peombwa
Copy link
Member

peombwa commented Jul 19, 2023

@ddyett, MIME format is currently not supported by all SDKs due to missing MIME path in the metadata used to generate the SDKs. A workaround is to fall back to Invoke-MgGraphRequest as documented #844 (comment). I'll transfer the issue to the metadata repo for visibility.

@peombwa
Copy link
Member

peombwa commented Jul 19, 2023

Transferred to microsoftgraph/msgraph-metadata#389.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

3 participants