Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
feat(temporary): test send mail to raph via cron
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Jun 3, 2022
1 parent a19a599 commit c1ca341
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .kube-workflow/preprod/templates/sendMailToRaph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This is test of the workflow
apiVersion: batch/v1beta1
kind: CronJob
metadata:
namespace: mon-psy-sante-preprod
name: send-mail-to-raph
labels:
app: mon-psy
spec:
# Every 10 minutes (test purpose)
schedule: "*/10 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: mon-psy
image: ghcr.io/socialgouv/mon-psy-sante/app:{{ .Values.global.imageTag }}
envFrom:
- secretRef:
name: app-sealed-secret
- secretRef:
name: pg-user
command:
- yarn
- run
- cron:launch
- sendMailToRaph
restartPolicy: Never
concurrencyPolicy: Forbid
2 changes: 2 additions & 0 deletions src/cron/launch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Sentry from "@sentry/nextjs";

import * as demarchesSimplifiees from "./demarchesSimplifiees";
import { sendMailToRaph } from "./sendMailToRaph";

const runJob = async (job): Promise<void> => {
const SENTRY_DSN = process.env.NEXT_PUBLIC_SENTRY_DSN;
Expand All @@ -25,6 +26,7 @@ if (process.argv.length < 3) {
const cronJobs = {
importFromDS: demarchesSimplifiees.importFromDS,
verifFolders: demarchesSimplifiees.verifFolders,
sendMailToRaph,
};

const jobName = process.argv[2];
Expand Down
34 changes: 34 additions & 0 deletions src/cron/sendMailToRaph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import nodemailer from "nodemailer";

import config from "../services/config";

const mailTransport = nodemailer.createTransport({
auth: {
pass: config.mail.auth.pass,
user: config.mail.auth.user,
},
host: config.mail.host,
ignoreTLS: !config.mail.tls,
port: config.mail.port,
requireTLS: config.mail.tls,
});

export function sendMailToRaph() {
const mail = {
from: `MonPsy <${config.supportMail}>`,
html: "<b>bonjour</b> raph",
subject: "salut raph",
text: "bonjour raph",
to: "raph@selego.co",
};
if (config.mail.enabled) {
return new Promise((resolve, reject) => {
mailTransport.sendMail(mail, (error, info) => {
console.log(error, info);
return error ? reject(error) : resolve(info);
});
});
}
console.log("Send email skipped");
return Promise.resolve();
}

0 comments on commit c1ca341

Please sign in to comment.