Skip to content

Commit

Permalink
Merge pull request #15 from NIAEFEUP/feature/allow-email-sending
Browse files Browse the repository at this point in the history
Feature/allow email sending
  • Loading branch information
limwa authored Dec 27, 2024
2 parents 2e413c4 + fd43d1d commit f0c7808
Show file tree
Hide file tree
Showing 12 changed files with 1,348 additions and 16 deletions.
15 changes: 15 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
website:
build:
context: .
dockerfile: deploy/Dockerfile.website
container_name: enei-website
ports:
- "3333:3333"

website-nginx:
build:
context: .
dockerfile: deploy/Dockerfile.nginx
ports:
- "80:80"
18 changes: 5 additions & 13 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
services:
website:
build:
context: .
dockerfile: deploy/Dockerfile.website
container_name: enei-website
mailpit:
image: axllent/mailpit
container_name: enei-mailpit
ports:
- "3333:3333"

website-nginx:
build:
context: .
dockerfile: deploy/Dockerfile.nginx
ports:
- "80:80"
- "1025:1025"
- "8025:8025"
7 changes: 6 additions & 1 deletion website/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ HOST=localhost
LOG_LEVEL=info
APP_KEY=
NODE_ENV=development
SESSION_DRIVER=cookie
SESSION_DRIVER=cookie
SMTP_HOST=localhost
SMTP_PORT=1025
MAILGUN_API_KEY=
MAILGUN_DOMAIN=
FROM_EMAIL=
7 changes: 6 additions & 1 deletion website/adonisrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export default defineConfig({
| will be scanned automatically from the "./commands" directory.
|
*/
commands: [() => import('@adonisjs/core/commands'), () => import('@adonisjs/lucid/commands')],
commands: [
() => import('@adonisjs/core/commands'),
() => import('@adonisjs/lucid/commands'),
() => import('@adonisjs/mail/commands'),
],

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -38,6 +42,7 @@ export default defineConfig({
() => import('@adonisjs/lucid/database_provider'),
() => import('@adonisjs/auth/auth_provider'),
() => import('@adonisjs/inertia/inertia_provider'),
() => import('@adonisjs/mail/mail_provider'),
],

/*
Expand Down
31 changes: 31 additions & 0 deletions website/app/mails/example_e_notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import env from '#start/env'
import { BaseMail } from '@adonisjs/mail'

export default class ExampleENotification extends BaseMail {
private userEmail: string

from = env.get('FROM_EMAIL')
subject = 'This is an example email'

constructor(userEmail: string) {
super()

this.userEmail = userEmail
}

/**
* The "prepare" method is called automatically when
* the email is sent or queued.
*/
async prepare() {
this.message
.to(this.userEmail)
.subject(this.subject)
.htmlView('emails/example_email_html', {
userEmail: this.userEmail,
})
.textView('emails/example_email_text', {
userEmail: this.userEmail,
})
}
}
65 changes: 65 additions & 0 deletions website/config/mail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import env from '#start/env'
import { defineConfig, transports } from '@adonisjs/mail'

const mailConfig = defineConfig({
default: 'smtp',

/**
* The mailers object can be used to configure multiple mailers
* each using a different transport or same transport with different
* options.
*/
mailers: {
smtp: transports.smtp({
host: env.get('SMTP_HOST'),
port: env.get('SMTP_PORT'),
/**
* Uncomment the auth block if your SMTP
* server needs authentication
*/
/* auth: {
type: 'login',
user: env.get('SMTP_USERNAME'),
pass: env.get('SMTP_PASSWORD'),
}, */
}),

/*ses: transports.ses({
apiVersion: '2010-12-01',
region: env.get('AWS_REGION'),
credentials: {
accessKeyId: env.get('AWS_ACCESS_KEY_ID'),
secretAccessKey: env.get('AWS_SECRET_ACCESS_KEY'),
},
sendingRate: 10,
maxConnections: 5,
}),
mailgun: transports.mailgun({
key: env.get('MAILGUN_API_KEY'),
baseUrl: 'https://api.mailgun.net/v3',
domain: env.get('MAILGUN_DOMAIN'),
}),
sparkpost: transports.sparkpost({
key: env.get('SPARKPOST_API_KEY'),
baseUrl: 'https://api.sparkpost.com/api/v1',
}),
brevo: transports.brevo({
key: env.get('BREVO_API_KEY'),
baseUrl: 'https://api.brevo.com/v3',
}),
resend: transports.resend({
key: env.get('RESEND_API_KEY'),
baseUrl: 'https://api.resend.com',
}),*/
},
})

export default mailConfig

declare module '@adonisjs/mail/types' {
export interface MailersList extends InferMailers<typeof mailConfig> {}
}
2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
"@adonisjs/cors": "^2.2.1",
"@adonisjs/inertia": "^2.1.0",
"@adonisjs/lucid": "^21.5.1",
"@adonisjs/mail": "^9.2.2",
"@adonisjs/session": "^7.5.0",
"@adonisjs/shield": "^8.1.1",
"@adonisjs/static": "^1.1.1",
"@adonisjs/vite": "^4.0.0",
"@aws-sdk/client-ses": "^3.716.0",
"@hookform/resolvers": "^3.9.1",
"@inertiajs/react": "^2.0.0",
"@radix-ui/react-accordion": "^1.2.2",
Expand Down
Loading

0 comments on commit f0c7808

Please sign in to comment.