import { gmail } from "@googleapis/gmail";
//#region src/sync/gmail-sender.ts
function buildMime(opts) {
	const contentType = opts.isHtml !== false ? "text/html; charset=utf-8" : "text/plain; charset=utf-8";
	return `${[
		`To: ${opts.to}`,
		...opts.cc && opts.cc.length > 0 ? [`Cc: ${opts.cc.join(", ")}`] : [],
		`Subject: ${opts.subject}`,
		`Content-Type: ${contentType}`,
		`MIME-Version: 1.0`,
		...opts.replyToMessageId ? [`In-Reply-To: ${opts.replyToMessageId}`, `References: ${opts.replyToMessageId}`] : []
	].join("\r\n")}\r\n\r\n${opts.body}`;
}
async function sendEmail(opts) {
	const gmail$1 = gmail({
		version: "v1",
		auth: opts.auth
	});
	const raw = Buffer.from(buildMime(opts)).toString("base64url");
	const res = await gmail$1.users.messages.send({
		userId: "me",
		requestBody: { raw }
	});
	return {
		messageId: res.data.id ?? "",
		threadId: res.data.threadId ?? ""
	};
}
//#endregion
export { sendEmail };

//# sourceMappingURL=gmail-sender-StTpJ9Ub.js.map