Failing to send email with the Python example

后端 未结 10 949
南旧
南旧 2020-12-04 15:56

I\'ve been trying (and failing) to figure out how to send email via Python.

Trying the example from here: http://docs.python.org/library/smtplib.html#smtplib.SMTP

10条回答
  •  心在旅途
    2020-12-04 16:42

    Then I had trie to sent email through smtp.gmail.com, I had the same errors. In my case the Internet provider had close the port 25 (and also 587 and other) for outgoing connections from the IP addresses (from my network) to the external network, leaving open the 25th port only for its mail server. So, at first try:

    telnet smtp.gmail.com 587

    (587 it your port)

    By doing this you can understand, if your port is closed by the Internet provider. You can contact your provider and ask them to open a port for you. My solution was connecting to other network (with open port) Here is the code I used:

    gmailaddress = "youremailadress@gmail.com"
    gmailpassword = "7777777"
    mailto = "youremailadress@gmail.com"
    msg = input("What is your message? \n ")
    mailServer = smtplib.SMTP('smtp.gmail.com' , 587)
    mailServer.starttls()
    mailServer.login(gmailaddress , gmailpassword)
    mailServer.sendmail(gmailaddress, mailto , msg)
    print(" \n Sent!")
    mailServer.quit()```
    

提交回复
热议问题