Exemplo n.º 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()
    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()