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>I would suggest using a package like <a href="https://github.com/kootenpv/yagmail" rel="nofollow">yagmail</a>, rather than trying to figure out how to get smtplib to work. Disclaimer: I'm the maintainer of yagmail.</p>

<p>Code would look like:</p>

<pre><code>import yagmail
yag = yagmail.SMTP(host="127.0.0.1")
yag.send(to"rajiv@domain.com", subject="subject", contents="content")
</code></pre>

python email