Skip to content

Commit

Permalink
chore: fixed the signature context
Browse files Browse the repository at this point in the history
  • Loading branch information
wildduck2 committed Aug 9, 2024
1 parent 9c33a7e commit fb2bf06
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 68 deletions.
8 changes: 3 additions & 5 deletions src/EmailBuilder/EmailBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ export class EmailBuilder implements EmailBuilderClass {
* });
* console.log(signature.join("\n"));
*/
public getSignature({ from, url, name }: GetSignatureType): string[] {
public getSignature({ from, url, name }: GetSignatureType): string {
return [
``,
`</div>`,
`<div style="margin: 1rem">`,
`---------------------------------`,
`<p>This email was sent from ${from} by <a style="color: blue" href="${url}" target="_blank">${name}</a> app</p>`,
`<p>This email was sent from ${from} by <a style="color: blue;" href="${url}" target="_blank">${name}</a> app</p>`,
`---------------------------------`,
`</div>`,
];
].join("\r\n");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/EmailBuilder/EmailBuilder.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type MIMEType = typeof MIMETypes;

export declare class EmailBuilderClass {
public constructor();
public getSignature({ from, url, name }: GetSignatureType): string[];
public getSignature({ from, url, name }: GetSignatureType): string;
public setSignature({
name,
url,
Expand Down
18 changes: 9 additions & 9 deletions src/EmailBuilder/__test__/EmailBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ describe("EmailBuilder", () => {
name: emailBuilder.applicationSignature.name,
});

expect(signature).toEqual([
"",
`</div>`,
`<div style="margin: 1rem">`,
`---------------------------------`,
`<p>This email was sent from sender@example.com by <a style="color: blue" href="${emailBuilder.applicationSignature.url}" target="_blank">${emailBuilder.applicationSignature.name}</a> app</p>`,
`---------------------------------`,
`</div>`,
]);
expect(signature).toEqual(
[
`<div style="margin: 1rem">`,
`---------------------------------`,
`<p>This email was sent from sender@example.com by <a style="color: blue;" href="${emailBuilder.applicationSignature.url}" target="_blank">${emailBuilder.applicationSignature.name}</a> app</p>`,
`---------------------------------`,
`</div>`,
].join("\r\n")
);
});

it("should include attachments in the raw message", () => {
Expand Down
107 changes: 54 additions & 53 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,57 @@ export * from "./EmailBuilderAttachment";
export * from "./Error";
export * from "./zod";

// import { Base64 } from "./Base64";
// import { EmailBuilderHeader } from "./EmailBiulderHeader";
// import { EmailBuilder } from "./EmailBuilder";
// import { EmailBuilderAttachment } from "./EmailBuilderAttachment/EmailBuilderAttachment";
// const header = new EmailBuilderHeader();
// header
// .setFrom("ahmed <ahmed@gmail.com>")
// .setTo("ahmed <ahmed@gmail.com>")
// .setCc("ahmed <ahmed@gmai.com>")
// .setBcc("ahmed <ahmed@gmai.com>")
// .setSubject("this is wild duck email test subject")
// .setInReplyTo("ahmed@gmail.com")
// .setMIMEVersion("1.0")
// .setContentTransferEncoding("quoted-printable")
// .setContentType("text/html")
// .setCharset("utf8");
//
// const attachment = new EmailBuilderAttachment();
// attachment.addAttachment({
// headers: {
// "Content-Type": 'text/plain; charset="utf-8"',
// "Content-Transfer-Encoding": "base64",
// "Content-Disposition": 'attachment; filename="test.txt"',
// },
// size: 1234,
// filename: "test.txt",
// mimeType: "text/plain",
// attachmentId: "1234",
// attachmentContent: Base64.encodeToBase64("test"),
// });
// attachment.addAttachment({
// headers: {
// "Content-Type": 'text/plain; charset="utf-8"',
// "Content-Transfer-Encoding": "base64",
// "Content-Disposition": 'attachment; filename="test.txt"',
// },
// size: 1234,
// filename: "test.txt",
// mimeType: "text/plain",
// attachmentId: "1234",
// attachmentContent: Base64.encodeToBase64("test"),
// });
//
// // console.log(header.attachments);
//
// const email = new EmailBuilder();
// email.messagebody = "this is message body";
//
// const finalEmail = email.getEncodedMessage(
// header.headers,
// attachment.attachments
// );
// console.log(finalEmail);
import { Base64 } from "./Base64";
import { EmailBuilderHeader } from "./EmailBiulderHeader";
import { EmailBuilder } from "./EmailBuilder";
import { EmailBuilderAttachment } from "./EmailBuilderAttachment/EmailBuilderAttachment";
const header = new EmailBuilderHeader();
header
.setFrom("ahmed <ahmed@gmail.com>")
.setTo("ahmed <ahmed@gmail.com>")
.setCc("ahmed <ahmed@gmai.com>")
.setBcc("ahmed <ahmed@gmai.com>")
.setSubject("this is wild duck email test subject")
.setInReplyTo("<ahmed@gmail.com>")
.setMIMEVersion("1.0")
.setContentTransferEncoding("quoted-printable")
.setContentType("text/html")
.setCharset("utf8");

const attachment = new EmailBuilderAttachment();
attachment.addAttachment({
headers: {
"Content-Type": 'text/plain; charset="utf-8"',
"Content-Transfer-Encoding": "base64",
"Content-Disposition": 'attachment; filename="test.txt"',
},
size: 1234,
filename: "test.txt",
mimeType: "text/plain",
attachmentId: "1234",
attachmentContent: Base64.encodeToBase64("test"),
});
attachment.addAttachment({
headers: {
"Content-Type": 'text/plain; charset="utf-8"',
"Content-Transfer-Encoding": "base64",
"Content-Disposition": 'attachment; filename="test.txt"',
},
size: 1234,
filename: "test.txt",
mimeType: "text/plain",
attachmentId: "1234",
attachmentContent: Base64.encodeToBase64("test"),
});

// console.log(header.attachments);

const email = new EmailBuilder();
email.setSignature({
name: "ahmed",
url: "https://ahmed.com",
});
email.messagebody = "this is message body";

const finalEmail = email.getRawMessage(header.headers, attachment.attachments);
console.log(finalEmail);

0 comments on commit fb2bf06

Please sign in to comment.