Kryptonian
Sending email with SMTP and Deno, with InReplyTo headers failing
It seems that currently it's not possible to send emails using denomailer with InReplyTo headers, as it chockes on the
in
in the header name.
Any other ideas as to how I should do sending email?
I'm using the following code currently, or trying to:
import { SMTPClient as DenoMailerSMTPClient } from "https://deno.land/x/denomailer@1.6.0/mod.ts";
type Smtp = {
host: string;
port: number;
};
type EmailObject = {
from: string;
cc?: string;
subject: string;
content: string;
inReplyTo?: string; // Added inReplyTo field
references?: string; // Added references field
};
export async function send_smtp_email(
smtp_res: Smtp,
to_email: string,
from_email: string,
subject: string,
content: string,
cc_email?: string,
inReplyTo?: string,
references?: string,
) {
const client = new DenoMailerSMTPClient({
debug: {
allowUnsecure: true,
},
connection: {
hostname: smtp_res.host,
port: smtp_res.port,
},
});
const headers: { [key: string]: string } = {
from: from_email,
to: to_email,
cc: cc_email || '', // Use the cc_email parameter here
subject: subject,
inReplyTo: inReplyTo || '', // Add In-Reply-To header if provided
references: references || '', // Add References header if provided
};
await client.send({
headers,
content,
});
await client.close();
return `Email sent from ${from_email} to ${to_email}`;
}
export async function main(email: EmailObject, smtpResource: Smtp) {
if (email != null) {
const currentDate = new Date().toLocaleDateString("fi-FI");
const emailBody = "Hei"
`On ${currentDate}, ${email.from} wrote:\n` +
`\"${email.content}\"\n\n`
const sendEmail = await send_smtp_email(
smtpResource,
email.from,
"sender",
`Re: ${email.subject}`,
emailBody,
"cc",
email.inReplyTo,
email.references,
);
return sendEmail;
} else {
return "NOOP";
}
}
import { SMTPClient as DenoMailerSMTPClient } from "https://deno.land/x/denomailer@1.6.0/mod.ts";
type Smtp = {
host: string;
port: number;
};
type EmailObject = {
from: string;
cc?: string;
subject: string;
content: string;
inReplyTo?: string; // Added inReplyTo field
references?: string; // Added references field
};
export async function send_smtp_email(
smtp_res: Smtp,
to_email: string,
from_email: string,
subject: string,
content: string,
cc_email?: string,
inReplyTo?: string,
references?: string,
) {
const client = new DenoMailerSMTPClient({
debug: {
allowUnsecure: true,
},
connection: {
hostname: smtp_res.host,
port: smtp_res.port,
},
});
const headers: { [key: string]: string } = {
from: from_email,
to: to_email,
cc: cc_email || '', // Use the cc_email parameter here
subject: subject,
inReplyTo: inReplyTo || '', // Add In-Reply-To header if provided
references: references || '', // Add References header if provided
};
await client.send({
headers,
content,
});
await client.close();
return `Email sent from ${from_email} to ${to_email}`;
}
export async function main(email: EmailObject, smtpResource: Smtp) {
if (email != null) {
const currentDate = new Date().toLocaleDateString("fi-FI");
const emailBody = "Hei"
`On ${currentDate}, ${email.from} wrote:\n` +
`\"${email.content}\"\n\n`
const sendEmail = await send_smtp_email(
smtpResource,
email.from,
"sender",
`Re: ${email.subject}`,
emailBody,
"cc",
email.inReplyTo,
email.references,
);
return sendEmail;
} else {
return "NOOP";
}
}
5 replies