@travetto/email-nodemailer 3.1.6 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/nodemailer.ts +18 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/email-nodemailer",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
4
4
  "description": "Email transmission module.",
5
5
  "keywords": [
6
6
  "email",
@@ -24,7 +24,7 @@
24
24
  "directory": "module/email-nodemailer"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/email": "^3.1.6",
27
+ "@travetto/email": "^3.1.8",
28
28
  "@types/nodemailer": "^6.4.8",
29
29
  "nodemailer": "^6.9.2"
30
30
  },
package/src/nodemailer.ts CHANGED
@@ -14,11 +14,29 @@ type Transport = TransportType | json.Options | smtp.Options | ses.Options | sen
14
14
  export class NodemailerTransport implements MailTransport {
15
15
  #transport: Transporter;
16
16
 
17
+ /**
18
+ * Force content into alternative slots
19
+ */
20
+ #forceContentToAlternative(msg: MessageOptions): MessageOptions {
21
+ for (const [key, mime] of [['text', 'text/plain'], ['html', 'text/html']] as const) {
22
+ if (msg[key]) {
23
+ (msg.alternatives ??= []).push({
24
+ content: msg[key], contentDisposition: 'inline', contentTransferEncoding: '7bit', contentType: `${mime}; charset=utf-8`
25
+ });
26
+ delete msg[key];
27
+ }
28
+ }
29
+ return msg;
30
+ }
31
+
17
32
  constructor(transportFactory: Transport) {
18
33
  this.#transport = createTransport(transportFactory);
19
34
  }
20
35
 
21
36
  async send<S extends SentMessage = SentMessage>(mail: MessageOptions): Promise<S> {
37
+
38
+ mail = this.#forceContentToAlternative(mail);
39
+
22
40
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23
41
  const res = await this.#transport.sendMail(mail) as {
24
42
  messageId?: string;