diff --git a/Sources/Mailosaur/Models/MessageModels.swift b/Sources/Mailosaur/Models/MessageModels.swift index 9e0a7ef..03cf0d2 100644 --- a/Sources/Mailosaur/Models/MessageModels.swift +++ b/Sources/Mailosaur/Models/MessageModels.swift @@ -166,6 +166,8 @@ public enum MessageSearchMatchOperator: String, Encodable { public struct MessageCreateOptions: Encodable { /// The email address to which the email will be sent. public let to: String + /// The email address to which the email will be CC'd. + public let cc: String? /// If true, email will be sent upon creation. public let send: Bool /// The email subject line. @@ -185,8 +187,10 @@ public struct MessageCreateOptions: Encodable { /// - Parameter text: Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both /// - Parameter html: Any additional HTML content to include in the reply. Note that only html or text can be supplied, not both. /// - Parameter attachments: Any message attachments. - public init(to: String, send: Bool, subject: String, text: String? = nil, html: String? = nil, attachments: [MessageAttachmentOptions]? = nil) { + /// - Parameter cc: The email address to which the email will be CC'd. + public init(to: String, send: Bool, subject: String, text: String? = nil, html: String? = nil, attachments: [MessageAttachmentOptions]? = nil, cc: String? = nil) { self.to = to + self.cc = cc self.send = send self.subject = subject self.text = text @@ -198,6 +202,8 @@ public struct MessageCreateOptions: Encodable { public struct MessageForwardOptions: Encodable { /// The email address to which the email will be sent. public let to: String + /// The email address to which the email will be CC'd. + public let cc: String? // Any additional plain text content to forward the email with. Note that only text or html can be supplied, not both. public let text: String? /// Any additional HTML content to forward the email with. Note that only html or text can be supplied, not both. @@ -206,16 +212,20 @@ public struct MessageForwardOptions: Encodable { /// Initializes a new instance of the MessageForwardOptions class. /// - Important: Note that only html or text can be supplied, not both. /// - Parameter to: The email address to which the email will be sent. + /// - Parameter cc: The email address to which the email will be sent. /// - Parameter text: Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both /// - Parameter html: Any additional HTML content to include in the reply. Note that only html or text can be supplied, not both. - public init(to: String, text: String? = nil, html: String? = nil) { + public init(to: String, text: String? = nil, html: String? = nil, cc: String? = nil) { self.to = to + self.cc = cc self.text = text self.html = html } } public struct MessageReplyOptions: Encodable { + /// The email address to which the email will be CC'd. + public let cc: String? /// Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both. public let text: String? /// Any additional HTML content to include in the reply. Note that only html or text can be supplied, not both. @@ -228,7 +238,9 @@ public struct MessageReplyOptions: Encodable { /// - Important: Note that only html or text can be supplied, not both. /// - Parameter text: Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both /// - Parameter html: Any additional HTML content to include in the reply. Note that only html or text can be supplied, not both. - public init(text: String? = nil, html: String? = nil, attachments: [MessageAttachmentOptions]? = nil) { + /// - Parameter cc: The email address to which the email will be sent. + public init(text: String? = nil, html: String? = nil, attachments: [MessageAttachmentOptions]? = nil, cc: String? = nil) { + self.cc = cc self.text = text self.html = html self.attachments = attachments diff --git a/Tests/MailosaurTests/EmailsTests.swift b/Tests/MailosaurTests/EmailsTests.swift index 506e471..f12bc33 100644 --- a/Tests/MailosaurTests/EmailsTests.swift +++ b/Tests/MailosaurTests/EmailsTests.swift @@ -258,6 +258,23 @@ final class EmailsTests: XCTestCase { XCTAssertEqual(subject, message.subject) } + func testCreateWithCc() async throws { + try XCTSkipIf(EmailsTestsSetup.verifiedDomain == nil, "Skipping test") + + let subject = "CC message" + let ccRecipient = "someoneelse@\(EmailsTestsSetup.verifiedDomain ?? "")" + let message = try await EmailsTestsSetup.client.messages.create(server: EmailsTestsSetup.server, messageCreateOptions: MessageCreateOptions(to: "anything@\(EmailsTestsSetup.verifiedDomain ?? "")", + send: true, + subject: subject, + html: "
This is a new email.
", + cc: ccRecipient)) + + XCTAssertFalse(message.id.isEmpty) + XCTAssertEqual(subject, message.subject) + XCTAssertEqual(1, message.cc.count) + XCTAssertEqual(ccRecipient, message.cc[0].email) + } + func testCreateSendWithAttachment() async throws { try XCTSkipIf(EmailsTestsSetup.verifiedDomain == nil, "Skipping test") @@ -308,6 +325,23 @@ final class EmailsTests: XCTestCase { XCTAssertTrue(message.html.body?.contains(body) == true) } + func testForwardWithCc() async throws { + try XCTSkipIf(EmailsTestsSetup.verifiedDomain == nil, "Skipping test") + + let body = "Forwarded HTML message.
" + let targetEmail = EmailsTestsSetup.emails[0] + let ccRecipient = "someoneelse@\(EmailsTestsSetup.verifiedDomain ?? "")" + + let message = try await EmailsTestsSetup.client.messages.forward(id: targetEmail.id, messageForwardOptions: MessageForwardOptions(to: "forwardcc@\(EmailsTestsSetup.verifiedDomain ?? "")", + html: body, + cc: ccRecipient)) + + XCTAssertFalse(message.id.isEmpty) + XCTAssertTrue(message.html.body?.contains(body) == true) + XCTAssertEqual(1, message.cc.count) + XCTAssertEqual(ccRecipient, message.cc[0].email) + } + func testReplyText() async throws { try XCTSkipIf(EmailsTestsSetup.verifiedDomain == nil, "Skipping test") @@ -332,6 +366,21 @@ final class EmailsTests: XCTestCase { XCTAssertTrue(message.html.body?.contains(body) == true) } + func testReplyWithCc() async throws { + try XCTSkipIf(EmailsTestsSetup.verifiedDomain == nil, "Skipping test") + + let body = "Reply CC Message" + let targetEmail = EmailsTestsSetup.emails[0] + let ccRecipient = "someoneelse@\(EmailsTestsSetup.verifiedDomain ?? "")" + + let message = try await EmailsTestsSetup.client.messages.reply(id: targetEmail.id, messageReplyOptions: MessageReplyOptions(html: body, cc: ccRecipient)) + + XCTAssertFalse(message.id.isEmpty) + XCTAssertTrue(message.html.body?.contains(body) == true) + XCTAssertEqual(1, message.cc.count) + XCTAssertEqual(ccRecipient, message.cc[0].email) + } + func testReplyWithAttachment() async throws { try XCTSkipIf(EmailsTestsSetup.verifiedDomain == nil, "Skipping test")