Crash when sending email in Python 2.7.10
<p>I'm trying to send an email within python, but the program is crashing when I run it either as a function in a larger program or on it's own in the interpreter.</p>

<pre><code>import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

fromaddr = "exampleg@gmail.com"
toaddr = "recipient@address.com"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Hi there"

body = "example"
msg.attach(MIMEText(body, 'plain'))

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "Password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
</code></pre>

<p>In the interpreter, it seems to fail with <code>server = smtplib.SMTP('smtp.gmail.com', 587)</code></p>

<p>Any ideas?</p>

<p>That's because you are getting error when trying to connect Google SMTP server.
Note that if you are using Google SMTP you should use:</p>

<p>Username: Your gmail address<br>
Password: Your gmail password</p>

<p>And you should be already logged in. If you still get an error, you should check what is the problem in this list: <a href="http://stackoverflow.com/a/25238515/1600523">http://stackoverflow.com/a/25238515/1600523</a></p>

<p>Note: You can also use your own SMTP server.</p>

python email smtp