Skip to content

Commit

Permalink
feat: Update email sending function to use MailerSend API
Browse files Browse the repository at this point in the history
  • Loading branch information
niyobern committed May 3, 2024
1 parent e8a32b4 commit 20430ac
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/emails/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ async function sendEmail(emailType: EmailType, recipient: string, data: Data) {
const html = template(data);

// Send the Email
const url = `https://api.mailgun.net/v3/${domain}/messages`

const body = {
'from': `Dynamites Account Team <account@${domain}>`,
'to': [recipient],
'subject': 'Verification Email',
'html': html,
}
const formattedBody = qs.stringify(body);

const response = await axios.post(url, formattedBody, {
auth: {
username: 'api',
password: apiKey
const domain2 = process.env.MAILERSEND_DOMAIN
const key2 = process.env.MAILERSEND_TOKEN
const body2 = {
"from": {

Check failure on line 40 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 40 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 40 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
"email": `info@${domain2}`,

Check failure on line 41 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 41 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 41 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
},
"to": [

Check failure on line 43 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 43 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 43 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
{
"email": recipient

Check failure on line 45 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 45 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 45 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
}
],
"subject": "Verification Email",

Check failure on line 48 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 48 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 48 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 48 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 48 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote

Check failure on line 48 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
"html": html

Check failure on line 49 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Strings must use singlequote

Check failure on line 49 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 49 in src/emails/index.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
}
const mailersend = 'https://api.mailersend.com/v1/email'
const response = await axios.post(mailersend, body2, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${key2}`
}
});
return response
} catch (error) {
Expand Down

0 comments on commit 20430ac

Please sign in to comment.