-1
我使用Flak Mail從網站的聯繫表單發送電子郵件。聯繫表單還有一個sender
電子郵件ID字段。因此,當我收到「收件人」電子郵件ID的電子郵件時,我想將from
設置爲sender
電子郵件ID,以便在表單中輸入值。以下是處理電子郵件的類:如何在使用Flask郵件時設置發件人電子郵件ID
from flask_mail import Mail, Message
class SendMail:
def __init__(self, app):
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = '<password>'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
self.recipient_email = '[email protected]'
self.app = app
self.mail = Mail(self.app)
def compile_mail(self, name, email_id, phone_no, msg):
message = Message(name+" has a query",
sender = email_id,
recipients=[self.recipient_email])
message.html = "<b>Name : </b>"+name+"<br><b>Phone No :</b> "+phone_no+"<br><b>Message : </b>"+msg
return message
def send_mail(self, name, email_id, phone_no, msg):
message = self.compile_mail(name, email_id, phone_no, msg)
with self.app.app_context():
self.mail.send(message)
send_mail
方法接收四個參數是哪些領域的聯繫表格上輸入。問題是,當我發送這樣的電子郵件時,儘管事實上我將郵件對象中的sender
參數設置爲email_id
,但收到的電子郵件中的from
被設置爲SMTP MAIL_USERNAME [email protected]
。 無法弄清楚如何將發件人設置爲我想要的值。
是的,它是正確的。我調試了代碼來檢查它。 –