lib/mailer
Ce contenu n’est pas encore disponible dans votre langue.
Interfaces
Section titled “Interfaces”MailerConfig
Section titled “MailerConfig”Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:84
Configuration interface for the mailer.
Properties
Section titled “Properties”sender
Section titled “sender”sender: string;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:93
The email address of the sender.
transporter
Section titled “transporter”transporter: TransporterConfig;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:88
The configuration object for the mail transporter.
MailOptions
Section titled “MailOptions”Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:99
Interface representing the options for sending an email.
Properties
Section titled “Properties”optional html: string;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:118
The HTML content of the email. Optional.
subject
Section titled “subject”subject: string;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:108
The subject of the email.
optional text: string;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:113
The plain text content of the email. Optional.
to: string | string[];
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:103
The recipient(s) of the email. Can be a single email address or an array of email addresses.
TransporterConfig
Section titled “TransporterConfig”Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:29
Configuration options for the mail transporter.
Properties
Section titled “Properties”auth: { pass: string; user: string;};
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:53
Authentication details for the SMTP server.
optional pass: string;
The password for authentication.
optional user: string;
The username for authentication.
host: string;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:33
The hostname or IP address of the SMTP server.
port: number;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:38
The port number to connect to the SMTP server.
proxy?
Section titled “proxy?”optional proxy: string;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:48
The proxy URL to use for the connection (optional).
secure
Section titled “secure”secure: boolean;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:43
If true, the connection will use TLS when connecting to the server.
optional tls: { rejectUnauthorized: boolean; servername: string;};
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:68
TLS configuration options (optional).
rejectUnauthorized?
Section titled “rejectUnauthorized?”optional rejectUnauthorized: boolean;
If true, the server certificate will not be validated (optional).
servername?
Section titled “servername?”optional servername: string;
The server name for SNI (optional).
Type Aliases
Section titled “Type Aliases”MailerResponse
Section titled “MailerResponse”type MailerResponse = MailerSuccessResponse | MailerErrorResponse;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:138
Interface representing the response from a mail verification operation.
tsMailer
Section titled “tsMailer”type tsMailer = typeof tsMailerConfig.$inferSelect;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:19
TypeSafe Table definition for use in StudioCMS Integrations
tsMailerInsert
Section titled “tsMailerInsert”type tsMailerInsert = Omit<typeof tsMailerConfig.$inferInsert, "id">;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:24
TypeSafe Table definition for use in StudioCMS Integrations
Variables
Section titled “Variables”tsMailerConfig
Section titled “tsMailerConfig”const tsMailerConfig: Table<"StudioCMSMailerConfig", { auth_pass: { type: "text"; }; auth_user: { type: "text"; }; default_sender: { type: "text"; }; host: { type: "text"; }; id: { type: "text"; }; port: { type: "number"; }; proxy: { type: "text"; }; secure: { type: "boolean"; }; tls_rejectUnauthorized: { type: "boolean"; }; tls_servername: { type: "text"; };}>;
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:14
TypeSafe Table definition for use in StudioCMS Integrations
Functions
Section titled “Functions”createMailerConfigTable()
Section titled “createMailerConfigTable()”function createMailerConfigTable(config: tsMailerInsert): Promise< | MailerErrorResponse | { auth_pass: null | string; auth_user: null | string; default_sender: string; host: string; id: string; port: number; proxy: null | string; secure: boolean; tls_rejectUnauthorized: null | boolean; tls_servername: null | string;}>
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:201
Creates a new mailer configuration in the database.
Parameters
Section titled “Parameters”config
Section titled “config”The mailer configuration object to create.
Returns
Section titled “Returns”Promise
<
| MailerErrorResponse
| {
auth_pass
: null
| string
;
auth_user
: null
| string
;
default_sender
: string
;
host
: string
;
id
: string
;
port
: number
;
proxy
: null
| string
;
secure
: boolean
;
tls_rejectUnauthorized
: null
| boolean
;
tls_servername
: null
| string
;
}>
A promise that resolves with the new mailer configuration object.
getMailerConfigTable()
Section titled “getMailerConfigTable()”function getMailerConfigTable(): Promise< | undefined | { auth_pass: null | string; auth_user: null | string; default_sender: string; host: string; id: string; port: number; proxy: null | string; secure: boolean; tls_rejectUnauthorized: null | boolean; tls_servername: null | string;}>
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:175
Gets the mailer configuration from the database.
Returns
Section titled “Returns”Promise
<
| undefined
| {
auth_pass
: null
| string
;
auth_user
: null
| string
;
default_sender
: string
;
host
: string
;
id
: string
;
port
: number
;
proxy
: null
| string
;
secure
: boolean
;
tls_rejectUnauthorized
: null
| boolean
;
tls_servername
: null
| string
;
}>
A promise that resolves with the mailer configuration object.
isMailerEnabled()
Section titled “isMailerEnabled()”function isMailerEnabled(): Promise<boolean>
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:397
Checks if the mailer service is enabled in the StudioCMS configuration.
This function retrieves the configuration from the StudioCMS SDK and
returns the value of the enableMailer
property. If the configuration
is not available, it defaults to false
.
Returns
Section titled “Returns”Promise
<boolean
>
A promise that resolves to true
if the mailer
service is enabled, otherwise false
.
sendMail()
Section titled “sendMail()”function sendMail(mailOptions: MailOptions): Promise<MailerResponse>
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:285
Sends an email using the provided mailer configuration and mail options.
Parameters
Section titled “Parameters”mailOptions
Section titled “mailOptions”The options for the mail, including the subject and other message details.
Returns
Section titled “Returns”Promise
<MailerResponse
>
A promise that resolves with the result of the mail sending operation.
Throws
Section titled “Throws”Will throw an error if the mail sending operation fails.
Example
Section titled “Example”const mailOptions = { subject: 'Test Email', text: 'This is a test email.'};
sendMail(mailerConfig, mailOptions) .then(result => console.log('Email sent:', result)) .catch(error => console.error('Error sending email:', error));
updateMailerConfigTable()
Section titled “updateMailerConfigTable()”function updateMailerConfigTable(config: tsMailerInsert): Promise<MailerResponse>
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:184
Updates the mailer configuration in the database.
Parameters
Section titled “Parameters”config
Section titled “config”The new mailer configuration object.
Returns
Section titled “Returns”Promise
<MailerResponse
>
A promise that resolves when the mailer configuration has been updated.
verifyMailConnection()
Section titled “verifyMailConnection()”function verifyMailConnection(): Promise<MailerResponse>
Defined in: studiocms/packages/studiocms/src/lib/mailer/index.ts:351
Verifies the mail connection using the provided transporter configuration.
Returns
Section titled “Returns”Promise
<MailerResponse
>
A promise that resolves to an object containing either a success message or an error message.
Example
Section titled “Example”const result = await verifyMailConnection();if ('message' in result) { console.log(result.message);} else { console.error(result.error);}