export type SmtpConnectionDto = {emailAddress: string, password: string, host: string, port: number, encryption: 'TLS' | 'SSL', userName: string}; export type ImapConnectionDto = {emailAddress: string, password: string, host: string, port: number, encryption: 'TLS' | 'SSL'}; export type ConnectEmailAccountPayloadDto = {smtp: SmtpConnectionDto, imap: ImapConnectionDto}; export type ConnectEmailAccountDto = {emailServiceProvider: 'gmail' | 'microsoft' | 'gsuite' | 'o365' | 'yahoo' | 'zoho' | 'godaddy' | 'yandex' | 'sendgrid' | 'other', fromName: string, fromFirstName: string, fromLastName: string, payload: ConnectEmailAccountPayloadDto}; export type CreateApiV1EmailAccountsSmtpImapConnectArgs = {body: ConnectEmailAccountDto}; export type CreateApiV1EmailAccountsSmtpImapConnectOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Connect an SMTP/IMAP email account * * POST /v1/email-accounts/smtp-imap/connect */ export const createApiV1EmailAccountsSmtpImapConnect = async (args: CreateApiV1EmailAccountsSmtpImapConnectArgs, options: CreateApiV1EmailAccountsSmtpImapConnectOptions) => { const {baseUrl, fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/email-accounts/smtp-imap/connect${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };