microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
695 stars 168 forks source link

Send-MgUserMail: issue when sending attachments related to MIME types #1496

Closed v1ctormoreno closed 1 year ago

v1ctormoreno commented 2 years ago

Hello,

I am trying to send a message via Send-MgUserEmail.

When the attachment is an Excel document with macros (with the MIME type specified in the code below), the email is sent and shows up in the Sent Items folder, but it is not received by the recipient, it is returned in exactly 14 minutes. I have seen something similar here: https://docs.microsoft.com/en-us/answers/questions/891752/sending-mail-via-using-graph-api-is-so-slow.html If the attachment is another type of document with another MIME type, it is received correctly.

The attachment is 400 KB, so I am not using createUploadSession (https://docs.microsoft.com/en-us/graph/api/attachment-createuploadsession?view=graph-rest-1.0&tabs=http)

I am using the following code:

$contentBase64 = [convert]::ToBase64String( [system.io.file]::readallbytes($attachmentFile))

$params = @{
    Message = @{
        Subject = "Test Email"
        Body = @{
            ContentType = "HTML"
            Content = "$($bodyHTML)"
        }
        ToRecipients = @(
            @{
                EmailAddress = @{
                    Address = "redacted"
                }
            }
        )
        CcRecipients = @(
            @{
                EmailAddress = @{
                    #Address = "redacted"
                }
            }
        )
       Attachments = @(
            @{
                "@odata.type" = "#microsoft.graph.fileAttachment"
                Name = "Macros.xlsm"
                ContentType = "application/vnd.ms-excel.sheet.macroEnabled.12"
                ContentBytes = "$($contentBase64)"
            }
        )
    }
    SaveToSentItems = "true"
}

Send-MgUserMail -UserId redacted@redacted.tld -BodyParameter $params

The attachment is converted to Base64 with the first line.

Can anyone help with this problem?

Thanks

Bryand13 commented 2 years ago

Hello,

I have the same problem here.

Regards.

peombwa commented 2 years ago

Thanks for following up on this.

As this repository is intended for issues related to the functionality of the SDK, we may not be the best placed to answer some queries that are tied to the functionality of the API.

Please open a support ticket at https://developer.microsoft.com/en-us/graph/support to get help from the API owner. You can find the request-id of the failing request by following the guide at https://docs.microsoft.com/en-us/powershell/microsoftgraph/troubleshooting?view=graph-powershell-1.0#using--debug.

ghost commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.