[TriEmbed] programmatic email with a Raspberry Pi or the like
Alan Wiggs
alanwiggs at gmail.com
Tue Nov 10 12:07:09 CST 2015
For the old school dos types I have a batch file. That sends automated
emails thru gmail.
Let me neutralize my passwords and I can post it.
R,
Alan
On Nov 10, 2015 1:02 PM, "Dave Buster via TriEmbed" <triembed at triembed.org>
wrote:
> GMAIL is finicky, and everything has to be encrypted now. I've got it
> working on a home security camera (not Raspberry Pi) with the following
> settings.
>
> smtp server: smtp.gmail.com
> SMTP port: 465
> use TLS encryption
>
> ----
> I think it also supports STARTTLS on port 25/587, but I could not get that
> to work.
>
> source information is here:
>
> https://support.google.com/a/answer/176600?hl=en
>
>
>
>
> On Tue, Nov 10, 2015 at 12:51 PM, Adam Haile via TriEmbed <
> triembed at triembed.org> wrote:
>
>> I knew I had it working with gmail...
>> Try this out:
>> _username = "user"
>> _password = "password"
>> _fromname = "Your Name"
>>
>>
>>
>> def send_msg(_to_addr, _subject, _body):
>> server = smtplib.SMTP('smtp.gmail.com:587')
>> server.starttls()
>> server.login(_username, _password)
>>
>> print "To: %s" % _to_addr
>> print "Subject: %s" %_subject
>>
>> msg = MIMEText(_body)
>> msg['Subject'] = _subject
>> msg['From'] = email.utils.formataddr((_fromname, _username))
>> msg['To'] = _to_addr
>>
>> server.sendmail(_username, [_to_addr], msg.as_string())
>>
>> On Tue, Nov 10, 2015 at 12:40 PM, Pete Soper via TriEmbed <
>> triembed at triembed.org> wrote:
>>
>>> 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?
>>>
>>> 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.
>>>
>>> -Pete
>>>
>>> #!/usr/bin/python
>>> # Hack of code I found at https://gist.github.com/dbieber/5146518
>>> # pete at soper.us, November, 2015
>>>
>>> import getpass, smtplib
>>> from email.MIMEMultipart import MIMEMultipart
>>> from email.MIMEBase import MIMEBase
>>> from email.MIMEText import MIMEText
>>> from email import Encoders
>>> import os
>>>
>>> smtp_server = 'smtp.someserver.com'
>>> smtp_user = 'user at somedomain.com'
>>> smtp_password = 'accountpassword'
>>> smtp_port = 587
>>>
>>> def mail(to, subject, text, attach=None):
>>> msg = MIMEMultipart()
>>> msg['From'] = smtp_user
>>> msg['To'] = to
>>> msg['Subject'] = subject
>>> msg.attach(MIMEText(text))
>>> if attach:
>>> part = MIMEBase('application', 'octet-stream')
>>> part.set_payload(open(attach, 'rb').read())
>>> Encoders.encode_base64(part)
>>> part.add_header('Content-Disposition', 'attachment; filename="%s"'
>>> % os.path.basename(attach))
>>> msg.attach(part)
>>> mailServer = smtplib.SMTP(smtp_server, smtp_port)
>>> mailServer.ehlo()
>>> mailServer.starttls()
>>> mailServer.ehlo()
>>> mailServer.login(smtp_user, smtp_password)
>>> mailServer.sendmail(smtp_user, to, msg.as_string())
>>> mailServer.close()
>>>
>>> mail("somebody at someplace.com", "FYI", "Here is something you really
>>> need to know:-------")
>>>
>>>
>>> _______________________________________________
>>> Triangle, NC Embedded Computing mailing list
>>> TriEmbed at triembed.org
>>> http://mail.triembed.org/mailman/listinfo/triembed_triembed.org
>>> TriEmbed web site: http://TriEmbed.org
>>>
>>
>>
>> _______________________________________________
>> Triangle, NC Embedded Computing mailing list
>> TriEmbed at triembed.org
>> http://mail.triembed.org/mailman/listinfo/triembed_triembed.org
>> TriEmbed web site: http://TriEmbed.org
>>
>>
>
>
> --
> Dave Buster
>
> KK4ELT on 2 meters
>
> Never look at the trombones, it only encourages them.
> *Ri
> <http://t.sidekickopen27.com/e1t/c/5/f18dQhb0S7lC8dDMPbW2n0x6l2B9nMJW7t5XX45vMtjYVQZgwH64R1y4W8r4TLx56dPn8f5RTxgR02?t=http%3A%2F%2Fwww.brainyquote.com%2Fquotes%2Fauthors%2Fr%2Frichard_wagner.html&si=4964982235594752&pi=abbca291-7b77-4f42-b627-fc135240e6eb>chard
> Strauss*
>
>
>
> _______________________________________________
> Triangle, NC Embedded Computing mailing list
> TriEmbed at triembed.org
> http://mail.triembed.org/mailman/listinfo/triembed_triembed.org
> TriEmbed web site: http://TriEmbed.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.triembed.org/pipermail/triembed_triembed.org/attachments/20151110/55639e51/attachment.htm>
More information about the TriEmbed
mailing list