implement sendgrid integration in mail service

This commit is contained in:
Simon Larsen 2023-05-04 12:51:15 +01:00
parent 35869893f9
commit 9f93cdedf7
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
11 changed files with 52 additions and 58 deletions

View File

@ -88,20 +88,19 @@ const Accordian: FunctionComponent<ComponentProps> = (
)}
{props.title && (
<div
className={`ml-1 -mt-1 ${props.onClick ? 'cursor-pointer' : ''
}`}
className={`ml-1 -mt-1 ${
props.onClick ? 'cursor-pointer' : ''
}`}
>
<div className="text-gray-500">
{props.title}{' '}
</div>
<div className="mb-2 text-sm">
{props.description && <MarkdownViewer
text={
props.description ||
''
}
/>}
{props.description && (
<MarkdownViewer
text={props.description || ''}
/>
)}
</div>
</div>
)}

View File

@ -90,12 +90,7 @@ const EventItem: FunctionComponent<ComponentProps> = (
</div>
{props.eventDescription && (
<p className="mt-2 text-sm">
<MarkdownViewer
text={
props.eventDescription ||
''
}
/>
<MarkdownViewer text={props.eventDescription || ''} />
</p>
)}
@ -121,7 +116,7 @@ const EventItem: FunctionComponent<ComponentProps> = (
)}
{props.eventResourcesAffected &&
props.eventResourcesAffected?.length > 0 ? (
props.eventResourcesAffected?.length > 0 ? (
<div key={0}>
<div className="flex space-x-1">
<div className="text-sm text-gray-400 mr-3 mt-1">
@ -150,11 +145,12 @@ const EventItem: FunctionComponent<ComponentProps> = (
{props.eventTimeline && props.eventTimeline.length > 0 && (
<div
className={`w-full border-t border-gray-200 mt-5 -ml-5 ${props.eventTimeline &&
props.eventTimeline.length > 0
className={`w-full border-t border-gray-200 mt-5 -ml-5 ${
props.eventTimeline &&
props.eventTimeline.length > 0
? 'mb-5'
: 'mb-0'
} -mr-5 -pr-5`}
} -mr-5 -pr-5`}
style={{ width: 'calc(100% + 2.5em)' }}
></div>
)}
@ -174,12 +170,12 @@ const EventItem: FunctionComponent<ComponentProps> = (
{i !==
props.eventTimeline
.length -
1 && (
<span
className="absolute top-5 left-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
)}
1 && (
<span
className="absolute top-5 left-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
)}
<div className="relative flex items-start space-x-3">
<div>
<div className="relative px-1">
@ -246,12 +242,12 @@ const EventItem: FunctionComponent<ComponentProps> = (
{i !==
props.eventTimeline
.length -
1 && (
<span
className="absolute top-5 left-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
)}
1 && (
<span
className="absolute top-5 left-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
></span>
)}
<div className="relative flex items-start space-x-3">
<div>
<div className="relative px-1">

View File

@ -26,5 +26,4 @@ export const InternalSmtpFromEmail: Email = new Email(
export const InternalSmtpFromName: string =
process.env['INTERNAL_SMTP_NAME'] || '';
export const SendGridApiKey: string =
process.env['SENDGRID_API_KEY'] || '';
export const SendGridApiKey: string = process.env['SENDGRID_API_KEY'] || '';

View File

@ -16,7 +16,7 @@ import { JSONObject } from 'Common/Types/JSON';
import logger from 'CommonServer/Utils/Logger';
import { IsDevelopment } from 'CommonServer/Config';
import { SendGridApiKey } from '../Config';
import SendgridMail from '@sendgrid/mail';
import SendgridMail, { MailDataRequired } from '@sendgrid/mail';
Handlebars.registerHelper('ifCond', function (v1, v2, options) {
if (v1 === v2) {
@ -117,8 +117,8 @@ export default class MailService {
};
}
public static getGlobalFromEmail(){
const emailServer = this.getGlobalSmtpSettings();
public static getGlobalFromEmail(): Email {
const emailServer: EmailServer = this.getGlobalSmtpSettings();
return emailServer.fromEmail;
}
@ -202,8 +202,6 @@ export default class MailService {
mail: EmailMessage,
emailServer?: EmailServer
): Promise<void> {
// default vars.
if (!mail.vars) {
mail.vars = {};
@ -218,18 +216,18 @@ export default class MailService {
: this.compileText(mail.body || '', mail.vars);
mail.subject = this.compileText(mail.subject, mail.vars);
if(!emailServer && SendGridApiKey){
if (!emailServer && SendGridApiKey) {
SendgridMail.setApiKey(SendGridApiKey);
const msg = {
to: mail.toEmail.toString(), // Change to your recipient
from: this.getGlobalFromEmail().toString(), // Change to your verified sender
const msg: MailDataRequired = {
to: mail.toEmail.toString(),
from: this.getGlobalFromEmail().toString(),
subject: mail.subject,
html: mail.body,
}
};
await SendgridMail.send(msg)
return;
await SendgridMail.send(msg);
return;
}
if (!emailServer) {

View File

@ -185,7 +185,8 @@ export default class IncidentCustomField extends BaseModel {
required: false,
type: TableColumnType.LongText,
title: 'Description',
description: 'Friendly description of this custom field that will help you remember',
description:
'Friendly description of this custom field that will help you remember',
})
@Column({
nullable: true,

View File

@ -185,7 +185,8 @@ export default class MonitorCustomField extends BaseModel {
required: false,
type: TableColumnType.LongText,
title: 'Description',
description: 'Friendly description of this custom field that will help you remember',
description:
'Friendly description of this custom field that will help you remember',
})
@Column({
nullable: true,

View File

@ -211,7 +211,8 @@ export default class ScheduledMaintenance extends BaseModel {
required: false,
type: TableColumnType.Description,
title: 'Description',
description: 'Description of this scheduled event that will show up on Status Page. This is in markdown.',
description:
'Description of this scheduled event that will show up on Status Page. This is in markdown.',
})
@Column({
nullable: true,

View File

@ -185,7 +185,8 @@ export default class ScheduledMaintenanceCustomField extends BaseModel {
required: false,
type: TableColumnType.LongText,
title: 'Description',
description: 'Friendly description of this custom field that will help you remember',
description:
'Friendly description of this custom field that will help you remember',
})
@Column({
nullable: true,

View File

@ -185,7 +185,8 @@ export default class StatusPageCustomField extends BaseModel {
required: false,
type: TableColumnType.LongText,
title: 'Description',
description: 'Friendly description of this custom field that will help you remember',
description:
'Friendly description of this custom field that will help you remember',
})
@Column({
nullable: true,

View File

@ -288,7 +288,8 @@ export default class StatusPageGroup extends BaseModel {
required: false,
type: TableColumnType.LongText,
title: 'Description',
description: 'Description for this group. This is visible on Status Page. This can be in markdown format.',
description:
'Description for this group. This is visible on Status Page. This can be in markdown format.',
})
@Column({
nullable: true,

View File

@ -62,13 +62,9 @@ const MonitorOverview: FunctionComponent<ComponentProps> = (
)}
</div>
<div className="mb-2 text-sm">
{props.description && <MarkdownViewer
text={
props.description ||
''
}
/>}
{props.description && (
<MarkdownViewer text={props.description || ''} />
)}
</div>
</div>
{props.showHistoryChart && (