-
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
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 |
private var html: String? = null | ||
private var subject: String? = null | ||
private var attachments: MutableList<EmailFile> = mutableListOf() | ||
private var inlines: MutableList<EmailFile> = mutableListOf() |
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 are inlines?
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.
An inline is a file that is sent along with an email, similar to an attachment, except it doesn't show as a downloadable file and instead can be referenced from the email html using the cid:
protocol. This is how inline images are implemented.
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.
Oh, nice. Maybe we should have a comment explaining that since I'm guessing a lot of people won't know that.
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