Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35410
| Date | 2012-12-23 15:34 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Python, email temperature |
| References | <543ec063-14c1-4ca6-a911-ae6f58c22a8c@googlegroups.com> <bf6655e9-4b90-4be7-a5c6-758777ea6c0e@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1224.1356294905.29569.python-list@python.org> (permalink) |
On 12/23/2012 08:46 AM, KarlE wrote: > On Saturday, December 22, 2012 9:36:41 PM UTC+1, KarlE wrote: >> Hi! >> >> >> >> Im totally new to Python, and im using it on my Raspberry pi. I found a program that sends an email, and one that checks the temperature of my CPU, but i cant seem to combine the to into the funktion that i want, sending me the CPU temp via Email. >> >> >> >> The two programs work very well on their own, but this doesnt work. >> >> >> >> this works: server.sendmail(fromaddr, toaddrs, msg) >> >> but this doesnt: server.sendmail(fromaddr, toaddrs, cpu_temperature) >> >> >> >> despite the command "print cputemp" working in the same program. >> >> >> >> When i run the program i get the error: >> >> >> >> Traceback (most recent call last): >> >> File "sendcpu.py", line 36, in <module> >> >> msg = cpu_temperature >> >> NameError: name 'cpu_temperature' is not defined >> >> >> >> Does anyone know why the program claims that cpu_temperature isnt defined, when it is? >> >> >> >> Thanx! >> >> >> >> //Alexander > Ok, im back with a little more understanding of python! I got the program working, every time my Raspberry Pi reboots i get an Email containing information about the boot and the CPU temperature. > > The issue now is that there seems to be a limitation to how long the message string can be, about 32 letters. The code below works well, but when i add more letters to the string "ord" and pass about 32 in size the email comes through emptpy... I don't know the email protocols that well, but I can tell you a Python string isn't limited in size to any small value. Maybe a few hundred million characters, but i haven't tried beyond that. i suspect the limit you're hitting is the limit of subject size in an email protocol. In particular, the 3rd argument to sendmail() needs to have newlines in a particular format before you get to the body of the email. The body can be quite large, but you probably are required to have the appropriate headers first. When you send a short message, does it all come out as a subject line? It would be good to look up the docs on smtplib, but if I had to just do some blind testing, I'd try first adding a newline pair, changing the line to something like: ord = "Subject: Pi Boot, CPU: \r\n" + str(cpu_temperature) + WhateverOtherStuffYouWantedToTry -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python, email temperature Alexander Ranstam <ranstam@gmail.com> - 2012-12-22 12:36 -0800
Re: Python, email temperature KarlE <ranstam@gmail.com> - 2012-12-22 12:38 -0800
Re: Python, email temperature Joel Goldstick <joel.goldstick@gmail.com> - 2012-12-22 15:44 -0500
Re: Python, email temperature KarlE <ranstam@gmail.com> - 2012-12-22 12:54 -0800
Re: Python, email temperature Gary Herron <gary.herron@islandtraining.com> - 2012-12-22 13:12 -0800
Re: Python, email temperature KarlE <ranstam@gmail.com> - 2012-12-22 12:54 -0800
Re: Python, email temperature No One <atsidi@gmail.com> - 2012-12-22 21:53 +0000
Re: Python, email temperature Gary Herron <gary.herron@islandtraining.com> - 2012-12-22 12:45 -0800
Re: Python, email temperature KarlE <ranstam@gmail.com> - 2012-12-22 14:50 -0800
Re: Python, email temperature Chris Angelico <rosuav@gmail.com> - 2012-12-23 10:15 +1100
Re: Python, email temperature KarlE <ranstam@gmail.com> - 2012-12-23 05:46 -0800
Re: Python, email temperature Mitya Sirenef <msirenef@lightbird.net> - 2012-12-23 12:23 -0500
Re: Python, email temperature Dave Angel <d@davea.name> - 2012-12-23 15:34 -0500
Re: Python, email temperature Terry Reedy <tjreedy@udel.edu> - 2012-12-23 19:31 -0500
csiph-web