def __call__(self): smtpHost = "mailhost" properties = System.getProperties() properties["mail.smtp.host"] = smtpHost session = Session.getInstance(System.getProperties()) session.debug = 1 message = MimeMessage(session) message.setFrom(InternetAddress("*****@*****.**")) message.addRecipient(Message.RecipientType.TO, InternetAddress("*****@*****.**")) message.subject = "Test email %s from thread %s" % ( grinder.runNumber, grinder.threadNumber) # One could vary this by pointing to various files for content message.setText("SMTPTransport Email works from The Grinder!") # Wrap transport object in a Grinder Jython Test Wrapper transport = emailSendTest1.wrap(session.getTransport("smtp")) transport = emailSendTest1.wrap(transport) transport.connect(smtpHost, "username", "password") transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)) transport.close()
def __call__(self): smtpHost = "mailhost" properties = System.getProperties() properties["mail.smtp.host"] = smtpHost session = Session.getInstance(System.getProperties()) session.debug = 1 message = MimeMessage(session) message.setFrom(InternetAddress("*****@*****.**")) message.addRecipient(Message.RecipientType.TO, InternetAddress("*****@*****.**")) message.subject = "Test email %s from thread %s" % (grinder.runNumber, grinder.threadID) # One could vary this by pointing to various files for content message.setText("SMTPTransport Email works from The Grinder!") # Wrap transport object in a Grinder Jython Test Wrapper transport = emailSendTest1.wrap(session.getTransport("smtp")) transport = emailSendTest1.wrap(transport) transport.connect(smtpHost, "username", "password") transport.send(message) transport.close()
def sendEmail(self, useremail, subject, messageText): # server connection smtpconfig = self.getSmtpConfig() properties = Properties() properties.setProperty("mail.smtp.host", smtpconfig['host']) properties.setProperty("mail.smtp.port", str(smtpconfig['port'])) properties.setProperty("mail.smtp.starttls.enable", "true") session = Session.getDefaultInstance(properties) message = MimeMessage(session) message.setFrom(InternetAddress(smtpconfig['from'])) message.addRecipient(Message.RecipientType.TO, InternetAddress(useremail)) message.setSubject(subject) #message.setText(messageText) message.setContent(messageText, "text/html") transport = session.getTransport("smtp") transport.connect(properties.get("mail.smtp.host"), int(properties.get("mail.smtp.port")), smtpconfig['user'], smtpconfig['pwd_decrypted']) transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)) transport.close()
def __index(self, emailInfo): from org.apache.lucene.index import IndexWriterConfig from org.apache.lucene.util import Version from org.apache.lucene.analysis.standard import StandardAnalyzer analyser = StandardAnalyzer(Version.LUCENE_33) conf = IndexWriterConfig(Version.LUCENE_33, analyser) from org.apache.lucene.store import FSDirectory from java.io import File storage = File.createTempFile(u'Tubelight-', '.index') storage.delete() storage.mkdir() storage.deleteOnExit() self.storage = storage.getAbsolutePath() from java.io import File self.session.setAttribute('directory', storage.getAbsolutePath()+File.separator+'mail.idx') directory = FSDirectory.open(storage) from org.apache.lucene.index import IndexWriter iw = IndexWriter(directory, conf) from us.d8u.tubelight import Configuration addr = emailInfo[Configuration.EmailAddressKey] (username, server) = addr.split('@') from java.lang import System System.setProperty("mail.imap.partialfetch", "false") urlPrefix = (("imap://%s@%s:%d/Inbox") % (username, server, int(emailInfo[Configuration.EmailPortKey]))) from javax.mail import Session session = Session.getDefaultInstance(System.getProperties(), None).getStore(h.get(Configuration.EmailProtocolKey)) session.connect(server, username, emailInfo[Configuration.EmailPasswordKey]) folder = session.getDefaultFolder() for m in folder.getMessages(): from org.apache.lucene.document import Document d = Document() subject = Field("subject", m.getSubject(), Field.Store.YES, Field.Index.ANALYZED) toSrc = u'' toSrc = [((u'%s, %s') % (toSrc, str(r))) for r in m.getAllRecipients()] to = Field("to", toSrc.substring(toSrc.indexOf(u',')), Field.Store.YES, Field.Index.ANALYZED) d.add(to) d.add(subject) iw.addDocument(d) iw.commit() self.searcher = IndexSearcher(directory)
def sendJournalMessage(guid, sender, to, cc, bcc, domain, cloudDomain, mtaHost): randomId = String.valueOf(Random(System.currentTimeMillis()).nextInt(1000000)) print 'Sending message ' + randomId + ' to journaling address ' + guid + '@' + cloudDomain try: props = System.getProperties() props.put("mail.smtp.host", mtaHost) props.put("mail.smtp.starttls.enable", "false") session = Session.getDefaultInstance(props) session.setDebug(True) # create message envelope envelope = MimeMessage(session) envelope.setSentDate(Date(System.currentTimeMillis() - 2000)) envelope.setSubject("Test Journal Envelope " + randomId) envelope.setFrom(InternetAddress(sender + "@" + domain)) # alternating character sets if (int(randomId) % 2) == 0: envelope.setText(String('bullet \x95, euro sign \x80, latin F \x83, tilde \x98', 'windows-1252'), 'windows-1252') elif (int(randomId) % 3) == 0: envelope.setText('plain ascii text...', 'us-ascii') else: envelope.setText('bullet \xe2\x80\xa2, euro sign \xe2\x82\xac, latin F \xc6\x92, tilde \x7e', 'utf-8') if to is not None: for recipient in to: envelope.addRecipient(Message.RecipientType.TO, InternetAddress(recipient + "@" + domain)) if cc is not None: for recipient in cc: envelope.addRecipient(Message.RecipientType.CC, InternetAddress(recipient + "@" + domain)) if bcc is not None: for recipient in bcc: envelope.addRecipient(Message.RecipientType.BCC, InternetAddress(recipient + "@" + domain)) # generate message-id envelope.saveChanges() # create journal envelope journalEnvelope = MimeMessage(session) journalEnvelope.setHeader("X-MS-Journal-Report", "") journalEnvelope.setSentDate(Date()) journalEnvelope.setSubject(envelope.getSubject()) journalEnvelope.setFrom(InternetAddress("pseudoexchange@" + domain)) journalEnvelope.addRecipient(Message.RecipientType.TO, InternetAddress(guid + "@" + cloudDomain)) # Sender: [email protected] # Subject: RE: Test - load CAtSInk # Message-Id: <[email protected]= # 1dev.com> # To: [email protected] # Cc: [email protected] # Bcc: [email protected] journalReport = StringBuilder() journalReport.append("Sender: ").append(sender + "@" + domain).append("\r\n") journalReport.append("Subject: ").append(envelope.getSubject()).append("\r\n") journalReport.append("Message-Id: ").append(envelope.getMessageID()).append("\r\n") if to is not None: for recipient in to: journalReport.append("To: ").append(recipient + "@" + domain).append("\r\n") if cc is not None: for recipient in cc: journalReport.append("Cc: ").append(recipient + "@" + domain).append("\r\n") if bcc is not None: for recipient in bcc: journalReport.append("Bcc: ").append(recipient + "@" + domain).append("\r\n") multipart = MimeMultipart() reportPart = MimeBodyPart() reportPart.setText(journalReport.toString(), "us-ascii") multipart.addBodyPart(reportPart) messagePart = MimeBodyPart() messagePart.setContent(envelope, "message/rfc822") multipart.addBodyPart(messagePart) journalEnvelope.setContent(multipart) try: Transport.send(journalEnvelope) except: print "Send failed, will try to propagate MTA configuration again..." propagateMtaConfig() Transport.send(journalEnvelope) return True except: print 'Failed to send journaled message', randomId raise