Exemplo n.º 1
0
class MailSender(object):
    implements(smtp.IMessage)

    def __init__(self,toAddr):
    	self.toAddr = toAddr # Who are we sending the encrypted email to?
        self.lines = []
	self.gpg = GPG()
    
    def lineReceived(self, line):
        self.lines.append(line)

    def eomReceived(self):
	# Message we recieved
    	msgRcv = email.message_from_string('\n'.join(self.lines)) 
	# This will be the message that we send
	payload = msgRcv.get_payload()
    	self.msg = MIMEText(self.gpg.encrypt(payload,TO_EMAIL,always_trust=True).data) 
    	self.msg['Subject'] = msgRcv['Subject']
	self.msg['From'] = email.Utils.parseaddr(msgRcv['From'])[1]
	self.msg['Reply-To'] = self.msg['From']
        self.msg['To'] = TO_EMAIL
        print self.msg 	
	self.sendMessage()
        return defer.succeed(None)

    def connectionLost(self):
        print "Connection lost unexpectedly!"
        del(self.lines) # unexpected loss of connection; don't save
	
    def sendMessage(self):
        s = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
	s.ehlo()
	s.starttls()
	s.ehlo()
	s.login(SMTP_USERNAME,SMTP_PASSWORD)
        s.sendmail(self.msg['From'], self.msg['To'], str(self.msg))
	s.close()
Exemplo n.º 2
0
    def __init__(self,toAddr):
    	self.toAddr = toAddr # Who are we sending the encrypted email to?
        self.lines = []
	self.gpg = GPG()