I am prompting a user for input, but I have no idea how to include it in a python mail. This is the message field:
message = """\
Subject: Info
{input} """
The input is supposed to be where I put {input}
, how do I implement it?
I am prompting a user for input, but I have no idea how to include it in a python mail. This is the message field:
message = """\
Subject: Info
{input} """
The input is supposed to be where I put {input}
, how do I implement it?
You can use an fstring since python 3.6 (just put a f
before the """
), but don't forget to escape the content of the input for security reasons. Here is an example with the html module, available since python 3.2 :
import html
# ...
message = f"""
Subject: Info
{html.escape(input)}
"""
Otherwise the old way is to use .format()
:
import html
# ...
message = f"""
Subject: Info
{}
""".format(html.escape(input))
if you are below version 3.2, then you can escape the input manually:
text.replace('&', '&').replace('>', '>' ).replace('<','<').replace('\'',''' ).replace('"','"').encode('ascii', 'xmlcharrefreplace')
But except if you have heavy restrictions on python version, you should be using a recent version of python 3
.
you can check your python version with python --version
and/or python3 --version