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

Adding attachment >3 MB not possible if no client secret is used #55

Open
scriptkiddy666 opened this issue Jul 29, 2024 · 6 comments
Open

Comments

@scriptkiddy666
Copy link

Hi,
maybe it's a bug, but I'm unable to send attachments which are bigger than 3 MB via a managed identity or a normal app registration with certificate based authentication.
After creating a client secret for the same app registration it worked. (But I don't want to use a client secret.)
Is it possible, that the function which handles the upload somehow doesn't use the already existing session?
Because the upload doesn't work, but the email is send without problems (and without an attachment of course).

image

I used the following commands:
Connect-MgGraph -Identity
or
Connect-MgGraph -ClientId $ClientId -TenantId $TenantId -CertificateThumbprint $Thumbprint

Send-EmailMessage -From 'XXX' -To 'XXX' -HTML "XXX" -Subject 'XXX' -Graph -ReplyTo "XXX" -MgGraphRequest -Attachment "C:\temp\XXX.pdf" -Verbose

(By using the parameter -Credential and the function ConvertTo-GraphCredential for generating the credential object and removing the parameter -MgGraphRequest it worked.)

Thanks,
Markus

@PrzemyslawKlys
Copy link
Member

Try using PS 7, it should provide better error reporting. Also do you have proper rights to upload files? As ReadWrite Emails? Send is not enough.

@scriptkiddy666
Copy link
Author

Same with PS7 (do I have to "reinstall" the module for PS7?):
image

Yes, both, my managed identity and the app registration have Mail.Send and Mail.ReadWrite. (That should be fine, because it worked with the client secret for the same app registration.)

@PrzemyslawKlys
Copy link
Member

You don't have to reinstall module.

Just to clarify:

  • Does it work for 4MB plus with Connect-MgGraph and MgGraphRequest with ClientSecret?
  • It doesn't work with Connect-MgGraph and MgGraphRequest with Certificate?

@PrzemyslawKlys
Copy link
Member

And I assume in all cases the mailbox does exists? The one you're sending it with?

@scriptkiddy666
Copy link
Author

scriptkiddy666 commented Jul 30, 2024

You don't have to reinstall module.

Just to clarify:

  • Does it work for 4MB plus with Connect-MgGraph and MgGraphRequest with ClientSecret?
    Yes. I just tried it again (also without executing Connect-MgGraph before) by just adding the -Credential parameter with the ClientSecret. Works like a charm. (The parameter -MgGraphRequeset was not added.)
  • It doesn't work with Connect-MgGraph and MgGraphRequest with Certificate?
    Yes. I used Connect-MgGraph with my certificate before executing Send-EmailMessage.
    (-Credential parameter of Send-EmailMessage removed and -MgGraphRequest added instead.)

And I assume in all cases the mailbox does exists? The one you're sending it with?

Correct. (It's the always the same mailbox and I also tried it with a different one, but the error is the same.)

@scriptkiddy666
Copy link
Author

I'm now using the following workaround without the need for a client secret:

$null = Connect-AzAccount -Identity
[System.Object]$AccessToken = (Get-AzAccessToken -ResourceTypeName 'MSGraph' -AsSecureString -WarningAction 'SilentlyContinue').Token
[System.Object]$Credentials = ConvertTo-GraphCredential -MsalToken ([System.Net.NetworkCredential]::new('', $AccessToken).Password)
[System.String[]]$Attachments = @(XXX)

Send-EmailMessage -From 'XXX' -To 'XXX' -HTML "XXX" -Subject 'XXX' -Graph -ReplyTo "XXX" -Credential $Credentials -Attachment $Attachments -DoNotSaveToSentItems

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

No branches or pull requests

2 participants