← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #241177]: How to send an email over SSL using the smtplib module

 

Question #241177 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/241177

Joshua-tollefson posted a new comment:
Ador, I ran into the same problem. I found that Jython 2.7b3 has issues
in smtplib the same as above so I switched to commons email as was
proposed here. I would suggest using an editor such as LiClipse with the
PyDev plugin(if you're not already) as it helps with the imports and
code formatting.

You need to  make sure that your classpath is setup to point to commons-email-<ver>.jar and javax.mail.jar. 
javax.mail can be found here http://www.oracle.com/technetwork/java/javamail/index.html. As an aside, I'm using the Python keyring module to store passwords, it's not all that secure... but... it's better than having passwords in plaintext laying around.

Code:
import keyring
from org.apache.commons.mail import SimpleEmail, DefaultAuthenticator
from EmailConstants import FROMADDR, TOADDR, SUBJECT, USERNAME, KEYRING_SOURCE,\
    SMTP_SERVER, SMTP_PORT

PASSWORD = keyring.get_password(KEYRING_SOURCE, FROMADDR)


def sendNotification(
        message,
        fromaddr=FROMADDR,
        toaddr=TOADDR,
        subject=SUBJECT):

    email = SimpleEmail()
    email.setHostName(SMTP_SERVER)
    email.setSmtpPort(SMTP_PORT)
    email.setAuthenticator(DefaultAuthenticator(USERNAME, PASSWORD))
    email.setStartTLSEnabled(True)
    email.setFrom(fromaddr)
    email.setSubject(subject)
    email.setMsg(message)
    email.addTo(toaddr)
    email.send()

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.