def sendEmail(self, dicValues, liAttachments,dicUser ): cuonmail = Email(smtp_server = "localhost") print ' send mail' if liAttachments: cuonmail.attachments = liAttachments else: cuonmail.attachments = [] ok = '' try: dicValues = self.replaceValues(dicValues) if dicUser.has_key('Email'): dicEmail = dicUser['Email'] ## self.Email['From']='MyAddress@mail_anywhere.com' ## self.Email['Host']='mail_anywhere.com' ## self.Email['Port']='25' ## self.Email['LoginUser']='******' ## self.Email['Password']='******' ## self.Email['Signatur']='NONE' print '1' if dicEmail['LoginUser'] != 'login': self.EMAILUSER = dicEmail['LoginUser'] print '2' if dicEmail['Password'] != 'secret': self.EMAILPASSWORD = dicEmail['Password'] print '3' if dicEmail['Host'] != 'mail_anywhere.com': self.EMAILSERVER = dicEmail['Host'] if dicValues.has_key('From'): cuonmail.from_address = dicValues['From'] print '4' print dicValues if dicValues.has_key('To'): #print 'send mail to ', dicValues['To'] liTo = dicValues['To'].split(',') for s in liTo: cuonmail.recipients.add(s) if dicValues.has_key('CC') and dicValues['CC'] is not None: #print 'send mail to ', dicValues['To'] liCc = dicValues['CC'].split(',') for s in liCc: cuonmail.cc_recipients.add(s) if dicValues.has_key('BCC') and dicValues['BCC'] is not None: #print 'send mail to ', dicValues['To'] liBcc = dicValues['BCC'].split(',') for s in liBcc: cuonmail.bcc_recipients.add(s) print '6' if dicValues.has_key('Subject'): cuonmail.subject = dicValues['Subject'] else: cuonmail.subject = 'No Subject' print '7' if dicValues.has_key('Body'): #print 'dicValues = ', dicValues.keys() # workaround for python 2.6 try: dicValues['Body'] = dicValues['Body'].encode('UTF-8') except: pass dicValues['Body'] = self.normalizeHtml(dicValues['Body'] ) cuonmail.message = dicValues['Body'] print '8' cuonmail.smtp_server = self.EMAILSERVER print '9' cuonmail.smtp_user = self.EMAILUSER print '10' cuonmail.smtp_password = self.EMAILPASSWORD print '11' cuonmail.smtp_crypt = dicEmail['Crypt'] print '12' s = None try: s = cuonmail.send() except Exception, params: print Exception print ' -----------------' print params s = params try: print 'return Value form Email2 ', s print 'Status = ', cuonmail.statusdict print 's = ', s if not s: s = 'Email ' try: s += 'send : ' + dicValues['To'] + ', ' + `dicValues['Subject']` except: s += ' wrong To or subject' else: s = `s` ok = s if dicValues['sm'].has_key('addressid'): ok += ';p=' else: ok += ';a=' ok += `dicValues['sm']['id']` f = open('/var/log/cuonmail.log','a') f.write(time.ctime(time.time() )) f.write(' ') f.write(ok) f.write('\n') f.close() except: pass
def sendEmail(self, dicValues, liAttachments,dicUser ): cuonmail = Email(smtp_server = "localhost") print ' send mail' if liAttachments: cuonmail.attachments = liAttachments else: cuonmail.attachments = [] ok = '' try: dicValues = self.replaceValues(dicValues) if dicUser.has_key('Email'): dicEmail = dicUser['Email'] ## self.Email['From']='MyAddress@mail_anywhere.com' ## self.Email['Host']='mail_anywhere.com' ## self.Email['Port']='25' ## self.Email['LoginUser']='******' ## self.Email['Password']='******' ## self.Email['Signatur']='NONE' print '1' if dicEmail['LoginUser'] != 'login': self.EMAILUSER = dicEmail['LoginUser'] print '2' if dicEmail['Password'] != 'secret': self.EMAILPASSWORD = dicEmail['Password'] print '3' if dicEmail['Host'] != 'mail_anywhere.com': self.EMAILSERVER = dicEmail['Host'] if dicValues.has_key('From'): cuonmail.from_address = dicValues['From'] print '4' if dicValues.has_key('To'): print 'send mail to ', dicValues['To'] cuonmail.recipients.add(dicValues['To']) print '6' if dicValues.has_key('Subject'): cuonmail.subject = dicValues['Subject'] print '7' if dicValues.has_key('Body'): #print 'dicValues = ', dicValues.keys() cuonmail.message = dicValues['Body'] print '8' cuonmail.smtp_server = self.EMAILSERVER print '9' cuonmail.smtp_user = self.EMAILUSER print '10' cuonmail.smtp_password = self.EMAILPASSWORD print '11' cuonmail.smtp_crypt = dicEmail['Crypt'] print '12' except Exception, params: print 'Error in Email' print Exception, params