Exemple #1
0
    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()
Exemple #2
0
    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()
Exemple #3
0
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
    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()