How to use smtp lib with values coming from a form?

0

I have two files the idea was to get the data from form.py and use it to send an email with smtplib follows the codes form.py:

#!/usr/bin/python
# cabecalho que informa o browser para renderizar como HTML
print "Content-Type: text/html\n\n"
# o conteudo em si
print '''<html>

    <h1>E-mail com SMPT</h1>

    <form action="email.py" method="post">
        <div>
            <label for="login">Login:</label>
            <input type="text" name="login">
        </div>
        <div>
            <label for="senha">Senha:</label>
            <input type="password" name="senha">
        </div>
        <div>
            <label for="destinatario">Destinatario:</label>
            <input type="text" name="destinatario">
        </div>
        <div>
            <label for="mensagem">Mensagem:</label>
            <textarea name="mensagem"></textarea>
        </div>
        <input type="submit" value ="Submit" />
    </form>

    </html>'''

And email.py

#!/usr/bin/python

# Import modules for CGI handling
import cgi, cgitb

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
login = form.getvalue('login')
senha = form.getvalue('senha')
destinatario = form.getvalue('destinatario')
mensagem = form.getvalue('mensagem')

print "Content-type:application"
#!/usr/bin/python
import smtplib
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(login,senha)
server.sendmail(login, destinatario, mensagem)
print <h2>"Email enviado com sucesso!"</h2>
    
asked by anonymous 05.05.2018 / 03:26

0 answers