@@ -27,26 +27,26 @@ def set_email_config(email, password, sender_name=''):
27
27
_set_email_credentials (mail_cred , email , password , sender_name )
28
28
29
29
30
- def _send_email_helper (subject , message , to_addr = None , cc_addr = None , bcc_addr = None , attachment_path = None ):
30
+ def _send_email_helper (subject , message , to_addr = None , cc_addr = None , bcc_addr = None , attachment_path = None , html_text = None ):
31
31
global mail_cred
32
32
global SMTP_GMAIL_URL
33
33
34
34
to_addr , cc_addr , bcc_addr = _check_recipients (to_addr , cc_addr , bcc_addr )
35
35
36
36
client = smtplib .SMTP_SSL (SMTP_GMAIL_URL )
37
37
client = _login_client (client )
38
- recipients , email_body = _build_email (subject , message , to_addr , cc_addr , bcc_addr , attachment_path )
38
+ recipients , email_body = _build_email (subject , message , to_addr , cc_addr , bcc_addr , attachment_path , html_text = html_text )
39
39
client .sendmail (mail_cred .EMAIL_ID , recipients , email_body )
40
40
client .quit ()
41
41
return True
42
42
43
43
44
- def send_email (subject , message , to_addr = None , cc_addr = None , bcc_addr = None , attachment_path = None , is_async = True ):
44
+ def send_email (subject , message , to_addr = None , cc_addr = None , bcc_addr = None , attachment_path = None , html_text = None , is_async = True ):
45
45
global _send_email_helper
46
46
if is_async :
47
47
_send_email_helper = Async (_send_email_helper )
48
48
49
- return _send_email_helper (subject , message , to_addr , cc_addr , bcc_addr , attachment_path )
49
+ return _send_email_helper (subject , message , to_addr , cc_addr , bcc_addr , attachment_path , html_text )
50
50
51
51
52
52
def _login_client (client ):
@@ -78,7 +78,7 @@ def _check_recipients(to_addr, cc_addr, bcc_addr):
78
78
return to_addr , cc_addr , bcc_addr
79
79
80
80
81
- def _build_email (subject , text , to_emails , cc_emails , bcc_emails , attachment_path ):
81
+ def _build_email (subject , text , to_emails , cc_emails , bcc_emails , attachment_path , html_text ):
82
82
global mail_cred
83
83
if len (mail_cred .EMAIL_USER ) > 0 :
84
84
sender = mail_cred .EMAIL_USER + ' <' + mail_cred .EMAIL_ID + '>'
@@ -89,7 +89,10 @@ def _build_email(subject, text, to_emails, cc_emails, bcc_emails, attachment_pat
89
89
message ['To' ] = "," .join (to_emails )
90
90
message ['CC' ] = "," .join (cc_emails )
91
91
message ['Subject' ] = subject
92
- message .attach (MIMEText (text , 'plain' ))
92
+ if text is not None :
93
+ message .attach (MIMEText (text , 'plain' ))
94
+ if html_text is not None :
95
+ message .attach (MIMEText (html_text , 'html' ))
93
96
94
97
if attachment_path is not None :
95
98
attachment = open (attachment_path , 'rb' )
0 commit comments