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

feat: arbitrary emails on server side and dynamic message configs #112

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

dword-design
Copy link
Owner

@dword-design dword-design commented Feb 13, 2022

I think I have come up with a solution that might fit for most users. The idea is similar to the one I sketched out above. What you basically do when sending emails from the client is to define message configs and then calling those configs with parameters. It's similar to the template system in EmailJS. This way you can define your emails in a flexible way without risking security leaks. The definition as a plain object is still the safest way to do it because nuxt-mail will filter out the risky fields. When setting a message config to a function, the developer is responsible to only pass the right fields through.

Here is an example of how message configs look like:

// nuxt.config.js

export default {
  modules: [
    ['nuxt-mail', {
      configs: {
        contact: {
          from: 'admin@foo.de',
          to: 'admin@foo.de',
        },
        issues: { /* ... */ },
        custom: ({ replyTo, text }) => ({
          from: 'admin@foo.de',
          to: 'admin@foo.de',
          replyTo,
          text,
        }),
      },
      smtp: { /* ... */ },
    }],
  ],
}

Then send the email like so:

this.$mail.send('contact', {
  replyTo: this.email,
  text: this.text,
})

On the server side, you have full freedom now. this.$mail.send behaves different depending on if it is on the client or the server, so for more complex logic, you can run $mail.send from the application context.

I've implemented the proposal in this pull request. Before deploying it I'd like to get your opinion on it since it has some breaking changes and there are many use cases to cover. You can find the more detailed explanation in the updated readme in the PR. To test the PR, check out the branch locally and run yarn --frozen-lockfile && yarn prepublishOnly. Then add it to some project via yarn add ../nuxt-mail.

Alright thanks for waiting, looking forward to your feedback!

@codecov
Copy link

codecov bot commented Feb 14, 2022

Codecov Report

Merging #112 (1fb9901) into master (1e1539c) will decrease coverage by 14.68%.
The diff coverage is 70.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #112       +/-   ##
===========================================
- Coverage   86.11%   71.42%   -14.69%     
===========================================
  Files           2        4        +2     
  Lines          36       56       +20     
===========================================
+ Hits           31       40        +9     
- Misses          5       16       +11     
Impacted Files Coverage Δ
src/plugin.client.js 0.00% <0.00%> (ø)
src/plugin.server.js 0.00% <0.00%> (ø)
src/send.js 86.36% <86.36%> (ø)
src/index.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 817ef89...1fb9901. Read the comment docs.

This was linked to issues Feb 15, 2022
@dword-design dword-design changed the title feat: allow arbitrary emails on server side feat: arbitrary emails on server side and dynamic message configs Feb 15, 2022
This was linked to issues Feb 15, 2022
This was referenced Feb 15, 2022
@dword-design dword-design mentioned this pull request Feb 15, 2022
@vencho-mdp
Copy link

Hi! Any updates on this? Any way we could help?

@vencho-mdp
Copy link

@dword-design How could we help in order to have it ASAP? BTW, thanks for the great module!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants