Dash app + sending email

Hi there,

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

thank you for your quick reply!

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 :slight_smile: )

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 :slight_smile: ), but it would be nice if I could get to use the dash component into the body of the email message.

Hi there,

I have got it to work with dash by replacing app.config with app.server.config.

However, I am still wondering how I can use dash component into an email, basically how to convert a dash component into html code.

Thanks in advance for any suggestions !

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.

Ok clear thanks!