As per subject, I am building a dash web app with dash and I would like to integrate a page where I can send email to user (for exemple user verification code or newsletter)
I have got it to work with “pure” Flask, but I am not to able to integrate flask mail lib into a dash app.
Has anyone already done something similar?
Otherwise I should use other python library to do that, but as dash is built on flask I thought I would make sense to use flask to send email, isn’t it?
If you have a solution working with flask, I believe it should be doable to adopt it to make it work with Dash. Did you try applying you currently solution using Flask object that serves as the Dash backend?
app = dash.Dash(__name__)
sever = app.server # this is a flask.Flask object
I think I have kind of already tried that but I have got 2 problem (which I think they could be easily solved but I do not know how )
firstly, when I try to set the email server into the app.config
app.config['MAIL_SERVER'] = 'smtp server address here'
I get the following error:
AttributeError: (‘Invalid config key. Some settings are only available via the Dash constructor’, ‘MAIL_SERVER’)
Secondly, I would like to add to the body of the email some dash component or dash/boostrap component (cards, buttons, or simply html.P etc…) or even some images, but I am not sure how. I guess this is not a big deal (I would mean that I should learn to code in html ), but it would be nice if I could get to use the dash component into the body of the email message.
This isn’t supported as is. Dash components serialized as JSON data structures that are passed to the Javascript front end and turned into HTML tags with Javascript. There isn’t a way to convert these components into HTML tags directly in Python.
Have you looked into any conversion tools? I’d image that if these were html or even dcc components, it could handle the structure of the change.
However, if you were to do something, like a clientside callback that takes the target components innerHTML and places that in a string that is then passed to the email. That could work. You could even just place the string in to a dcc.Store and use that to trigger the sending of the email.
Things to watch out for in this approach, you aren’t going to have your styling natively appear, so that makes it tricky. All things will be provided in the email from the component. And all scripts that interact with the components will not transfer either.