Functions:SMTP - bettyblocks/cli GitHub Wiki
SMTP
In order to connect to SMTP servers and send e-mails the runtime exposes the smtp helper. This helper connects to an SMTP server of your choice and sends an e-mail.
The smtp helper expects the following arguments: an object containing the SMTP configuration and an object containing the details for the e-mail you want to send. It returns a promise that once resolved, results in an object containing information about the sent e-mail.
interface Credentials {
host: string;
port: number;
username: string;
password: string;
secure?: boolean;
ignoreTLS?: boolean;
requireTLS: boolean;
}
interface Options {
sender: {
from: string;
replyTo?: string;
};
recipient: {
to: string | string[];
cc?: string | string[];
bcc?: string | string[];
};
subject: string;
body: string;
attachments?: {
filename: string;
path: string;
}[];
}
const smtp = async (credentials: Credentials, mailDetails: Options): Promise<SMTPPool.SentMessageInfo | Error>
The helper function uses nodemailer, see SMTP transport: Nodemailer for documentation on the SMTPCredentials.
Function example:
const sendMail = async ({
host,
port,
username,
password,
from,
replyTo,
to,
cc,
bcc,
subject,
body,
}) => {
const result = await smtp(
{
host,
port,
username,
password,
requireTLS: true
},
{
sender: {
from,
replyTo,
},
recipient: {
to,
cc,
bcc,
},
subject,
body,
attachments: [
{
filename: 'The name and extension for the file',
path: 'Url of the file',
},
]
}
);
return { result };
};
export default sendMail;
If you want to use a name in the from, to, cc, and bcc fields you can add it using "John Doe" [email protected]