import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Create Draft Email
* Create a draft in the Drafts folder, with optional recipients and file attachments from object storage (about 3 MB in total). Returns the draft message; send it with Send Draft. Requires Mail.ReadWrite (a connection default).
*/
export async function main(
auth: RT.MsOutlook,
subject: string,
body: string,
content_type: "HTML" | "Text" = "HTML",
to: string[] | undefined,
cc: string[] | undefined,
bcc: string[] | undefined,
attachments: S3Object[] | undefined,
mailbox: string | undefined
) {
const base = `https://graph.microsoft.com/v1.0/${
mailbox != null && mailbox !== ""
? `users/${encodeURIComponent(mailbox)}`
: "me"
}`
const recipients = (addresses: string[] | undefined) =>
(addresses ?? [])
.filter((a) => a != null && a.trim() !== "")
.map((address) => ({ emailAddress: { address } }))
const files = []
for (const file of attachments ?? []) {
const bytes = await wmill.loadS3File(file)
if (!bytes) throw new Error(`Could not load ${file.s3}`)
files.push({
"@odata.type": "#microsoft.graph.fileAttachment",
name: file.s3.split("/").pop(),
contentBytes: Buffer.from(bytes).toString("base64"),
})
}
const response = await fetch(`${base}/messages`, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
subject,
body: { contentType: content_type, content: body },
toRecipients: recipients(to),
ccRecipients: recipients(cc),
bccRecipients: recipients(bcc),
attachments: files,
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago
import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Create Draft Email
* Create a draft in the Drafts folder, with optional recipients and file attachments from object storage (about 3 MB in total). Returns the draft message; send it with Send Draft. Requires Mail.ReadWrite (a connection default).
*/
export async function main(
auth: RT.Outlook,
subject: string,
body: string,
content_type: "HTML" | "Text" = "HTML",
to: string[] | undefined,
cc: string[] | undefined,
bcc: string[] | undefined,
attachments: S3Object[] | undefined,
mailbox: string | undefined
) {
const base = `https://graph.microsoft.com/v1.0/${
mailbox != null && mailbox !== ""
? `users/${encodeURIComponent(mailbox)}`
: "me"
}`
const recipients = (addresses: string[] | undefined) =>
(addresses ?? [])
.filter((a) => a != null && a.trim() !== "")
.map((address) => ({ emailAddress: { address } }))
const files = []
for (const file of attachments ?? []) {
const bytes = await wmill.loadS3File(file)
if (!bytes) throw new Error(`Could not load ${file.s3}`)
files.push({
"@odata.type": "#microsoft.graph.fileAttachment",
name: file.s3.split("/").pop(),
contentBytes: Buffer.from(bytes).toString("base64"),
})
}
const response = await fetch(`${base}/messages`, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
subject,
body: { contentType: content_type, content: body },
toRecipients: recipients(to),
ccRecipients: recipients(cc),
bccRecipients: recipients(bcc),
attachments: files,
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 11 hours ago
import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Create Draft Email
* Create a draft in the Drafts folder, with optional recipients and file attachments from object storage (about 3 MB in total). Returns the draft message; send it with Send Draft. Requires Mail.ReadWrite on the connection.
*/
export async function main(
auth: RT.Outlook,
subject: string,
body: string,
content_type: "HTML" | "Text" = "HTML",
to: string[] | undefined,
cc: string[] | undefined,
bcc: string[] | undefined,
attachments: S3Object[] | undefined,
mailbox: string | undefined
) {
const base = `https://graph.microsoft.com/v1.0/${
mailbox != null && mailbox !== ""
? `users/${encodeURIComponent(mailbox)}`
: "me"
}`
const recipients = (addresses: string[] | undefined) =>
(addresses ?? [])
.filter((a) => a != null && a.trim() !== "")
.map((address) => ({ emailAddress: { address } }))
const files = []
for (const file of attachments ?? []) {
const bytes = await wmill.loadS3File(file)
if (!bytes) throw new Error(`Could not load ${file.s3}`)
files.push({
"@odata.type": "#microsoft.graph.fileAttachment",
name: file.s3.split("/").pop(),
contentBytes: Buffer.from(bytes).toString("base64"),
})
}
const response = await fetch(`${base}/messages`, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
subject,
body: { contentType: content_type, content: body },
toRecipients: recipients(to),
ccRecipients: recipients(cc),
bccRecipients: recipients(bcc),
attachments: files,
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 11 hours ago