need to add api to send emails
This commit is contained in:
@@ -22,6 +22,15 @@ def verify_token(token):
|
|||||||
return token == secret_token
|
return token == secret_token
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/send-email', methods=['POST'])
|
||||||
|
@auth.login_required
|
||||||
|
@cross_origin()
|
||||||
|
def send_email():
|
||||||
|
data_in_json = request.get_json()
|
||||||
|
print(data_in_json)
|
||||||
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from mailjet_rest import Client
|
||||||
|
|
||||||
|
api_key = "489274f04d5c155f81370fccc3904e20"
|
||||||
|
api_secret = "edac41f0e1726ba49808dfb12204ecd6"
|
||||||
|
|
||||||
|
|
||||||
|
class MailSender:
|
||||||
|
def __init__(self, dest_email, email_body, store: str, contact_name: str, from_email="no-reply@lpaconsulting.fr"):
|
||||||
|
self.mailjet_client = Client(auth=(api_key, api_secret), version='v3.1')
|
||||||
|
self.store = store
|
||||||
|
self.from_email = from_email
|
||||||
|
self.dest_email = dest_email
|
||||||
|
self.contact_name = contact_name
|
||||||
|
self.email_body = email_body
|
||||||
|
|
||||||
|
def send(self):
|
||||||
|
data = {
|
||||||
|
'Messages': [
|
||||||
|
{
|
||||||
|
"From": {
|
||||||
|
"Email": self.from_email,
|
||||||
|
"Name": self.store
|
||||||
|
},
|
||||||
|
"To": [
|
||||||
|
{
|
||||||
|
"Email": self.dest_email,
|
||||||
|
"Name": self.contact_name
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Subject": "Your appointment is confirmed!",
|
||||||
|
"HTMLPart": self.email_body
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return self.mailjet_client.send.create(data=data)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from src.pojo.contact_pojo import ContactPojo
|
||||||
|
|
||||||
|
|
||||||
|
class EmailReceiver:
|
||||||
|
def __init__(self, mail_address: str, store_type: int, id: str, date: str):
|
||||||
|
self.mail_address = mail_address
|
||||||
|
self.store_type = store_type
|
||||||
|
self.appointment_id = id
|
||||||
|
self.appointment_date = date
|
||||||
@@ -1,53 +1,29 @@
|
|||||||
"""
|
|
||||||
Run:
|
|
||||||
"""
|
|
||||||
from mailjet_rest import Client
|
|
||||||
|
|
||||||
from src import config
|
from src import config
|
||||||
|
from src.mail.mail_sender import MailSender
|
||||||
|
|
||||||
api_key = "489274f04d5c155f81370fccc3904e20"
|
store = "Hermès Paris Faubourg"
|
||||||
api_secret = "edac41f0e1726ba49808dfb12204ecd6"
|
# store = "Hermès Paris George V"
|
||||||
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
|
|
||||||
from_email = "no-reply@lpaconsulting.fr"
|
|
||||||
# store = "Hermès Paris Faubourg"
|
|
||||||
store = "Hermès Paris George V"
|
|
||||||
# store = "Hermès Paris Sèvres"
|
# store = "Hermès Paris Sèvres"
|
||||||
# dest_email = "928490803@qq.com"
|
# dest_email = "928490803@qq.com"
|
||||||
# dest_email = "1757344572@qq.com"
|
# dest_email = "1757344572@qq.com"
|
||||||
# dest_email = "392417782@qq.com"
|
# dest_email = "392417782@qq.com"
|
||||||
# dest_email = "linghuili@hotmail.com"
|
# dest_email = "linghuili@hotmail.com"
|
||||||
|
dest_email = "panleicim@gmail.com"
|
||||||
# dest_email = "fanfan19810617@icloud.com"
|
# dest_email = "fanfan19810617@icloud.com"
|
||||||
# dest_email = "fanchunying323@163.com"
|
# dest_email = "fanchunying323@163.com"
|
||||||
# dest_email = "lytlaure@gmail.com"
|
# dest_email = "lytlaure@gmail.com"
|
||||||
dest_email = "arianezhangsn@yahoo.com"
|
# dest_email = "arianezhangsn@yahoo.com"
|
||||||
|
# dest_email = "tranthu.ht1983@gmail.com"
|
||||||
|
# dest_email = "124652097@qq.com"
|
||||||
# dest_email = "sunrose75015@gmail.com"
|
# dest_email = "sunrose75015@gmail.com"
|
||||||
# dest_email = "1340219934@qq.com"
|
# dest_email = "1340219934@qq.com" #小于
|
||||||
# dest_email = "lytlaure@gmail.com"
|
# dest_email = "lytlaure@gmail.com"
|
||||||
# dest_email = "m13805869912@163.com"
|
# dest_email = "m13805869912@163.com"
|
||||||
# dest_email = "tangliang0411@gmail.com"
|
# dest_email = "tangliang0411@gmail.com"
|
||||||
contact_name = "LU yaping"
|
contact_name = "YUAN Jinxuan"
|
||||||
|
|
||||||
f = open(config.ROOT_DIR + "/templates/confirmed_rdv.html", "r")
|
f = open(config.ROOT_DIR + "/templates/confirmed_rdv.html", "r")
|
||||||
email_body = f.read()
|
email_body = f.read()
|
||||||
print(email_body)
|
print(email_body)
|
||||||
data = {
|
sender = MailSender(dest_email=dest_email, email_body=email_body, store=store, contact_name=contact_name)
|
||||||
'Messages': [
|
print(sender.send().json)
|
||||||
{
|
|
||||||
"From": {
|
|
||||||
"Email": from_email,
|
|
||||||
"Name": store
|
|
||||||
},
|
|
||||||
"To": [
|
|
||||||
{
|
|
||||||
"Email": dest_email,
|
|
||||||
"Name": contact_name
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Subject": "Your appointment is confirmed!",
|
|
||||||
"HTMLPart": email_body
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
result = mailjet.send.create(data=data)
|
|
||||||
print(result.status_code)
|
|
||||||
print(result.json())
|
|
||||||
|
|||||||
Reference in New Issue
Block a user