<div dir="ltr">Note: If you use gmail two-factor authentication (which everyone should!), the password needs to be a google "app password", not your normal password.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 10, 2015 at 12:51 PM, Adam Haile via TriEmbed <span dir="ltr"><<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I knew I had it working with gmail...<div>Try this out:</div><div><div>_username = "user"</div><div>_password = "password"</div><div>_fromname = "Your Name"</div><div><br></div><div><br></div><div><br></div><div>def send_msg(_to_addr, _subject, _body):</div><div>    server = smtplib.SMTP('<a href="http://smtp.gmail.com:587" target="_blank">smtp.gmail.com:587</a>')</div><div>    server.starttls()</div><div>    server.login(_username, _password)</div><div><br></div><div>    print "To: %s" % _to_addr</div><div>    print "Subject: %s" %_subject</div><div><br></div><div>    msg = MIMEText(_body)</div><div>    msg['Subject'] = _subject</div><div>    msg['From'] = email.utils.formataddr((_fromname, _username))</div><div>    msg['To'] = _to_addr</div><div><br></div><div>    server.sendmail(_username, [_to_addr], msg.as_string())</div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 10, 2015 at 12:40 PM, Pete Soper via TriEmbed <span dir="ltr"><<a href="mailto:triembed@triembed.org" target="_blank">triembed@triembed.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Following up on last night's conversation I spent another couple hours horsing around with getting a Python script to send email and I got something to work with my personal domain server. Implicit at the site below that the original code came from this "used to work" with Gmail but Google tightened things up a few years ago. I haven't found more recent SSL-based incantations on the 'Net to try this with an account where leakage/loss of the login details would only require destroying the account. But maybe one of you know about such things to demonstrate how to do this with Gmail?<br>
<br>
Anyway, here's a script that works for me so the next time my water heater is failing I can hack a leak detector from Lowes into a locked down single board system to tell me it would be a good idea to come home and turn the well pump off.<br>
<br>
-Pete<br>
<br>
#!/usr/bin/python<br>
# Hack of code I found at <a href="https://gist.github.com/dbieber/5146518" rel="noreferrer" target="_blank">https://gist.github.com/dbieber/5146518</a><br>
# <a href="mailto:pete@soper.us" target="_blank">pete@soper.us</a>, November, 2015<br>
<br>
import getpass, smtplib<br>
from email.MIMEMultipart import MIMEMultipart<br>
from email.MIMEBase import MIMEBase<br>
from email.MIMEText import MIMEText<br>
from email import Encoders<br>
import os<br>
<br>
smtp_server = '<a href="http://smtp.someserver.com" rel="noreferrer" target="_blank">smtp.someserver.com</a>'<br>
smtp_user = '<a href="mailto:user@somedomain.com" target="_blank">user@somedomain.com</a>'<br>
smtp_password = 'accountpassword'<br>
smtp_port = 587<br>
<br>
def mail(to, subject, text, attach=None):<br>
   msg = MIMEMultipart()<br>
   msg['From'] = smtp_user<br>
   msg['To'] = to<br>
   msg['Subject'] = subject<br>
   msg.attach(MIMEText(text))<br>
   if attach:<br>
      part = MIMEBase('application', 'octet-stream')<br>
      part.set_payload(open(attach, 'rb').read())<br>
      Encoders.encode_base64(part)<br>
      part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach))<br>
      msg.attach(part)<br>
   mailServer = smtplib.SMTP(smtp_server, smtp_port)<br>
   mailServer.ehlo()<br>
   mailServer.starttls()<br>
   mailServer.ehlo()<br>
   mailServer.login(smtp_user, smtp_password)<br>
   mailServer.sendmail(smtp_user, to, msg.as_string())<br>
   mailServer.close()<br>
<br>
mail("<a href="mailto:somebody@someplace.com" target="_blank">somebody@someplace.com</a>", "FYI", "Here is something you really need to know:-------")<br>
<br>
<br>
_______________________________________________<br>
Triangle, NC Embedded Computing mailing list<br>
<a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
<a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Triangle, NC Embedded Computing mailing list<br>
<a href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><br>
<a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" rel="noreferrer" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
TriEmbed web site: <a href="http://TriEmbed.org" rel="noreferrer" target="_blank">http://TriEmbed.org</a><br>
<br></blockquote></div><br></div>