How to send email from python
<p>My Code</p>

<pre><code>import smtplib
import socket
import sys
from email.mime.text import MIMEText
fp = open("CR_new.txt", 'r')
msg = MIMEText(fp.read())
fp.close()

you = "rajiv@domain.com"
me = "rajiv@domain.com"
msg['Subject'] = 'The contents of %s' % "CR_new.txt"
msg['From'] = you
msg['To'] = me
s = smtplib.SMTP('127.0.0.1')
s.sendmail(you,me, msg.as_string())
s.quit()
</code></pre>

<blockquote>
  <p>ConnectionRefusedError: [WinError 10061] No connection could be made
  because the target machine actively refused it</p>
</blockquote>

<p><strong>Note:</strong></p>

<ul>
<li>Not having a SMTP server </li>
</ul>

<p>This code will help you to send the email.
You just need to provide your email-id password.</p>

<p>The most important note is: don't give file name as email.py.</p>

<pre><code>import socket
import sys
import smtplib
EMAIL_TO = ["rajiv@domain.com"]
EMAIL_FROM = "rajiv@domain.com"
EMAIL_SUBJECT = "Test Mail... "
msg= {}
EMAIL_SPACE = ", "



msg['Subject'] = EMAIL_SUBJECT 
msg['To'] = EMAIL_SPACE.join(EMAIL_TO)
msg['From'] = EMAIL_FROM
try:
    mail = smtplib.SMTP_SSL('smtp.bizmail.yahoo.com',465)
    # 
    # if you are using gmail then  use
    #   smtplib.SMTP_SSL('smtp.gmail.com',587)
    #
    mail.login("rajiv@domain.com", 'password')   # you account email password..
    mail.sendmail("rajiv@domain.com", EMAIL_TO, msg.as_string())   
    mail.quit()
except Exception,e:
    print e
finally:
    print "Error of email sending mail"
</code></pre>

python email