Merged PR 633: HTMLテンプレートファイルの形式を決定

## 概要
[Task3320: HTMLテンプレートファイルの形式を決定](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3320)

- HTMLテンプレートの形式を見ていただくにあたって、ライセンス注文キャンセルでテンプレートからメールを生成する処理を実装しました。
  - ライセンス注文キャンセルメールのテンプレートを追加しています。
- メール送信時にTOとCCに複数人を設定できるように修正しました。

## レビューポイント
- テンプレート中で置き換える文字列を定数として定義していますが違和感はないでしょうか?
- テンプレートの文言置き換え処理ですべてのパターンに引っかかるように正規表現で検索していますが問題ないでしょうか?
- HTMLテンプレート、メール表示内容に違和感はないでしょうか?

## UIの変更
- [Task3320](https://ndstokyo.sharepoint.com/:f:/r/sites/Piranha/Shared%20Documents/General/OMDS/%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88/Task3320?csf=1&web=1&e=yU9aDH)

## 動作確認状況
- ローカルで確認
This commit is contained in:
makabe.t 2023-12-18 04:54:53 +00:00
parent afa05f381c
commit a676d65f0a
6 changed files with 169 additions and 10 deletions

View File

@ -299,7 +299,8 @@ export class AccountsService {
// メールを送信
await this.sendgridService.sendMail(
context,
email,
[email],
[],
this.mailFrom,
subject,
text,
@ -865,7 +866,8 @@ export class AccountsService {
);
await this.sendgridService.sendMail(
context,
email,
[email],
[],
this.mailFrom,
subject,
text,

View File

@ -298,7 +298,8 @@ export class UsersService {
//SendGridAPIを呼び出してメールを送信する
await this.sendgridService.sendMail(
context,
email,
[email],
[],
this.mailFrom,
subject,
text,
@ -506,7 +507,8 @@ export class UsersService {
// メールを送信
await this.sendgridService.sendMail(
context,
email,
[email],
[],
this.mailFrom,
subject,
text,
@ -574,7 +576,7 @@ export class UsersService {
if (adb2cUser == null) {
throw new Error('mail not found.'); // TODO: リファクタ時に挙動を変更しないようエラー文面をmail not foundのまま据え置き。影響がない事が確認できたらエラー文面を変更する。
}
// メールアドレスを取得する
const { emailAddress: mail } = getUserNameAndMailAddress(adb2cUser);

View File

@ -6,17 +6,27 @@ import { getPrivateKey } from '../../common/jwt/jwt';
import { Context } from '../../common/log';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import {
CUSTOMER_NAME,
DEALER_NAME,
LICENSE_QUANTITY,
PO_NUMBER,
} from '../../templates/constants';
@Injectable()
export class SendGridService {
private readonly logger = new Logger(SendGridService.name);
private readonly emailConfirmLifetime: number;
private readonly appDomain: string;
private readonly mailFrom: string;
private readonly templateEmailVerifyHtml: string;
private readonly templateEmailVerifyText: string;
private readonly templateU106Html: string;
private readonly templateU106Text: string;
constructor(private readonly configService: ConfigService) {
this.appDomain = this.configService.getOrThrow<string>('APP_DOMAIN');
this.mailFrom = this.configService.getOrThrow<string>('MAIL_FROM');
this.emailConfirmLifetime = this.configService.getOrThrow<number>(
'EMAIL_CONFIRM_LIFETIME',
);
@ -33,6 +43,15 @@ export class SendGridService {
path.resolve(__dirname, `../../templates/template_email_verify.txt`),
'utf-8',
);
this.templateU106Html = readFileSync(
path.resolve(__dirname, `../../templates/template_U_106.html`),
'utf-8',
);
this.templateU106Text = readFileSync(
path.resolve(__dirname, `../../templates/template_U_106.txt`),
'utf-8',
);
}
}
@ -161,7 +180,38 @@ export class SendGridService {
`[IN] [${context.getTrackingId()}] ${this.sendMailWithU106.name}`,
);
try {
// NOT IMPLEMENT
const subject = 'Cancelled License Order Notification [U-106]';
// メールの本文を作成する
const html = this.templateU106Html
.split(CUSTOMER_NAME)
.join(customerAccountName)
.split(DEALER_NAME)
.join(dealerAccountName)
.split(PO_NUMBER)
.join(poNumber)
.split(LICENSE_QUANTITY)
.join(`${lisenceCount}`);
const text = this.templateU106Text
.split(CUSTOMER_NAME)
.join(customerAccountName)
.split(DEALER_NAME)
.join(dealerAccountName)
.split(PO_NUMBER)
.join(poNumber)
.split(LICENSE_QUANTITY)
.join(`${lisenceCount}`);
// メールを送信する
this.sendMail(
context,
customerMails,
dealerEmails,
this.mailFrom,
subject,
text,
html,
);
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.sendMailWithU106.name}`,
@ -181,7 +231,8 @@ export class SendGridService {
*/
async sendMail(
context: Context,
to: string,
to: string[],
cc: string[],
from: string,
subject: string,
text: string,
@ -194,9 +245,8 @@ export class SendGridService {
from: {
email: from,
},
to: {
email: to,
},
to: to.map((v) => ({ email: v })),
cc: cc.map((v) => ({ email: v })),
subject: subject,
text: text,
html: html,

View File

@ -0,0 +1,4 @@
export const CUSTOMER_NAME = '$CUSTOMER_NAME$';
export const DEALER_NAME = '$DEALER_NAME$';
export const LICENSE_QUANTITY = '$LICENSE_QUANTITY$';
export const PO_NUMBER = '$PO_NUMBER$';

View File

@ -0,0 +1,63 @@
<html>
<head>
<title>Cancelled License Order Notification [U-106]</title>
</head>
<body>
<div>
<h3>&lt;English&gt;</h3>
<p>Dear $CUSTOMER_NAME$,</p>
<p>
We have received the cancellation of your recent license order.<br />
- Number of canceled licenses: $LICENSE_QUANTITY$<br />
- PO Number: $PO_NUMBER$
</p>
<p>
If you need support regarding ODMS Cloud, please contact $DEALER_NAME$.
</p>
<p>
If you have received this e-mail in error, please delete this e-mail
from your system.<br />
This is an automatically generated e-mail and this mailbox is not
monitored. Please do not reply.
</p>
</div>
<div>
<h3>&lt;Deutsch&gt;</h3>
<p>Sehr geehrte(r) $CUSTOMER_NAME$,</p>
<p>
Wir haben die Stornierung Ihrer letzten Lizenzbestellung erhalten.<br />
- Anzahl der gekündigten Lizenzen: $LICENSE_QUANTITY$<br />
- Bestellnummer: $PO_NUMBER$
</p>
<p>
Wenn Sie Unterstützung bezüglich ODMS Cloud benötigen, wenden Sie sich
bitte an $DEALER_NAME$.
</p>
<p>
Wenn Sie diese E-Mail fälschlicherweise erhalten haben, löschen Sie
diese E-Mail bitte aus Ihrem System.<br />
Dies ist eine automatisch generierte E-Mail und dieses Postfach wird
nicht überwacht. Bitte nicht antworten.
</p>
</div>
<div>
<h3>&lt;Français&gt;</h3>
<p>Chère/Cher $CUSTOMER_NAME$,</p>
<p>
Nous avons reçu l'annulation de votre récente commande de licence.<br />
- Nombre de licences annulées: $LICENSE_QUANTITY$<br />
- Numéro de bon de commande: $PO_NUMBER$
</p>
<p>
Si vous avez besoin d'assistance concernant ODMS Cloud, veuillez
contacter $DEALER_NAME$.
</p>
<p>
Si vous avez reçu cet e-mail par erreur, veuillez supprimer cet e-mail
de votre système.<br />
Il s'agit d'un e-mail généré automatiquement et cette boîte aux lettres
n'est pas surveillée. Merci de ne pas répondre.
</p>
</div>
</body>
</html>

View File

@ -0,0 +1,38 @@
<English>
Dear $CUSTOMER_NAME$,
We have received the cancellation of your recent license order.
- Number of canceled licenses: $LICENSE_QUANTITY$
- PO Number: $PO_NUMBER$
If you need support regarding ODMS Cloud, please contact $DEALER_NAME$.
If you have received this e-mail in error, please delete this e-mail from your system.
This is an automatically generated e-mail and this mailbox is not monitored. Please do not reply.
<Deutsch>
Sehr geehrte(r) $CUSTOMER_NAME$,
Wir haben die Stornierung Ihrer letzten Lizenzbestellung erhalten.
- Anzahl der gekündigten Lizenzen: $LICENSE_QUANTITY$
- Bestellnummer: $PO_NUMBER$
Wenn Sie Unterstützung bezüglich ODMS Cloud benötigen, wenden Sie sich bitte an $DEALER_NAME$.
Wenn Sie diese E-Mail fälschlicherweise erhalten haben, löschen Sie diese E-Mail bitte aus Ihrem System.
Dies ist eine automatisch generierte E-Mail und dieses Postfach wird nicht überwacht. Bitte nicht antworten.
<Français>
Chère/Cher $CUSTOMER_NAME$,
Nous avons reçu l'annulation de votre récente commande de licence.
- Nombre de licences annulées: $LICENSE_QUANTITY$
- Numéro de bon de commande: $PO_NUMBER$
Si vous avez besoin d'assistance concernant ODMS Cloud, veuillez contacter $DEALER_NAME$.
Si vous avez reçu cet e-mail par erreur, veuillez supprimer cet e-mail de votre système.
Il s'agit d'un e-mail généré automatiquement et cette boîte aux lettres n'est pas surveillée. Merci de ne pas répondre.