11# Sends an image to a designated user over email
22# and if we do, address concerns about user privacy, possibly IP locking them?
3- import base64
43import config
5- from sendgrid import SendGridAPIClient
6- from sendgrid .helpers .mail import (
7- Mail ,
8- Attachment ,
9- FileContent ,
10- FileName ,
11- FileType ,
12- Disposition ,
13- )
4+ import smtplib
5+ from email .mime .text import MIMEText
6+ from email .mime .application import MIMEApplication
7+ from email .mime .multipart import MIMEMultipart
148
159from camlib import current_order
1610
@@ -19,7 +13,7 @@ def digicam_sender(file_path: str, user_email: str, is_for_card: bool):
1913 """Sends the images to the users email"""
2014
2115 # Sending is optional.
22- if config .sendgrid_key is None :
16+ if config .smtp_key is None :
2317 return
2418
2519 html_content = """Hello!
@@ -38,33 +32,28 @@ def digicam_sender(file_path: str, user_email: str, is_for_card: bool):
3832
3933The WiiLink Team"""
4034
41- msg = Mail (
42- 43- to_emails = user_email ,
44- subject = "Here is your order!" ,
45- html_content = html_content ,
46- )
47-
4835 with open (file_path , "rb" ) as f :
4936 data = f .read ()
5037 f .close ()
5138
52- encoded_file = base64 .b64encode (data ).decode ()
39+ msg = MIMEMultipart ()
40+ msg .attach (MIMEText (html_content ))
5341
5442 if is_for_card :
55- msg .attachment = Attachment (
56- FileContent (encoded_file ),
57- FileName ("business_card.jpeg" ),
58- FileType ("application/jpeg" ),
59- Disposition ("attachment" ),
60- )
43+ part = MIMEApplication (data , Name = "business_card.jpeg" )
44+ part ['Content-Disposition' ] = f'attachment; filename="business_card.jpeg"'
6145 else :
62- msg .attachment = Attachment (
63- FileContent (encoded_file ),
64- FileName ("images.zip" ),
65- FileType ("application/zip" ),
66- Disposition ("attachment" ),
67- )
46+ part = MIMEApplication (data , Name = "images.zip" )
47+ part ['Content-Disposition' ] = f'attachment; filename="images.zip"'
48+
49+ msg .attach (part )
50+
51+ msg ["Subject" ] = "Here is your order!"
52+ 53+ msg ["To" ] = user_email
6854
69- sg = SendGridAPIClient (config .sendgrid_key )
70- sg .send (msg )
55+ s = smtplib .SMTP ("mail.postale.io" , 587 )
56+ s .starttls ()
57+ s .
login (
'[email protected] ' ,
config .
smtp_key )
58+ s .sendmail (msg ['From' ], msg ['To' ], msg .as_string ())
59+ s .close ()
0 commit comments