-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add email service #123
base: develop
Are you sure you want to change the base?
Add email service #123
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
78a6476
to
c1c29c2
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #123 +/- ##
==============================================
- Coverage 88.49% 77.43% -11.07%
- Complexity 345 355 +10
==============================================
Files 61 67 +6
Lines 791 935 +144
Branches 65 76 +11
==============================================
+ Hits 700 724 +24
- Misses 57 177 +120
Partials 34 34
☔ View full report in Codecov by Sentry. |
I'm marking as ready for review, but a few things are still missing:
|
Check the documentation preview: https://64148c8507396b40a734ad10--niaefeup-backend-docs.netlify.app |
Check the documentation preview: https://64161557a5113f2455baeb87--niaefeup-backend-docs.netlify.app |
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.
What a great PR 🎉 Tremendous job! I left minor/cosmetic suggestions
One thing I don't like is having email
as a top-level package, I think we already have enough of them. What do you think of storing the builders under service/email/
? together with EmailService?
src/main/kotlin/pt/up/fe/ni/website/backend/config/email/EmailConfigProperties.kt
Show resolved
Hide resolved
import pt.up.fe.ni.website.backend.config.email.EmailConfigProperties | ||
import pt.up.fe.ni.website.backend.model.Account | ||
|
||
abstract class BaseEmailBuilder : EmailBuilder { |
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.
Testing the builders should be trivial with unit tests (testing validation, whether emails are added in the right places, etc.)
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.
One can also mock the java mail library and verify if the methods are being called with the correct arguments
src/main/kotlin/pt/up/fe/ni/website/backend/email/SimpleEmailBuilder.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/email/TemplateEmailBuilder.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/service/EmailService.kt
Outdated
Show resolved
Hide resolved
this.data = data | ||
} | ||
|
||
override fun build(helper: MimeMessageHelper, emailConfigProperties: EmailConfigProperties) { |
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.
this function is a bit verbose, I'd consider splitting it into more methods if possible
spring.mail.host= | ||
spring.mail.port= | ||
spring.mail.username= | ||
spring.mail.password= |
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.
Will we need to configure this in prod? It'd be nice to have some example in the wiki if so
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.
You're right, I'll add a section on how to configure it
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.
Where is it? I may be legally blind
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.
Could you try to add this @rubuy-74 ? (Meant to comment under the open conversation, about adding instructions to the wiki)
Check the documentation preview: https://641c7e9b8ddee704dad18da7--niaefeup-backend-docs.netlify.app |
Have you decided something about the tests? |
744c69c
to
33dc731
Compare
Check the documentation preview: https://649c5a2becd22626c57b25e2--niaefeup-backend-docs.netlify.app |
src/main/kotlin/pt/up/fe/ni/website/backend/email/SimpleEmailBuilder.kt
Outdated
Show resolved
Hide resolved
Check the documentation preview: https://6748a29cc73b7330bd8b3797--niaefeup-backend-docs.netlify.app |
Check the documentation preview: https://6793cddd62e627d5c653cc1b--niaefeup-backend-docs.netlify.app |
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.
It's looking good so far. Shouldn't we add tests for SimpleEmailBuilder
and TemplateEmailBuilder
too?
spring.mail.host= | ||
spring.mail.port= | ||
spring.mail.username= | ||
spring.mail.password= |
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.
Could you try to add this @rubuy-74 ? (Meant to comment under the open conversation, about adding instructions to the wiki)
class BaseEmailBuilderImpl( | ||
override val emailConfigProperties: EmailConfigProperties | ||
) : BaseEmailBuilder() { | ||
fun getToEmails(): Set<String> = to | ||
fun getCcEmails(): Set<String> = cc | ||
fun getBccEmails(): Set<String> = bcc | ||
fun getFromEmail(): String? = from | ||
fun getName(): String? = fromPersonal | ||
} |
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.
Why is this needed?
Don't forget to add instructions for testing on the wiki. |
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.
I like the changes from the last time I saw it. Good job with the tests!
One thing that would be great to improve is the size of the PRs. We didn't use to do this in NI but it's much easier to do small and incremental PRs, even if the feature or issue isn't fully closed. This should help make the reviews quicker and avoid having stale CRs for months at a time
PS: you need to fix the lint, it seems
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.
approve to unblock, but look at the comments
Closes #82.
Adds a new
EmailService
with a methodsend
, which receives an instance ofEmailBuilder
.Two builders were implemented:
SimpleEmailBuilder
, which receives all properties directly, andTemplateEmailBuilder
, which generates the subject, content and attachments from the given data using mustache templates.Each different template email should be a subclass of
TemplateEmailBuilder
, here's an example:This sends an email that looks something like this:
Review checklist