<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Here's what I get when I try that with my Gmail account (Ubuntu
    13.10, Python 2.7.5+):<br>
    <br>
    psoper@len:~/p$ ./foo.py<br>
    Traceback (most recent call last):<br>
      File "./foo.py", line 29, in <module><br>
        send_msg('<a class="moz-txt-link-abbreviated" href="mailto:fredfarkel@bitser.net">fredfarkel@bitser.net</a>', 'FYI', 'Here is a message')<br>
      File "./foo.py", line 15, in send_msg<br>
        server = smtplib.SMTP('smtp.gmail.com:587')<br>
      File "/usr/lib/python2.7/smtplib.py", line 251, in __init__<br>
        (code, msg) = self.connect(host, port)<br>
      File "/usr/lib/python2.7/smtplib.py", line 311, in connect<br>
        self.sock = self._get_socket(host, port, self.timeout)<br>
      File "/usr/lib/python2.7/smtplib.py", line 286, in _get_socket<br>
        return socket.create_connection((host, port), timeout)<br>
      File "/usr/lib/python2.7/socket.py", line 553, in
    create_connection<br>
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):<br>
    socket.gaierror: [Errno -2] Name or service not known<br>
    <br>
    When I tried the original code off the 'Net Google sent me a msg as
    if paratroopers in blue helmets were sliding down ropes onto the
    roof of my house. <br>
    <br>
    <div class="moz-cite-prefix">On 11/10/2015 12:51 PM, Adam Haile
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAG8g-TZVa4kE=mwvshQsfvyGG8Syv3ooduM-e=0kVmm4CuZhyA@mail.gmail.com"
      type="cite">
      <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 moz-do-not-send="true"
              href="http://smtp.gmail.com:587">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="gmail_extra"><br>
        <div class="gmail_quote">On Tue, Nov 10, 2015 at 12:40 PM, Pete
          Soper via TriEmbed <span dir="ltr"><<a
              moz-do-not-send="true" 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 moz-do-not-send="true"
              href="https://gist.github.com/dbieber/5146518"
              rel="noreferrer" target="_blank">https://gist.github.com/dbieber/5146518</a><br>
            # <a moz-do-not-send="true" 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 moz-do-not-send="true"
              href="http://smtp.someserver.com" rel="noreferrer"
              target="_blank">smtp.someserver.com</a>'<br>
            smtp_user = '<a moz-do-not-send="true"
              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 moz-do-not-send="true"
              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 moz-do-not-send="true"
              href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
            <a moz-do-not-send="true"
              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 moz-do-not-send="true"
              href="http://TriEmbed.org" rel="noreferrer"
              target="_blank">http://TriEmbed.org</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>