-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validateemail): add and export validateEmail function
Add validateEmail function which used mailtrap and nodemailer to send emails Resolves #97 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
- Loading branch information
1 parent
ce4ebfa
commit 9c462a4
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { validateEmail } from './validateEmail'; | ||
export type { MailtrapOptions } from './usingMailtrap'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import nodemailer from 'nodemailer'; | ||
|
||
interface Auth { | ||
user: string; | ||
pass: string; | ||
} | ||
|
||
export interface MailtrapOptions { | ||
from: string; | ||
to: string; | ||
subject: string; | ||
HTMLEmail: string; | ||
textEmail?: string; | ||
auth: Auth; | ||
} | ||
|
||
export async function validateEmailUsingMailtrap({ | ||
from, | ||
to, | ||
subject, | ||
HTMLEmail, | ||
textEmail, | ||
auth, | ||
}: MailtrapOptions) { | ||
const transporter = nodemailer.createTransport({ | ||
host: 'smtp.mailtrap.io', | ||
port: 2525, | ||
auth: { | ||
user: auth.user, | ||
pass: auth.pass, | ||
}, | ||
}); | ||
|
||
let info, error; | ||
|
||
try { | ||
const res = await transporter.sendMail({ | ||
from: from, | ||
to: to, | ||
subject: subject, | ||
text: textEmail, | ||
html: HTMLEmail, | ||
}); | ||
|
||
info = res; | ||
} catch (err) { | ||
console.log(err); | ||
error = err; | ||
} | ||
|
||
return { info, error }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { MailtrapOptions } from './usingMailtrap'; | ||
import { validateEmailUsingMailtrap } from './usingMailtrap'; | ||
|
||
export async function validateEmail(options: MailtrapOptions) { | ||
return await validateEmailUsingMailtrap(options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters