-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
added email notification text content support #934
Conversation
added default email notification text content default value empty converted email notification from html to multipart/alternatives with support to both html (first) and text (last) ignore intellij IDE .idea working folder
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.
@awaragi I think the convention in the Prometheus organization is to not add editor specific .gitignore entries. Please add them to your global .gitignore instead.
Thanks for picking this up! Go's standard library actually has a package for multipart: https://godoc.org/mime/multipart |
config/notifiers.go
Outdated
@@ -142,6 +143,7 @@ type EmailConfig struct { | |||
AuthIdentity string `yaml:"auth_identity,omitempty" json:"auth_identity,omitempty"` | |||
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"` | |||
HTML string `yaml:"html,omitempty" json:"html,omitempty"` | |||
TEXT string `yaml:"text,omitempty" json:"text,omitempty"` |
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.
Just Text
as it's not an acronym.
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.
Hi @fabxc
I am not sure I understand your comment. I am not a Go dev (yet) so I need more details about what you are requesting as a change.
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 think the key here is that HTML
is all caps since it it an initialism, but TEXT
would be written as Text
since it's just a word.
Does that make sense?
https://github.com/golang/go/wiki/CodeReviewComments#initialisms gives move info on this case
@fabxc The original code of email notification was constructed manually from smtp handshake to email construction. I am not at the level to rework this entire section of code. The smtp protocole is old dated and is not likely to change any time soon. may I recommend adding //TODO refactor to use standard multipart library https://godoc.org/mime/multipart? |
added TODO note to refactor multipart code to use standard go library
Hi, any progress with this pull request? I see that the flag for changes requested is still there but I have removed the offending file (.gitignore). @mxinden can you please mark your change request as satisfied? |
Sorry, I've to raise a very clear "NO" on this. Every new feature is a maintenance liability and already having pending TODOs when adding them is not sustainable. I hope my concern is understandable. I'm happy to review any attempts to use the proper standard library package. If you don't feel like trying it yourself, maybe someone else who's keen on this feature wants to give it a shot. |
…l parts and bounderies
@fabxc I understand your point. My liking to Go is increasing so I've attempted to use the mime/multipart library. Take another look and let me know if it works. By the way, your original TODO about adding support text template is now removed so one less to go. |
As far as I can tell (for documentation purposes): Fixes #290 |
Any chance someone can take a look at this PR? |
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.
Thanks for putting in the work! Looks good in general. Just a few remarks on usage of the multipart
package and we should be good to go.
notify/impl.go
Outdated
fmt.Fprintf(wc, "Date: %s\r\n", time.Now().Format(time.RFC1123Z)) | ||
fmt.Fprintf(wc, "Content-Type: multipart/alternative; boundary=\"%s\"\r\n", multipartWriter.Boundary()) |
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 like this can be replaced with this convenience function: https://godoc.org/mime/multipart#Writer.FormDataContentType
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.
Hi Fabian @fabxc, your initial thought is correct however for multipart email content, you need the multipart/alternative instead of multipart/form-data which is what the FormDataContentType return. I did however notice an additional quotes that were problematic that I took out from around the boundary string.
notify/impl.go
Outdated
|
||
// TODO: Add some useful headers here, such as URL of the alertmanager | ||
// and active/resolved. | ||
fmt.Fprintf(wc, "\r\n") | ||
|
||
// TODO(fabxc): do a multipart write that considers the plain template. | ||
// Html template | ||
multipartWriter.CreatePart(textproto.MIMEHeader{"Content-Type": {"text/html; charset=UTF-8"}}) |
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.
According to the documentation of CreatePart
the io.Writer
it returns should be used to write the output of the template into.
Same below when creating the part for the text template.
https://godoc.org/mime/multipart#Writer.CreatePart
The returned error should be checked as well.
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.
@fabxc implemented as suggested and added basic error handling.
Thanks for the feedback. I will update accordingly. |
added error handling while creating parts removed unnecessary quotes from boundry string
notify/impl.go
Outdated
if err != nil { | ||
return true, err | ||
} | ||
|
||
// closing multi-part content |
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 comment probably isn't necessary, since the code says essentially the same thing.
notify/impl.go
Outdated
// closing multi-part content | ||
multipartWriter.Close() | ||
|
||
// writing multipart content |
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.
Same as above comment.
@fabxc any chance to take another look? |
@fabxc any possibility to move forward with this pull request? |
Anyone? |
Any possibility of merging this pull request? |
Sorry for the delay, I'll try to poke @fabxc again |
Thanks, LGTM! Sorry about the long delay. |
* added email notification text content support (configuration text) added default email notification text content default value empty converted email notification from html to multipart/alternatives with support to both html (first) and text (last) ignore intellij IDE .idea working folder * removed specific editor .gitignore entries * renamed TEXT to Text as it's not an acronym added TODO note to refactor multipart code to use standard go library * refactored to use standard go mime/multipart library for text and html parts and bounderies * use multipart createPart returned writer added error handling while creating parts removed unnecessary quotes from boundry string * removed unnecessary comments
This causes a regression. I've built alertmanager from head and now I'm getting multipart emails with the old html content and empty text content. If your email client chooses the text format (which Gmail does for me, for some reason) then the content of the alert email is empty. The code should check for non-empty html and/or text templates and skip the empty one, if any. |
Also, a |
And, per RFC 2046 section 5.1.4, the parts should be in increasing preference order. Meaning text should come before HTML. This explains why I'm seeing the empty plain text version in Gmail. Never mind, I'll submit a PR. |
@alin-amana Are you working on this currently? This is a big enough issue that a new release will go out when it's fixed. |
Yup, working as we speak. |
Done, PTAL at #1009. |
Huh, missed that one. Thanks to all involved! |
* Do not rely on AArch64 CPUs to support 32-bit ARM for cross-testing. Signed-off-by: Alexey Kopytov <akopytov@gmail.com> * aarch64 like ppc64le reports 64k node_sockstat_TCP_mem_bytes due to 64k pages. Signed-off-by: Alexey Kopytov <akopytov@gmail.com>
added email notification text content support (configuration text)
added default email notification text content default value empty
converted email notification from html to multipart/alternatives with support to both html (first) and text (last)
ignore intellij IDE .idea working folder