Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CC property to message option models #72

Merged
merged 1 commit into from
Jan 2, 2025
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
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 `[email protected]`.
*/
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
Loading