47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import axios, { AxiosInstance } from 'axios';
|
|
import config from '../../config/config';
|
|
|
|
interface EmailRecipient {
|
|
email: string;
|
|
name?: string;
|
|
}
|
|
|
|
interface EmailOptions {
|
|
recipients: EmailRecipient[];
|
|
subject: string;
|
|
htmlContent: string;
|
|
}
|
|
|
|
class BrevoService {
|
|
private readonly instance: AxiosInstance;
|
|
|
|
constructor() {
|
|
this.instance = axios.create({
|
|
baseURL: config.email.BrevobaseURL,
|
|
headers: {
|
|
'api-key': config.email.api_key,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
}
|
|
|
|
async sendEmail(options: EmailOptions): Promise<{ messageId: string }> {
|
|
const response = await this.instance.post('/smtp/email', {
|
|
sender: {
|
|
name: 'Minglar',
|
|
email: 'minglar.admin@minglargroup.com',
|
|
},
|
|
to: options.recipients,
|
|
subject: options.subject,
|
|
htmlContent: options.htmlContent,
|
|
replyTo: {
|
|
email: 'minglar.admin@minglargroup.com',
|
|
},
|
|
});
|
|
|
|
return response.data;
|
|
}
|
|
}
|
|
|
|
export const brevoService = new BrevoService();
|