Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions libraries/grpc-sdk/src/modules/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export class Email extends ConduitModule<typeof EmailDefinition> {
sender?: string;
replyTo?: string;
cc?: string[];
attachments?: string[];
attachments?: {
filename: string;
contentType?: string;
content?: Buffer;
href?: string;
httpHeaders?: Record<string, string>;
}[];
},
) {
return this.client!.sendEmail({
Expand All @@ -70,7 +76,14 @@ export class Email extends ConduitModule<typeof EmailDefinition> {
sender: params.sender,
replyTo: params.replyTo,
cc: params.cc ?? [],
attachments: params.attachments ?? [],
attachments:
params.attachments?.map(attachment => ({
...attachment,
content: attachment.content ? new Uint8Array(attachment.content) : undefined,
httpHeaders: attachment.httpHeaders
? JSON.stringify(attachment.httpHeaders)
: undefined,
})) ?? [],
},
}).then(res => {
return res.sentMessageInfo;
Expand Down
8 changes: 7 additions & 1 deletion modules/email/src/Email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ export default class Email extends ManagedModule<Config> {
sender: call.request.params!.sender ?? '',
cc: call.request.params!.cc,
replyTo: call.request.params!.replyTo,
attachments: call.request.params!.attachments,
attachments: call.request.params!.attachments.map(attachment => ({
...attachment,
content: attachment.content ? Buffer.from(attachment.content) : undefined,
httpHeaders: attachment.httpHeaders
? JSON.parse(attachment.httpHeaders)
: undefined,
})),
};

let errorMessage: string | null = null;
Expand Down
10 changes: 9 additions & 1 deletion modules/email/src/email.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ message RegisterTemplateResponse {
string template = 1;
}

message Attachment {
string filename = 1;
optional string contentType = 2;
optional bytes content = 3;
optional string href = 4;
optional string httpHeaders = 5;
}

message SendEmailRequest {
string templateName = 1;
SendEmailParams params = 2;
Expand All @@ -34,7 +42,7 @@ message SendEmailRequest {
optional string sender = 3;
repeated string cc = 4;
optional string replyTo = 5;
repeated string attachments = 6;
repeated Attachment attachments = 6;
}
}

Expand Down
3 changes: 2 additions & 1 deletion modules/email/src/interfaces/SendEmailParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Indexable } from '@conduitplatform/grpc-sdk';
import { Attachment } from 'nodemailer/lib/mailer';

export interface ISendEmailParams {
email: string;
Expand All @@ -8,5 +9,5 @@ export interface ISendEmailParams {
sender: string;
cc?: string[];
replyTo?: string;
attachments?: string[];
attachments?: Attachment[];
}
Loading