@@ -85,7 +85,7 @@ class ServiceUnavailableError(Error):
8585class EmailMessage (object ):
8686 """Main interface to SAE Mail Service
8787 """
88- _properties = ['to' , 'subject' , 'body' , 'html' , 'attachments' , 'smtp' ]
88+ _properties = ['to' , 'subject' , 'body' , 'html' , 'attachments' , 'smtp' , 'from_addr' ]
8989 _ext_to_disposition = {
9090 'bmp' : 'I' , 'css' : 'A' ,
9191 'csv' : 'A' , 'gif' : 'I' ,
@@ -186,7 +186,7 @@ def _to_proto(self):
186186 """Convert mail mesage to protocol message"""
187187 self .check_initialized ()
188188
189- args = {'from' : self .smtp [2 ],
189+ args = {'from' : getattr ( self , 'from_addr' , self .smtp [2 ]) ,
190190 'to' : self .to ,
191191 'subject' : self .subject ,
192192 'smtp_host' : self .smtp [0 ],
@@ -228,45 +228,10 @@ def _to_proto(self):
228228 def _remote_call (self , message ):
229229 args = json .loads (message ['saemail' ])
230230
231- import smtplib
232- from email import encoders
233- from email .Header import Header
234- from email .mime .text import MIMEText
235- from email .MIMEBase import MIMEBase
236- from email .MIMEMultipart import MIMEMultipart
237-
238- if args ['tls' ]:
239- s = smtplib .SMTP_SSL ()
240- else :
241- s = smtplib .SMTP ()
242-
243- s .connect (args ['smtp_host' ], args ['smtp_port' ])
244- s .login (args ['smtp_username' ], args ['smtp_password' ])
245-
246- msg = MIMEMultipart ()
247- msg ['From' ] = args ['from' ]
248- msg ['To' ] = args ['to' ]
249- msg ['Subject' ] = Header (args ['subject' ], 'utf-8' ).encode ()
250-
251- if args ['content_type' ] == 'plain' :
252- msg .attach (MIMEText (args ['content' ].encode ('utf-8' ), _charset = "utf-8" ))
253- else :
254- msg .attach (MIMEText (args ['content' ].encode ('utf-8' ), 'html' , _charset = "utf-8" ))
255-
256- for k , v in args .iteritems ():
257- if not k .startswith ('attach' ):
258- continue
259-
260- ap = k .split (':' )
261- part = MIMEBase ('application' , "octet-stream" )
262- part .set_payload (base64 .decodestring (v ))
263- encoders .encode_base64 (part )
264- part .add_header ('Content-Disposition' , 'attachment' , filename = ap [1 ])
265- msg .attach (part )
266-
267- s .sendmail (args ['from' ], args ['to' ].split (',' ), msg .as_string ())
268-
269- s .quit ()
231+ # just print the message on console
232+ print '[SAE:MAIL] Sending new mail'
233+ import pprint
234+ pprint .pprint (args )
270235
271236 def _get_headers (self ):
272237 access_key = core .get_access_key ()
0 commit comments