简体   繁体   中英

Send user authentication by mail

I am designing a program which the person (be user, admin, client, etc), register and this I sent an email with the authentication route and thus ends the registration process.

  1. the person enters the page and places his email and password.

  2. the app generates an access token and saves the email as identity, takes the email and sends the token with a link.

  3. when clicking on the link redirects to the page, the app searches for the access token and thus allow the user to finish their registration process (name, surname, address, telephone, etc).

I am using python together with the flask framework. so far I have to do the access token and the authentication required to access the different routes. my problem is to send the link with the token to the person's email.

for sending mail I am using the SMTPLIB and this is the code

user = 'xxxxxxxxxx@gmail.com'

password = 'xxxxxxxxx'


    remitente = 'xxxxxxxxxx@gmail.com'
    destinatario = destinatario
    asunto = 'Registro Exitoso'
    mensaje = 'ok: <a href="nuevoenlace">nuevoenlace</a>' 


gmail = smtplib.SMTP('smtp.gmail.com', 587)


gmail.starttls()


gmail.login(user, password)


header = MIMEMultipart()    
header['From'] = remitente
header['To'] = destinatario
header['Subject'] = asunto
mensaje = MIMEText(mensaje, 'html')
header.attach(mensaje)

    gmail.sendmail(remitente, destinatario, header.as_string())

    gmail.quit()

ok, my problem is to send the token by mail along with authentication link, this redirects me to a protected endpoint and finishes the entry process

If sending the email is the problem, here it says here you need to call gmail.ehlo() before calling gmail.starttls() . Find more information here: https://docs.python.org/3/library/smtplib.html

If this is not the problem, please provide more information or Stacktrace etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM