def send_feedback(name, email, subject, message): msg = Message(subject, sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = name + ' ' + email + ' ' + message msg.html = name + ' ' + email + ' ' + message mail.send(msg)
def send_email(email, code): msg = Message( subject='消息接收邮箱验证', recipients=[email + '@yiduyongche.com'] ) msg.body = '【一度用车-前端日志监控】验证码:' + str(code) + ', 该验证码5分钟内有效。为了保障您的账户安全,请勿向他人泄漏验证码信息。' mail.send(msg)
def send_async_email(app, msg): with app.app_context(): try: mail.send(msg) print('Mail sent') except ConnectionRefusedError: return 'MAIL SERVER] not working', 500
def send_mail(to, subject, template, **kwargs): msg = Message(subject, recipients=[to], sender=app.config['MAIL_USERNAME']) msg.body = render_template(template + '.txt', **kwargs) # msg.html = render_template(template + '.html', **kwargs) mail.send(msg)
def sendEmail(to, header, body): msg = Message( header, recipients=to ) msg.body = "body" msg.html = body mail.send(msg)
def send_async_email(email, subject, link): """Background task to send an email with Flask-Mail.""" msg = Message(subject, sender=app.config['MAIL_DEFAULT_SENDER'], recipients=[email], html=link) msg.body = "Your confirmation link is here: " with app.app_context(): mail.send(msg)
def sendEmail(to, replyTo, sender, header, body): msg = Message(header, recipients=to, reply_to=replyTo, sender=sender) msg.body = "body" msg.html = body mail.send(msg) #For Development, uncomment to use function from command line # with app.app_context(): # mail.send(msg)
def send_async_email(app, msg): """ 利用多執行緒來處理郵件寄送,因為使用另一執行緒來寄信, 所以需要利用app_context來處理。 :param app: 實作Flask的app :param msg: 實作Message的msg :return: """ with app.app_context(): mail.send(msg)
def send_password_reset_email(user): token = user.get_reset_password_token() msg = Message('Reset your password', sender='Слайдовалюта', recipients=[user.email]) link = 'https://slide-wallet.firebaseapp.com/auth/restore-password?token=' + \ str(token)[2:-1] msg.body = render_template('reset_password.txt', user=user, link=link) msg.html = render_template('reset_password.html', user=user, link=link) mail.send(msg)
def send_support_email(body, user): msg = Message('Technical Support message', sender='Слайдовалюта', recipients=[app.config['MAIL_USERNAME']]) msg.body = render_template('technical_support.txt', user=user, body=body) msg.html = render_template('technical_support.html', user=user, body=body) mail.send(msg)
def send_email(email_token, recepient): html = """<div> <p>Здравствуйте, !</p> <p>Перейдите по этой <a href='https://vak.ictlab.kg:7003/confirm/{}' target=""_blank>{}</a></p> </div>""".format(email_token, email_token) msg = Message( 'Подтверждение почты', sender=MAIL_USERNAME, html=html, recipients=[recepient]) mail.send(msg) return
def contact(): contact_form = ContactForm() if request.method == 'POST': if contact_form.validate() == False: flash('All fields are required.') return render_template('contact.html', form=contact_form, success=False) else: msg = Message(contact_form.subject.data, sender=mail_info['mail_username'], recipients=[mail_info['mail_username']]) msg.body = "Contact Information \n Name: {} \n Mail: {} \n Content: {}".format(contact_form.name.data, contact_form.email.data, contact_form.message.data) mail.send(msg) return render_template('contact.html', success=True) elif request.method == 'GET': return render_template('contact.html', form=contact_form, success=False)
def send_details_account(form, type): password = password_generator() hash_password = generate_password_hash(password) if type == 'new_user': subject = 'Account details for Maya translator website' new_user = Account(email=form.email.data, pswd=hash_password, isAdmin=form.isAdmin.data) db.session.add(new_user) elif type == 'forget_update': subject = 'Your new password for your account on Maya translator website' user = Account.query.filter_by(email = form.email.data).first() user.pswd = hash_password db.session.commit() msg = Message(subject, sender = '*****@*****.**', body='Your login is :'+ form.email.data +' and your password is '+password, recipients = [form.email.data]) mail.send(msg)
def send_mail(sender, recipients, subject, template, mailtype='html', **kwargs): """ sender:的部份可以考慮透過設置default recipients:記得要list格式 subject:是郵件主旨 template: mailtype=body:郵件內容文字 mailtype=txt、html:樣板名稱 mailtype: html:html樣板(預設) txt:txt樣板 body:文字方式 **kwargs:參數 """ # app = current_app._get_current_object() # msg = Message(subject, # sender=sender, # recipients=recipients) # if mailtype == 'html': # msg.html = render_template(template + '.html', **kwargs) # elif mailtype == 'txt': # msg.body = render_template(template + '.txt', **kwargs) # elif mailtype == 'body': # msg.body = template # # # 使用多線程 # thr = Thread(target=send_async_email, args=[app, msg]) # thr.start() # return thr subject = subject # message = '這是 flask-mail example <br> <br>' \ # '附上一張圖片 <br> <br>' \ # '<b style="color:#FF4E4E" >新垣結衣</b>' if mailtype == 'html': message = render_template(template + '.html', **kwargs) elif mailtype == 'txt': message = render_template(template + '.txt', **kwargs) elif mailtype == 'body': message = template msg = Message( subject=subject, recipients=recipients, html=message ) # msg.body = '純文字' # with app.open_resource("static/images/image.jpg") as fp: # msg.attach("image.jpg", "image/jpg", fp.read()) mail.send(msg)
def sendEmail(to, replyTo, sender, header, body): msg = Message( header, recipients=to, reply_to = replyTo, sender = sender ) msg.body = "body" msg.html = body mail.send(msg) #For Development, uncomment to use function from command line # with app.app_context(): # mail.send(msg)
def send_email(body_md, sender=None, recipients=None): body_md = body_md.strip() assert body_md.startswith('Subject: ') subject, _, body_md = body_md.partition('\n') _, _, subject = subject.partition(' ') if not sender: sender = default_sender if not recipients: recipients = [default_recipient] msg = Message(subject) msg.recipients = recipients msg.sender = sender msg.html = textwrap.fill(markdown_no_math(body_md), 990) msg.body = text_maker.handle(msg.html) mail.send(msg)
def send_password_reset_email(user): token = user.get_reset_password_token() msg = Message('Reset your password', sender='*****@*****.**', recipients=[user.email]) link = 'https://real-estate-research-6f694.firebaseapp.com/auth/restore-password?token=' + \ str(token)[2:-1] msg.body = render_template('reset_password.txt', user=user, link=link) msg.html = render_template('reset_password.html', user=user, link=link) # thr = Thread(target=async_send_mail, args=[app, msg]) # thr.start() # return thr mail.send(msg)
def post(self): args = invite_parser.parse_args() invite = InviteModel(args['email'], args['team_id']) team = TeamModel.query.get(args['team_id']) invite.save_to_db() try: msg = Message("Alert From Taskify", sender="*****@*****.**", recipients=[args['email']]) msg.body = "You have been invited to team {} , please sign in to taskify and start Collaborating, https://taskify-initial.herokuapp.com/ {}".format( team.name) mail.send(msg) return invite_schema.dump(invite) except Exception as e: return {'message': 'Something went wrong'}, 500
def send_mail(subject, receiver, plaintext, html=None): try: # Fill out the email fields message = Message() message.subject = subject message.sender = ("HawkAir", "*****@*****.**") message.add_recipient(receiver) # Add HTML/plain-text parts to message message.body = plaintext if html is not None: message.html = html # Send email with app.app_context(): mail.send(message) return 200 except Exception as e: return 500
def mail_sender(app, msg, to, subject): with app.app_context(): try: mail.send(msg) except smtplib.SMTPAuthenticationError as e: print("Error de autenticacion: " + str(e)) write_logmail(e, "Error de autenticacion: ", subject, to) except smtplib.SMTPServerDisconnected as e: print("Servidor desconectado: " + str(e)) write_logmail(e, "Servidor descontctado: ", subject, to) except smtplib.SMTPSenderRefused as e: print("Se requiere autenticacion: " + str(e)) write_logmail(e, "Se requiere autenticacion: ", subject, to) except smtplib.SMTPException as e: print("Unexpected error: " + str(e)) write_logmail(e, "Unexpected error: ", subject, to)
def post(self, team_id, user_id): user = UserModel.query.get(user_id) team = TeamModel.query.get(team_id) team.members.append(user) team.update_db() try: msg = Message("Alert From Taskify", sender="*****@*****.**", recipients=[user.email]) msg.body = "You have been added to team {} , please sign in to taskify and start Collaborating".format( team.name) mail.send(msg) return { "message": "added user {} to team {}, Mail Sent".format( user.name, team.name) } except Exception as e: return "added user {} to team {}, Mail Failed".format( user.name, team.name)
def send_email(to, subject, body): msg = Message(subject, recipients=[to], body=body, sender=app.config['MAIL_DEFAULT_SENDER']) mail.send(msg)
def register_student(): conn = connect("localhost", "root", "password", "jee") cursor = conn.cursor() # registration step 1 start here if "student/register/info" in request.referrer: cursor.execute("SELECT id FROM student ORDER BY id DESC LIMIT 1") ID = cursor.fetchall() newID = 1000 if ID: newID = int(ID[0][0]) + 1 session['username'] = request.form['name'].upper() session['father_name'] = request.form['father_name'].upper() session['mother_name'] = request.form['mother_name'].upper() session['gender'] = request.form['gender'].upper() session['state_of_eligibility'] = request.form['state_of_eligibility'].upper() session['date_of_birth'] = request.form['date'] + "-" + request.form['month'] + "-" + request.form['year'] session['category'] = request.form['category'].upper() session['pwd'] = request.form['pwd'].upper() session['applying_for'] = request.form['applying_for'].upper() session['mode_of_exam'] = request.form['mode_of_exam'].upper() session['paper_medium'] = request.form['paper_medium'].upper() session['address'] = request.form['address'].upper() session['email'] = request.form['email'] session['phone'] = request.form['phone'].upper() session['photo'] = None session['signature'] = None session['marksheet'] = None session['step_1'] = 1 session['step_2'] = None session['step_3'] = None session['physics'] = 0 session['chemistry'] = 0 session['maths'] = 0 session['AIR'] = None session['upload_verified'] = None session['info_verified'] = None session['obc_rank'] = None session['sc_rank'] = None session['st_rank'] = None cursor.execute('''INSERT INTO student(id,name,father_name,mother_name,gender,state_of_eligibility,date_of_birth,category, pwd,applying_for,mode_of_exam,paper_medium,address,email,phone,password,step_1) VALUES({newID},'{username}', '{father_name}','{mother_name}','{gender}','{state_of_eligibility}','{date_of_birth}','{category}','{pwd}','{applying_for}', '{mode_of_exam}','{paper_medium}','{address}','{email}','{phone}','{passwd}',1) '''.format(newID=newID, **session, passwd=request.form[ 'passwd'])) cursor.execute('''INSERT INTO credential(id,name,password) VALUES(%d,'%s','%s')''' % ( newID, session['username'], request.form['passwd'])) conn.commit() conn.close() session['id'] = newID session['password'] = request.form['passwd'] # email send here from run import mail msg = Message('JEE MAIN Registration', sender='noreply@gmail', recipients=['*****@*****.**']) msg.body = f'''Your Registration ID : %d''' % (session['id']) mail.send(msg) flash("Your registration ID is sent to your email address") # return redirect(url_for('student.register_step_2')) # registrations step 2 start here elif "student/register/upload" in request.referrer: ALLOWED_EXTENSION = ['jpg', 'jpeg'] UPLOAD_FOLDER = 'static/student/' + str(session['id']) image = request.files['image'] signature = request.files['signature'] marksheet = request.files['marksheet'] # hashed filenames image.filename = image.filename + str(session['id']) # session id signature.filename = signature.filename + str(session['id']) marksheet.filename = marksheet.filename + str(session['id']) image.filename = hashlib.md5(image.filename.encode()).hexdigest() signature.filename = hashlib.md5(signature.filename.encode()).hexdigest() marksheet.filename = hashlib.md5(marksheet.filename.encode()).hexdigest() if not os.path.exists(UPLOAD_FOLDER): os.mkdir(UPLOAD_FOLDER) image_path = os.path.join(UPLOAD_FOLDER + "/", image.filename) signature_path = os.path.join(UPLOAD_FOLDER + "/", signature.filename) # session id marksheet_path = os.path.join(UPLOAD_FOLDER + "/", marksheet.filename) print(image_path) print(signature_path) print(marksheet_path) cursor.execute('''UPDATE student SET photo='/%s',signature='/%s',marksheet='/%s',step_2=1 WHERE id=%d''' % (image_path, signature_path, marksheet_path, session['id'])) conn.commit() conn.close() image.save(image_path) signature.save(signature_path) marksheet.save(marksheet_path) session['photo'] = image_path session['signature'] = signature_path session['marksheet'] = marksheet_path session['step_2'] = 1 return redirect(url_for("student.register_step_3")) # registration step 3 start here elif "student/register/payment" in request.referrer: cursor.execute("UPDATE student SET step_3=1") conn.commit() conn.close() session['step_3'] = 1 return redirect(url_for('student.fake_payment_page'))
def async_send_mail(app, msg): with app.app_context(): mail.send(msg)
def sendEmail(to, header, body): msg = Message(header, recipients=to) msg.body = "body" msg.html = body mail.send(msg)
def send_email(to, subject, template): msg = Message(subject, recipients=[to], html=template, sender=app.config['MAIL_DEFAULT_SENDER']) mail.send(msg)