Skip to content

Commit

Permalink
perf(validateemail): remove nodemailer and its related dependency
Browse files Browse the repository at this point in the history
Remove nodemailer and whole validateEmail method from the package and add them to the docs

fix #133

Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
  • Loading branch information
niloysikdar committed Feb 24, 2023
1 parent 4e51860 commit 7c4ea63
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ node_modules/
public/
build/
dist/
docs/
.docusaurus/
docs-build/
CHANGELOG.md
example/lib/
Expand Down
46 changes: 23 additions & 23 deletions docusaurus/docs/installation/how-to-install.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
sidebar_position: 1
---

# Install Package

You can install our package using `npm` or `yarn`

## Using npm

Enter the following command into your project directory

```bash
npm install @leopardslab/react-email
```

## Using yarn

You can also use yarn to install the package locally

```bash
yarn add @leopardslab/react-email
```
---
sidebar_position: 1
---

# Install Package

You can install our package using `npm` or `yarn`

## Using npm

Enter the following command into your project directory

```bash
npm install @leopardslab/react-email
```

## Using yarn

You can also use yarn to install the package locally

```bash
yarn add @leopardslab/react-email
```
16 changes: 8 additions & 8 deletions docusaurus/docs/usage/_category_.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"label": "Usage",
"position": 3,
"link": {
"type": "generated-index",
"description": "How to use our package to build responsive email layouts"
}
}
{
"label": "Usage",
"position": 3,
"link": {
"type": "generated-index",
"description": "How to use our package to build responsive email layouts"
}
}
60 changes: 30 additions & 30 deletions docusaurus/docs/usage/how-to-use.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---
sidebar_position: 1
---

# Build Layout

Build simple layouts for Email using our existing components

## Demo

Create your Layout at using TypeScript or JavaScript using in React enviroment:

**In JavaScript**

```jsx title="Layout.js"
import React from 'react';
import { Email, Section, Column, Typography } from '@leopardslab/react-email';

export default function Layout() {
return (
<Email>
<Section>
<Column>
<Typography>Hello World</Typography>
</Column>
</Section>
</Email>
);
}
```
---
sidebar_position: 1
---

# Build Layout

Build simple layouts for Email using our existing components

## Demo

Create your Layout at using TypeScript or JavaScript using in React enviroment:

**In JavaScript**

```jsx title="Layout.js"
import React from 'react';
import { Email, Section, Column, Typography } from '@leopardslab/react-email';

export default function Layout() {
return (
<Email>
<Section>
<Column>
<Typography>Hello World</Typography>
</Column>
</Section>
</Email>
);
}
```
8 changes: 8 additions & 0 deletions docusaurus/docs/validation/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Validation",
"position": 4,
"link": {
"type": "generated-index",
"description": "How to validate your generated email templates"
}
}
98 changes: 98 additions & 0 deletions docusaurus/docs/validation/using-mailtrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
sidebar_position: 1
---

# Using Mailtrap

Validate your generated emails using [Mailtrap](https://mailtrap.io)

After creating an account on Mailtrap, you can create an inbox and get the SMTP credentials.

Send the generated emails to the Mailtrap inbox and validate them to check the **spam score, email preview, and other details**.

Also, you need [nodemailer](https://www.npmjs.com/package/nodemailer) package to send emails.

```tsx title="usingMailtrap.ts"
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 };
}
```

Import the `validateEmailUsingMailtrap` function and pass the required parameters.

```tsx title="index.ts"
import { validateEmailUsingMailtrap } from './usingMailtrap';

async function validate() {
const { info, error } = await validateEmailUsingMailtrap({
from: 'From email address',
to: 'To email address',
subject: 'Test Email',
HTMLEmail: 'Generated HTML email',
textEmail: 'Text version of the email',
auth: {
user: 'Mailtrap username',
pass: 'Mailtrap password',
},
});

if (error) {
console.log(error);
} else {
console.log(info);
}
}

validate();
```

This will help you to check the spam score and other details of the generated email before sending it to the actual recipients.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"@types/html-to-text": "^8.1.0",
"@types/jest": "^28.1.3",
"@types/node": "^18.0.0",
"@types/nodemailer": "^6.4.5",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@typescript-eslint/eslint-plugin": "^5.28.0",
Expand All @@ -93,7 +92,6 @@
"husky": "^8.0.0",
"jest": "^28.1.1",
"lint-staged": "^13.0.2",
"nodemailer": "^6.7.8",
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 0 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ export type { CSSClasses } from './makeStyles';
export { generateEmail } from './generateEmail';
export { generateTextEmailFromHTML } from './generateTextEmailFromHTML';
export { generateTextEmail } from './generateTextEmail';
export { validateEmail } from './validateEmail';
export type { MailtrapOptions } from './validateEmail';
2 changes: 0 additions & 2 deletions src/utils/validateEmail/index.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/utils/validateEmail/usingMailtrap.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/utils/validateEmail/validateEmail.ts

This file was deleted.

12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4508,13 +4508,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.41.tgz#88eb485b1bfdb4c224d878b7832239536aa2f813"
integrity sha512-mqoYK2TnVjdkGk8qXAVGc/x9nSaTpSrFaGFm43BUH3IdoBV0nta6hYaGmdOvIMlbHJbUEVen3gvwpwovAZKNdQ==

"@types/nodemailer@^6.4.5":
version "6.4.5"
resolved "https://registry.yarnpkg.com/@types/nodemailer/-/nodemailer-6.4.5.tgz#09011ac73259245475d1688e4ba101860567dc39"
integrity sha512-zuP3nBRQHI6M2PkXnGGy1Ww4VB+MyYHGgnfV2T+JR9KLkeWqPJuyVUgLpKXuFnA/b7pZaIDFh2sV4759B7jK1g==
dependencies:
"@types/node" "*"

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
Expand Down Expand Up @@ -12155,11 +12148,6 @@ node-releases@^2.0.5:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.5.tgz#280ed5bc3eba0d96ce44897d8aee478bfb3d9666"
integrity sha512-U9h1NLROZTq9uE1SNffn6WuPDg8icmi3ns4rEl/oTfIle4iLjTliCzgTsbaIFMq/Xn078/lfY/BL0GWZ+psK4Q==

nodemailer@^6.7.8:
version "6.7.8"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.7.8.tgz#9f1af9911314960c0b889079e1754e8d9e3f740a"
integrity sha512-2zaTFGqZixVmTxpJRCFC+Vk5eGRd/fYtvIR+dl5u9QXLTQWGIf48x/JXvo58g9sa0bU6To04XUv554Paykum3g==

nopt@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88"
Expand Down

0 comments on commit 7c4ea63

Please sign in to comment.