@@ -43,9 +43,11 @@ def __init__(self, **opts):
4343 self .html = opts .get ('html' , '' )
4444 self .bcc = []
4545 self .add_bcc (opts .get ('bcc' , []))
46- self .reply_to = opts .get ('reply_to' , '' )
46+ self .reply_to = ''
47+ self .set_replyto (opts .get ('reply_to' , '' ))
4748 self .files = opts .get ('files' , {})
48- self .set_headers (opts .get ('headers' , '' ))
49+ self .headers = {}
50+ self .set_headers (opts .get ('headers' , {}))
4951 self .date = opts .get ('date' , rfc822 .formatdate ())
5052 self .content = opts .get ('content' , {})
5153 self .smtpapi = opts .get ('smtpapi' , SMTPAPIHeader ())
@@ -123,7 +125,18 @@ def add_bcc(self, bcc):
123125 self .add_bcc (email )
124126
125127 def set_replyto (self , replyto ):
126- self .reply_to = replyto
128+ name , email = rfc822 .parseaddr (replyto .replace (',' , '' ))
129+ if name and email :
130+ self .set_reply_to_name (replyto )
131+ elif email :
132+ self .reply_to = email
133+
134+ def set_reply_to_name (self , replyto ):
135+ headers = {
136+ "Reply-To" : replyto
137+ }
138+ self .reply_to = ''
139+ self .set_headers (headers )
127140
128141 def add_attachment (self , name , file_ ):
129142 if sys .version_info < (3 , 0 ) and isinstance (name , unicode ):
@@ -146,10 +159,14 @@ def add_content_id(self, cid, value):
146159 self .content [cid ] = value
147160
148161 def set_headers (self , headers ):
162+ if sys .version_info < (3 , 0 ) and isinstance (headers , unicode ):
163+ headers = headers .encode ('utf-8' )
164+ if isinstance (self .headers , str ):
165+ self .headers = json .loads (self .headers )
149166 if isinstance (headers , str ):
150- self . headers = headers
151- else :
152- self .headers = json . dumps ( headers )
167+ headers = json . loads ( headers )
168+ for key , value in headers . iteritems () :
169+ self .headers [ key ] = value
153170
154171 def set_date (self , date ):
155172 self .date = date
0 commit comments