Skip to content

Commit

Permalink
feat: back to street legal
Browse files Browse the repository at this point in the history
  • Loading branch information
tuturd committed Nov 7, 2024
1 parent e170827 commit 4ca6419
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
14 changes: 8 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ DATABASE_URL=mysql://root:root@localhost/arena
# Used in mail templates
ARENA_WEBSITE=http://localhost:8080

# SMTP server address (smtp://user:password@host(:port)?)
# You can use Nodemailer App (https://nodemailer.com/app/) or mailtrap.io to test the emails
SMTP_URI=smtp://user:pass@address:25/?pool=true&maxConnections=1
GMAIL=false
GMAIL_USERNAME=[email protected]
GMAIL_PASSWORD=
MAX_MAILS_PER_BATCH=100
EMAIL_HOST=
EMAIL_PORT=
EMAIL_SECURE=
EMAIL_SENDER_NAME=
EMAIL_SENDER_ADDRESS=
EMAIL_AUTH_USER=
EMAIL_AUTH_PASSWORD=
EMAIL_REJECT_UNAUTHORIZED=

# Used to give a discount on tickets
PARTNER_MAILS=utt.fr,utc.fr,utbm.fr
Expand Down
21 changes: 12 additions & 9 deletions src/services/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ export const getEmailsLogs = async () =>
user: RawUser;
})[];

const emailOptions = env.email.gmail
? {
service: 'gmail',
auth: {
user: env.email.username,
pass: env.email.password,
},
}
: env.email.uri;
const emailOptions = {
host: env.email.host,
port: env.email.port,
secure: env.email.secure,
auth: {
user: env.email.auth.user,
pass: env.email.auth.password,
},
tls: {
rejectUnauthorized: env.email.rejectUnauthorized,
},
}

export const transporter = nodemailer.createTransport(emailOptions);

Expand Down
16 changes: 10 additions & 6 deletions src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ const env = {
email: {
// We don't use the normal 25 port because of testing (25 listening is usually denied)
// Also reject self signed certificates only in tests
uri: loadEnv('SMTP_URI') || `smtp://localhost:2525/?pool=true&maxConnections=1&tls.rejectUnauthorized=${!isTest}`,
host: loadEnv('EMAIL_HOST'),
port: loadIntEnv('EMAIL_PORT'),
secure: loadEnv('EMAIL_SECURE') !== 'false',
sender: {
name: loadEnv('EMAIL_SENDER_NAME') || 'UTT Arena',
address: loadEnv('EMAIL_SENDER_ADDRESS') || 'arena@utt.fr',
address: loadEnv('EMAIL_SENDER_ADDRESS') || 'arena@utt'

This comment has been minimized.

Copy link
@DevNono

DevNono Nov 7, 2024

Contributor

Il est normal le retrait du .fr là ?

This comment has been minimized.

Copy link
@tuturd

tuturd Nov 7, 2024

Author Contributor

nope c une erreur de frappe

},
gmail: loadEnv('GMAIL') === 'true',
username: loadEnv('GMAIL_USERNAME') || null,
password: loadEnv('GMAIL_PASSWORD') || null,
partners: ['utt.fr', 'utc.fr', 'utbm.fr'],
auth: {
user: loadEnv('EMAIL_AUTH_USER'),
password: loadEnv('EMAIL_AUTH_PASSWORD'),
},
rejectUnauthorized: loadEnv('EMAIL_REJECT_UNAUTHORIZED') !== 'false',
maxMailsPerBatch: loadIntEnv('MAX_MAIL_PER_BATCH') || 100,
partners: loadEnv('PARTNER_MAILS')?.split(',') || [],
},
stripe: {
callback: `${frontEndpoint}/stripe`,
Expand Down

0 comments on commit 4ca6419

Please sign in to comment.