def send_confirmation(name, email): msg = MIMEMultipart("related") msg["Subject"] = "[Alerta] Please verify your email '%s'" % email msg["From"] = app.config["MAIL_FROM"] msg["To"] = email msg.preamble = "[Alerta] Please verify your email '%s'" % email confirm_hash = str(uuid4()) db.set_user_hash(email, confirm_hash) text = ( "Hello {name}!\n\n" "Please verify your email address is {email} by clicking on the link below:\n\n" "{url}\n\n" "You're receiving this email because you recently created a new Alerta account." " If this wasn't you, please ignore this email.".format( name=name, email=email, url=absolute_url("/auth/confirm/" + confirm_hash) ) ) msg_text = MIMEText(text, "plain", "utf-8") msg.attach(msg_text) try: mx = smtplib.SMTP(app.config["SMTP_HOST"], app.config["SMTP_PORT"]) if app.config["DEBUG"]: mx.set_debuglevel(True) mx.ehlo() mx.starttls() mx.login(app.config["MAIL_FROM"], app.config["SMTP_PASSWORD"]) mx.sendmail(app.config["MAIL_FROM"], [email], msg.as_string()) mx.close() except (socket.error, socket.herror, socket.gaierror) as e: LOG.error("Mail server connection error: %s", str(e)) return except smtplib.SMTPException as e: LOG.error("Failed to send email : %s", str(e)) except Exception as e: LOG.error("Unhandled exception: %s", str(e))
def send_confirmation(name, email): msg = MIMEMultipart('related') msg['Subject'] = "[Alerta] Please verify your email '%s'" % email msg['From'] = app.config['MAIL_FROM'] msg['To'] = email msg.preamble = "[Alerta] Please verify your email '%s'" % email confirm_hash = str(uuid4()) db.set_user_hash(email, confirm_hash) text = 'Hello {name}!\n\n' \ 'Please verify your email address is {email} by clicking on the link below:\n\n' \ '{url}\n\n' \ 'You\'re receiving this email because you recently created a new Alerta account.' \ ' If this wasn\'t you, please ignore this email.'.format( name=name, email=email, url=absolute_url('/auth/confirm/' + confirm_hash)) msg_text = MIMEText(text, 'plain', 'utf-8') msg.attach(msg_text) try: mx = smtplib.SMTP(app.config['SMTP_HOST'], app.config['SMTP_PORT']) if app.config['DEBUG']: mx.set_debuglevel(True) mx.ehlo() mx.starttls() mx.login(app.config['MAIL_FROM'], app.config['SMTP_PASSWORD']) mx.sendmail(app.config['MAIL_FROM'], [email], msg.as_string()) mx.close() except (socket.error, socket.herror, socket.gaierror) as e: LOG.error('Mail server connection error: %s', str(e)) return except smtplib.SMTPException as e: LOG.error('Failed to send email : %s', str(e)) except Exception as e: LOG.error('Unhandled exception: %s', str(e))