-2

I'm trying to send email with python but I'm getting SSL error and I don't know why.

   File "./test.py", line 735, in <module>
     mail()   File "./test.py", line 721, in mail
     server.starttls()   File "/usr/local/lib/python2.7/smtplib.py", line 641, in starttls
     raise RuntimeError("No SSL support included in this Python") RuntimeError: No SSL support included in this Python

How do I add SSL support?

its just a small function to test if i can send email with python

def mail():
    import smtplib
    global log_location
    #inFile_list = open(log_location, 'r')
    #msg = inFile_list.readlines()
    #inFile_list.close()

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    #Next, log in to the server
    server.login("my username", "my password")

    #Send the mail
    msg = "\nHello!" # The /n separates the message from the headers
    server.sendmail("mymail@gmail.com", "mymail@gmail.com", msg)
    server.quit()
idan357
  • 342
  • 6
  • 17

2 Answers2

0

Tried to install _ssl.so manual but it didn't work.

instead I've upgraded from 2.7.6 to 2.7.7 and now i can import SSL.

idan357
  • 342
  • 6
  • 17
0
import smtplib
import config


def send_email(subject,msg):
    try:
        server = smtplib.SMTP('smtp.gmail.com:587')
        server.ehlo()
        server.starttls()
        server.login(config.EMAIL_ADDRESS, config.PASSWORD)
        message = 'subject: {}\n\n{}'.format(subject,msg)
        server.sendmail(config.EMAIL_ADDRESS,config.EMAIL_ADDRESS, message)
        server.quit()
        print('all good')
    except:
        print('email failed to send')
subject = "TEST SUBJECT"
msg = "hello"
send_email(subject,msg)

This works for me but you must create a new file called config.py then put in

EMAIL_ADDRESS = "email"
PASSWORD = "pwd"

The last step is go to this link >>> https://myaccount.google.com/lesssecureapps<<< and turn it on. Now you can run the script