How can I create a tag to include receiver name where I want in subject as well as in body

Viewed 24

This may be a stupid question or I am not smart enough to google things properly. No matter what I did, nothing worked. I want to create a tag like {{ fname }} which can be used in the subject as well as in the body to include the receiver's first name

Below is the sample of my code

class Reciver(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    fname = db.Column(db.String(100))       
    lname = db.Column(db.String(100))
    email = db.Column(EmailType, nullable = False)


@app.route('/send-email/',methods=['GET', 'POST'])
reciver = Reciver.with_entities(Reciver.email).all()
if request.method == 'POST':
    if form.validate_on_submit():
        with mail.connect() as conn:
            for i in reciver:
                msg = Message(sender = ('sender@gmail.com'), recipients = [i.email], subject = subject)
                msg.body = 'MESSAGE BODY'
                msg.html = 'MESSAGE BODY'
                conn.send(msg)
    return render_template('send_email.html', reciver=reciver)
else:
    render_template_string('Something went wrong')

Please help me out.

0 Answers
Related