|
@@ -13,12 +13,17 @@ import random
|
|
|
from starlette.status import HTTP_302_FOUND,HTTP_303_SEE_OTHER
|
|
|
import smtplib
|
|
|
import traceback
|
|
|
+import requests
|
|
|
+import threading
|
|
|
import os
|
|
|
from email.mime.text import MIMEText
|
|
|
from email.mime.image import MIMEImage
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
-import requests
|
|
|
-import threading
|
|
|
+import boto3
|
|
|
+from botocore.exceptions import ClientError
|
|
|
+from email.mime.base import MIMEBase
|
|
|
+from email.mime.application import MIMEApplication
|
|
|
+
|
|
|
|
|
|
app = FastAPI()
|
|
|
app.add_middleware(
|
|
@@ -30,6 +35,48 @@ app.add_middleware(
|
|
|
)
|
|
|
|
|
|
|
|
|
+def hhh_send_mail(email):
|
|
|
+ SENDER = "Gorgeous Space <noreply@hhh.com.tw>"
|
|
|
+ RECIPIENT = "jeweiliang@gmail.com"
|
|
|
+ AWS_REGION = "us-east-1"
|
|
|
+ CHARSET = "UTF-8"
|
|
|
+ client = boto3.client('ses',region_name=AWS_REGION)
|
|
|
+ # Try to send the email.
|
|
|
+ try:
|
|
|
+ #Provide the contents of the email.
|
|
|
+
|
|
|
+ msg = MIMEMultipart()
|
|
|
+ msg["Subject"] = "[幸福空間] 您的五萬元裝修折價券 "
|
|
|
+ msg["From"] = "noreply@hhh.com.tw"
|
|
|
+ msg["To"] = email
|
|
|
+
|
|
|
+ # Set message body
|
|
|
+ body = MIMEText("感謝填寫幸福空間問卷,這是您的五萬元裝修折價券\n", "plain")
|
|
|
+ msg.attach(body)
|
|
|
+
|
|
|
+ filename = "coupon.png" # In same directory as script
|
|
|
+
|
|
|
+ with open(filename, "rb") as attachment:
|
|
|
+ part = MIMEApplication(attachment.read())
|
|
|
+ part.add_header("Content-Disposition",
|
|
|
+ "attachment",
|
|
|
+ filename=filename)
|
|
|
+ msg.attach(part)
|
|
|
+
|
|
|
+ response = client.send_raw_email(
|
|
|
+ Source=msg["From"],
|
|
|
+ Destinations=[msg["To"]],
|
|
|
+ RawMessage={"Data": msg.as_string()}
|
|
|
+ )
|
|
|
+ print(response)
|
|
|
+
|
|
|
+ # Display an error if something goes wrong.
|
|
|
+ except ClientError as e:
|
|
|
+ print(e.response['Error']['Message'])
|
|
|
+ else:
|
|
|
+ print("Email sent! Message ID:"),
|
|
|
+ print(response['MessageId'])
|
|
|
+
|
|
|
def thread_mail(umail):
|
|
|
print('thread_mail called')
|
|
|
# r = requests.get('http://3.220.159.187:8081/mailto/'+umail)
|
|
@@ -108,7 +155,7 @@ app.mount("/a1", StaticFiles(directory="static"), name="static")
|
|
|
async def redirect():
|
|
|
# url = app.url_path_for("/a1/index.html")
|
|
|
response = RedirectResponse(url='/a1/index.html')
|
|
|
- x = threading.Thread(target=thread_mail, args=(1,))
|
|
|
+ x = threading.Thread(target=hhh_send_mail, args=('jared@choozmo.com',))
|
|
|
x.start()
|
|
|
return response
|
|
|
|