Python Forum
Please help with code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help with code
#1
My python code is meant to send me an email with the string send from Arduino through the serial. Everything is working fine (Emails are sent when string is present in the serial port) except that, emails are sent continuously, instead of once. I receiving about 100s of emails with the same information. I need only one. I don't know how to fix it. Please help.

import time
import serial
import smtplib
 
TO = '[email protected]'
GMAIL_USER = '[email protected]'
GMAIL_PASS = 'password'
SUBJECT = 'ALERT!!!'  
ser = serial.Serial('COM4', 9600)
message = ser.readline()
TEXT = message
def send_email():
    print("Sending Email")
    server = smtplib.SMTP("smtp.gmail.com",587)
    server.ehlo()
    server.starttls()
    server.ehlo
    server.login(GMAIL_USER, GMAIL_PASS)
    header = 'To:' + TO + '\n' + 'From: ' + GMAIL_USER
    header = header + '\n' + 'Subject:' + SUBJECT + '\n'
    print header
    msg = header + '\n' + TEXT + ' \n\n'
    server.sendmail(GMAIL_USER, TO, msg)
    server.close()
    
while True:
    print(message)
    send_email()
    time.sleep(0.5)
Reply


Messages In This Thread
Please help with code - by fikszon - Feb-02-2017, 09:58 AM
RE: Please help with code - by Ofnuts - Feb-02-2017, 10:00 AM
RE: Please help with code - by fikszon - Feb-02-2017, 10:02 AM
RE: Please help with code - by j.crater - Feb-02-2017, 11:34 AM
RE: Please help with code - by fikszon - Feb-02-2017, 12:12 PM
RE: Please help with code - by Ofnuts - Feb-02-2017, 02:15 PM
RE: Please help with code - by fikszon - Feb-02-2017, 02:22 PM
RE: Please help with code - by nilamo - Feb-03-2017, 04:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020