can anyone help me, i have developed flask api with form which is sending email using SMTPLIB. i'm using smtp gmail and also 587 port. this is my code.
s = smtplib.SMTP('smtp.gmail.com',587)
@app.route('/',methods=["GET","POST"])
def index():
if request.method == 'POST':
mails = request.form['email']
from_ = request.form['name']
msg = request.form['message']
fromredis = redis_server.get(mails)
if(fromredis):
flash("mail server busy, try again later or whatsapp me instead !","warn")
return redirect(url_for('index')+'#contact')
else:
if mails != '' and from_ != '' and msg != '':
sender = "mybotmailer2023@gmail.com"
rec = ["dafageraldine16@gmail.com",mails]
pwd = "movsydghkpnxqiad"
msg_embed = """From: <%s>
To: <%s>
Subject: Sended From Portfolio Web
<%s>
Pesan ini dikirim melalui smtplib dan diterima oleh modul SMTP Server Python.
""" %(from_,str(rec[0])+','+str(rec[1]),'Dari '+ str(from_) + ' untuk dafa geraldine, ' + str(msg))
try:
s.starttls()
s.login(sender,pwd)
s.sendmail(sender,rec,msg_embed)
redis_server.set(mails,mails)
redis_server.expire(mails,7200)
flash("an email has been sent, check your mail box !","success")
return redirect(url_for('index')+'#contact')
except:
try:
s.login(sender,pwd)
s.sendmail(sender,rec,msg_embed)
redis_server.set(mails,mails)
redis_server.expire(mails,7200)
flash("an email has been sent, check your mail box !","success")
return redirect(url_for('index')+'#contact')
except:
flash("error send email, please try again later or whatsapp instead !","danger")
return redirect(url_for('index')+'#contact')
return render_template("index.html")