Mail with File Attachments don't work - attachments content doesn't get serialized.
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- api
Research direction
Start with packages/msgraph-sdk/models/index.ts and inspect serializeFileAttachment, especially how isSerializingDerivedType affects contentBytes. Run the supplied TypeScript send-mail reproduction with SDK version 1.0.0-preview.64. Done means the attachment contentBytes is serialized and the mail sends successfully without the missing-property error.
Written by the indexing model from the issue text.
Description
Describe the bug
I am trying to send a Mail with an Image-Attachment via the Graph SDK. This is what my Test-Code looks like:
import { ClientSecretCredential } from "@azure/identity";
import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure";
import {
createGraphServiceClient,
GraphRequestAdapter,
} from "@microsoft/msgraph-sdk";
import { SendMailPostRequestBody } from "@microsoft/msgraph-sdk-users/users/item/sendMail/index.js";
import "@microsoft/msgraph-sdk-users";
import { FileAttachment } from "@microsoft/msgraph-sdk/models/index.js";
import fs from "fs";
const fromRecipient = "<[email protected]>";
const toRecipient = "<[email protected]>";
const credential = new ClientSecretCredential(
<tenantId>,
<clientId>,
<clientSecret>
);
// @microsoft/kiota-authentication-azure
const authProvider = new AzureIdentityAuthenticationProvider(credential, [
"https://graph.microsoft.com/.default",
]);
const requestAdapter = new GraphRequestAdapter(authProvider);
const client = createGraphServiceClient(requestAdapter);
const fileBuffer = fs.readFileSync("test.jpeg");
const fileAttachment: FileAttachment = {
odataType: "#microsoft.graph.fileAttachment",
name: "test.jpg",
contentType: "image/jpeg",
contentBytes: fileBuffer,
size: fileBuffer.byteLength,
};
const body: SendMailPostRequestBody = {
message: {
subject: "Testmail",
body: {
content:
'<style type="text/css">html, p { font-size:14px !important; font-family: Arial, Helvetica, sans-serif !important; }</style><p>this is a test message</p>',
contentType: "html",
},
hasAttachments: true,
toRecipients: [
{
emailAddress: {
address: toRecipient,
},
},
],
attachments: [fileAttachment],
},
};
try {
const user = client.users.byUserId(fromRecipient);
const mail = user.sendMail;
await mail.post(body);
console.log("done");
} catch (error) {
console.log(error.message);
}
My dependencies are:
"dependencies": {
"@azure/identity": "^4.10.2",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.96",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.96",
"@microsoft/msgraph-sdk": "^1.0.0-preview.64",
"@microsoft/msgraph-sdk-users": "^1.0.0-preview.64",
...
},
When I send this, I get an error with this message: 'Required property is missing.'
I debugged it and saw, that in https://github.com/microsoftgraph/msgraph-sdk-typescript/blob/main/packages/msgraph-sdk/models/index.ts the serializeFileAttachment Function only gets called with isSerializingDerivedType = true which leads to the state where "contentBytes" never gets written.
When i change isSerializingDerivedType to false in debug mode, the mail with the attachments got sent successfully!
Can you please fix that?
Thank you.
Expected behavior
The attachment's "contentBytes" gets written.
How to reproduce
Send a Mail with a File Attachment via Graph SDK - as shown above.
SDK Version
1.0.0-preview.64
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```Required property is missing.
</details>
### Configuration
_No response_
### Other information
_No response_
- Dominant language
- TypeScript
- Stars
- 44
- Forks
- 7
- Avg merge
- 12h 40m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoftgraph/msgraph-sdk-typescript
-
ToTriage type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoftgraph/msgraph-sdk-typescript#917 · 6 comments ·
Maintainers usually reply within 1 day
-
status:waiting-for-triage ToTriage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
microsoftgraph/msgraph-sdk-typescript#974 · 1 comment ·
Maintainers usually reply within 1 day
-
status:waiting-for-triage ToTriage type:bug
Difficulty 4/5 3-5 days Newbie friendliness 25/100
microsoftgraph/msgraph-sdk-typescript#953 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
status:waiting-for-triage ToTriage
Difficulty 5/5 Over a week Newbie friendliness 25/100
microsoftgraph/msgraph-sdk-typescript#912 · 1 comment ·
Maintainers usually reply within 1 day
-
status:waiting-for-triage ToTriage type:feature
Difficulty 3/5 1-2 days Newbie friendliness 48/100
microsoftgraph/msgraph-sdk-typescript#908 ·
Maintainers usually reply within 1 day
All issues in microsoftgraph/msgraph-sdk-typescript
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
aiko-chan-ai/DiscordBotClient#380 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vercel/ai-elements#507 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 Half a day Newbie friendliness 84/100
anaclumos/qa-interns#148 · 1 comment ·
Maintainers usually reply within 1 day