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
Make SMTP notify send images as attachments if html is disabled #93562
Conversation
@aptalca I think it would be helpful to get consensus on whether your proposal is preferred behaviour. It looks like this feature was added way back in #2738 by @partofthething. So might be worth reaching out to see if there was another reason for the original choice. I expect many users don't realise that inline images mean an email is html, so this change might force them to
If that's the case an option flag for inline images might be better? |
Thanks @davet2001 It looks like when the image attachment functionality was PRed in, there was no support for html emails. It was all plain text. So it seems the decision of sending them as inline html was just a personal choice by the dev. There was no plain text vs html choice given to the user. Later, when html was added as an option to the integration, the image addition forcing plain text to html probably should have been changed as it became problematic. Because at that point plain text vs html became a deliberate choice given to the users, and the forced html behavior goes against that choice. As far as consensus goes, not sure how to get that. This integration does not have a maintainer and apart from a few forum posts asking how to add images as attachments rather than inline, that end with |
Discord or user forums could help. https://analytics.home-assistant.io/integrations/ gives the approx number of people using this integration (currently >=3536). I think there's quite a high chance that some of them would not want the behaviour to change. If it did change, I suggest you would need to provide some instructions on how to restore old behaviour. For example, if a user does want inline images, what should they change their YAML to?
But given that new YAML configuration options are no longer allowed, the first step might be to convert it to be set up via the UI, then make the change. This is clearly more work and probably not what you were hoping for. I genuinely don't know what the use cases are. It could be that no one wants html. But my experience is that if you change something that affects users who were already happy, they will expect immediate guidance on how to make it work like it used to. |
Hi. Thanks for reaching out. I am still using this, and am totally fine with this change. Seems like an improvement to me, and I'll have no problem adjusting my config as necessary. |
That's a good point. I'll try and come up with a way to maintain the current behavior by default and add a flag for selecting attachments vs inline. |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
I gave this more thought and I'm personally not in favor of keeping the current behavior because it would be very confusing. The email should be html when the user selects and inputs html. If not, it should be plain text. That's my opinion. In any case, that's not a coding decision, but a behavior decision so it's not really up to me. HA team will have to decide since there is no maintainer for this core integration. Thanks |
Ok, I suggest adding a description of what the user has to do if they want the images to stay inline. This can be added to the PR description. That can then be included in the breaking changes in the release notes. I think an example YAML snippet is needed with HTML, ready for copy/paste. |
thanks @davet2001 Also improved attachment handling where it could add double headers if the file's MIME type could not be determined as image. |
@aptalca The CI is failing, please can you check and run it locally? |
Fixed formatting. Thanks for the heads up. |
47844e6
to
849c60b
Compare
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 looks good to me, the change is as described and the updated documentation is accurate.
Requested 2nd opinion to make sure others are happy with the user impact.
update smtp test to detect content_type for plain txt + image
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.
The change makes perfect sense and the behavior more logical.
Thanks @aptalca 👍
Breaking change
SMTP integration will send images as attachments to a plain text email instead of html in-line when the
html
field is not set. Previous behavior was to send all images as html in-line even when thehtml
field was not set. To continue sending images as in-line, please set the optionalhtml
field and include the images as<img src="cid:image_name.ext">
within the html block as described in the docs: https://www.home-assistant.io/integrations/smtp/#usageProposed change
Current behavior:
html
orimages
defined), is sent as plain textimages
defined (nohtml
defined) is sent as html with images in-linehtml
defined are sent as html with images in-line (if any)Proposed behavior:
html
orimages
defined), is sent as plain text (No change)images
defined (nohtml
defined) is sent as plain text with images as separate attachmentshtml
defined are sent as html with images in-line (if any) (No change)Only proposed change is to the second type listed above. Currently, if the user drafts a plain text message, but adds an image, it is force converted to html and sent that way. That is not the user's intention as they could have drafted an html message if that were the intention. This change respects the user's choice with regards to plain text vs html.
I personally consider this a bugfix, because currently a plain text email is force converted to html. Most notable issue it causes is when we try to use an email-sms gateway to send a text message to a cell phone (ie. email to
5555555555@msg.fi.google.com
). Without an image, email is sent plain text and is successfully delivered to the mobile device as a text/sms message. With an image, the mobile device displays the message body as raw html, and the inline images are entirely missing.With the proposed changes, a plain text email with images get delivered to the mobile device as a proper plain text mms, along with the pictures as mms attachments.
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: