-
Notifications
You must be signed in to change notification settings - Fork 10
Feature to add "reply_to" option when sending mails. #58
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
Conversation
…ToRecipient function
WalkthroughThis update enhances email functionality by introducing reply-to support. A new constant is added in the sending example, and the mail adapter function is modified to process a reply-to field using a newly added recipient adaptation function. Test cases have been updated accordingly, and the CommonMail type now contains an optional reply-to property. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant EmailAdapter as adaptMail
participant RecipientAdapter as adaptReplyToRecipient
participant MailService
Client->>EmailAdapter: Send email data with replyTo field
EmailAdapter->>RecipientAdapter: Process replyTo value
RecipientAdapter-->>EmailAdapter: Return adapted reply-to address
EmailAdapter->>MailService: Send email with added reply_to property
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (2)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/adapters/mail.ts (1)
4-4
: Fix import formattingThe import line should be reformatted for better readability according to the project's style guidelines.
-import adaptRecipients, { adaptSingleRecipient, adaptReplyToRecipient } from "./recipients"; +import adaptRecipients, { + adaptSingleRecipient, + adaptReplyToRecipient, +} from "./recipients";🧰 Tools
🪛 ESLint
[error] 4-4: Replace
·adaptSingleRecipient,·adaptReplyToRecipient·
with⏎··adaptSingleRecipient,⏎··adaptReplyToRecipient,⏎
(prettier/prettier)
src/adapters/recipients.ts (1)
42-64
: Well-implemented reply_to adapter function with minor formatting issuesThe new
adaptReplyToRecipient
function correctly handles various input scenarios and is well-documented. It properly handles the case where Mailtrap doesn't support multiple reply-to recipients by taking just the first one.There are a few formatting issues to fix:
/** * If there is no recipient or empty array is passed, then return undefined since it is an optional field. * If it's not array, then adapt recipient and returns it. -* Otherwise, if type is array as nodemailer allows, we pick the first recipient +* Otherwise, if type is array as nodemailer allows, we pick the first recipient * as Mailtrap doesn't support multiple reply-to recipients. */ export function adaptReplyToRecipient( recipients: | string | NodemailerAddress | Array<string | NodemailerAddress> | undefined ): Address | undefined { - if(!recipients || (Array.isArray(recipients) && recipients.length === 0)) { + if (!recipients || (Array.isArray(recipients) && recipients.length === 0)) { return undefined; } if (!Array.isArray(recipients)) { return adaptSingleRecipient(recipients); } return adaptSingleRecipient(recipients[0]); } +🧰 Tools
🪛 ESLint
[error] 45-45: Delete
·
(prettier/prettier)
[error] 55-55: Insert
·
(prettier/prettier)
[error] 64-64: Insert
⏎
(prettier/prettier)
src/__tests__/adapters/mail.test.ts (2)
4-4
: Fix import formatting to match code style guidelines.The import line should follow the project's formatting style as indicated by ESLint.
-import { adaptSingleRecipient, adaptReplyToRecipient } from "../../adapters/recipients"; +import { + adaptSingleRecipient, + adaptReplyToRecipient, +} from "../../adapters/recipients";🧰 Tools
🪛 ESLint
[error] 4-4: Replace
·adaptSingleRecipient,·adaptReplyToRecipient·
with⏎··adaptSingleRecipient,⏎··adaptReplyToRecipient,⏎
(prettier/prettier)
100-297
: Consider adding replyTo to additional test cases.The
replyTo
field is currently tested in 3 scenarios, but not in the template, category, text, or HTML test cases. For complete test coverage, consider adding thereplyTo
field to these test cases as well.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
examples/sending/everything.ts
(2 hunks)src/__tests__/adapters/mail.test.ts
(7 hunks)src/adapters/mail.ts
(2 hunks)src/adapters/recipients.ts
(1 hunks)src/types/mailtrap.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/adapters/mail.ts (1)
src/adapters/recipients.ts (1)
adaptReplyToRecipient
(48-64)
src/__tests__/adapters/mail.test.ts (1)
src/adapters/recipients.ts (1)
adaptReplyToRecipient
(48-64)
src/adapters/recipients.ts (1)
src/types/mailtrap.ts (1)
Address
(5-8)
🪛 ESLint
src/adapters/mail.ts
[error] 4-4: Replace ·adaptSingleRecipient,·adaptReplyToRecipient·
with ⏎··adaptSingleRecipient,⏎··adaptReplyToRecipient,⏎
(prettier/prettier)
src/__tests__/adapters/mail.test.ts
[error] 4-4: Replace ·adaptSingleRecipient,·adaptReplyToRecipient·
with ⏎··adaptSingleRecipient,⏎··adaptReplyToRecipient,⏎
(prettier/prettier)
src/adapters/recipients.ts
[error] 45-45: Delete ·
(prettier/prettier)
[error] 55-55: Insert ·
(prettier/prettier)
[error] 64-64: Insert ⏎
(prettier/prettier)
🔇 Additional comments (7)
src/types/mailtrap.ts (1)
26-26
: Clean addition of reply_to fieldThe
reply_to
field has been properly added as an optional property to theCommonMail
type, maintaining consistency with other address fields likefrom
,to
,cc
, andbcc
.examples/sending/everything.ts (2)
15-15
: Good example of reply_to configurationThe addition of the
REPLY_TO_EMAIL
constant provides a clear example of how to set up a reply-to address.
32-32
: Proper implementation of reply_to fieldThe reply_to field is correctly implemented in the email configuration object, demonstrating how to use this new feature.
src/adapters/mail.ts (1)
30-30
: Good implementation of reply_to adapterThe implementation correctly uses the new
adaptReplyToRecipient
function to handle thereplyTo
field from the input data, maintaining consistency with how other recipient fields are processed.src/__tests__/adapters/mail.test.ts (3)
27-27
: Implementation of reply-to support looks good.The test cases correctly add the
replyTo
field in the test data and verify thatadaptReplyToRecipient
is called to adapt the value in the expected result.Also applies to: 37-37
52-52
: Testing empty array for replyTo looks good.Good job testing the edge case of an empty array for the
replyTo
field. This ensures that theadaptReplyToRecipient
function handles this case correctly.Also applies to: 63-63
81-81
: Testing replyTo with array of strings looks good.Testing with an array containing a string value is a good approach to verify that the
adaptReplyToRecipient
function correctly processes array inputs.Also applies to: 93-93
Good day, @mklocek @vittorius @JSFernandes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution @aolamide! Could you please also update the Nodemailer usage example and we'll be good to go.
Thank you, @vittorius |
Hi, @VladimirTaytor. Could you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for contribution 💪
Motivation
Mailtrap has the option of a
reply_to
field, but this currently does not exist in the SDK. This PR introduces the functionality to allow users to pass areply_to
email address, which will be used as the default reply email in email clients.Changes
reply_to
in the CommonMail type.reply_to
feature.Summary by CodeRabbit