Skip to content

Commit

Permalink
Added CC property to message option models
Browse files Browse the repository at this point in the history
Including Create, Forward and Reply
  • Loading branch information
ey-mailosaur authored and jm-mailosaur committed Jan 2, 2025
1 parent 7797107 commit 4d470af
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ export interface MessageCreateOptions {
* The email address to which the email will be sent. Must be a verified email address.
*/
to?: string;
/**
* The email address to which the email will be CC'd to. Must be a verified email address.
*/
cc?: string;
/**
* Allows for the partial override of the message's 'from' address. This **must** be an address ending with `YOUR_SERVER.mailosaur.net`, such as `my-emails@a1bcdef2.mailosaur.net`.
*/
Expand Down Expand Up @@ -398,6 +402,10 @@ export interface MessageForwardOptions {
* The email address to which the email will be sent. Must be a verified email address.
*/
to: string;
/**
* The email address to which the email will be CC'd to. Must be a verified email address.
*/
cc?: string;
/**
* Any plain text to include when forwarding the message. Note that only text or html can be supplied, not both.
*/
Expand All @@ -412,6 +420,10 @@ export interface MessageForwardOptions {
* Options to use when replying to a message.
*/
export interface MessageReplyOptions {
/**
* The email address to which the email will be CC'd to. Must be a verified email address.
*/
cc?: string;
/**
* Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both.
*/
Expand Down
1 change: 1 addition & 0 deletions lib/models/messageCreateOptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class MessageCreateOptions {
constructor(data = {}) {
this.to = data.to;
this.cc = data.cc;
this.from = data.from;
this.send = data.send;
this.subject = data.subject;
Expand Down
1 change: 1 addition & 0 deletions lib/models/messageForwardOptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class MessageForwardOptions {
constructor(data = {}) {
this.to = data.to;
this.cc = data.cc;
this.text = data.text;
this.html = data.html;
}
Expand Down
1 change: 1 addition & 0 deletions lib/models/messageReplyOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class MessageReplyOptions {
this.text = data.text;
this.html = data.html;
this.attachments = data.attachments;
this.cc = data.cc;
}
}

Expand Down
47 changes: 47 additions & 0 deletions test/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ describe('emails', () => {
assert.equal(message.subject, subject);
});

it('send with HTML content to CC recipient', async () => {
const subject = 'CC Message';
const ccRecipient = `someoneelse@${verifiedDomain}`;
const message = await client.messages.create(server, {
to: `anything@${verifiedDomain}`,
send: true,
subject,
cc: ccRecipient,
html: '<p>This is a new email.</p>'
});
assert.isNotEmpty(message.id);
assert.equal(message.subject, subject);
assert.equal(message.cc.length, 1);
assert.equal(message.cc[0].email, ccRecipient);
});

it('send with attachment', async () => {
const subject = 'New message with attachment';

Expand Down Expand Up @@ -434,6 +450,22 @@ describe('emails', () => {
assert.isNotEmpty(message.id);
assert.isTrue(message.html.body.indexOf(body) >= 0);
});

it('forward with HTML content to CC recipient', async () => {
const targetEmailId = emails[0].id;
const body = '<p>Forwarded <strong>HTML</strong> message.</p>';
const ccRecipient = `someoneelse@${verifiedDomain}`;

const message = await client.messages.forward(targetEmailId, {
to: `anything@${verifiedDomain}`,
html: body,
cc: ccRecipient
});
assert.isNotEmpty(message.id);
assert.isTrue(message.html.body.indexOf(body) >= 0);
assert.equal(message.cc.length, 1);
assert.equal(message.cc[0].email, ccRecipient);
});
});

(verifiedDomain ? describe : describe.skip)('reply', () => {
Expand All @@ -459,6 +491,21 @@ describe('emails', () => {
assert.isTrue(message.html.body.indexOf(body) >= 0);
});

it('reply with HTML content to CC recipient', async () => {
const targetEmailId = emails[0].id;
const body = '<p>Reply <strong>HTML</strong> message.</p>';
const ccRecipient = `someoneelse@${verifiedDomain}`;

const message = await client.messages.reply(targetEmailId, {
html: body,
cc: ccRecipient
});
assert.isNotEmpty(message.id);
assert.isTrue(message.html.body.indexOf(body) >= 0);
assert.equal(message.cc.length, 1);
assert.equal(message.cc[0].email, ccRecipient);
});

it('reply with attachment', async () => {
const targetEmailId = emails[0].id;

Expand Down

0 comments on commit 4d470af

Please sign in to comment.