← Back to team overview

sikuli-driver team mailing list archive

[Bug 1380637] Re: [request] want to send an email over SSL using some smtplib module

 

--- from the related question comment #11 (https://launchpad.net
/~joshua-tollefson)

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 bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1380637

Title:
  [request] want to send an email over SSL using some smtplib module

Status in Sikuli:
  In Progress

Bug description:
  Basically i want to send a email when I find a particular image ,

  so my algorithm goes something like

  if exists(IMG):
   send email 
   exit(0); 

  So for past few hours I was working on email script and I'm not find
  any luck.

  import smtplib
  to = 'srkt@xxxxxxxxx'
  gmail_user = 'srkt2@xxxxxxxxx'
  gmail_pwd = 'Games@10'
  smtpserver = smtplib.SMTP("mail.gmail.com")      #the smtp used is just a example not the 1 I'm using in real script.
  smtpserver.ehlo()
  smtpserver.starttls()                   # HERE Is the place where is shows the error 
  smtpserver.ehlo
  smtpserver.login(gmail_user, gmail_pwd)
  header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:testing \n'
  print header
  msg = header + '\n this is a smtp successful message \n\n'
  smtpserver.sendmail(gmail_user, to, msg)
  print 'done!'
  smtpserver.close()

  
  I get a error like 
  [error] socket.sslerror ( (-1, 'SSL handshake exception: Differences between the SSL socket behaviour of cpython vs. jython are explained on the wiki: http://wiki.python.org/jython/NewSocketModule#SSL_Support') )

  I went through document and I had no luck, can someone correct me

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1380637/+subscriptions


References