Python Forum
Python Automated Email
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Automated Email
#11
(Jul-13-2020, 09:00 AM)HarleyQuin Wrote: Then pass it to the email program because your code seems fine to be honest.

So I currently have it like this:

[python]
for i in range(sheet.nrows):

if sheet.cell_value(i, 0) == scannedNumberPlateNumber:

print('Found in column A - ignore')

if sheet.cell_value(i, 2) == scannedNumberPlateNumber:

print('Found in column C - send email to ' + sheet.cell_value(i, 3) )

EMAIL_ADDRESS = "[email protected]"
EMAIL_PASSWORD = "XXXX"
some_variable = str(sheet.cell_value(i, 3))

msg = EmailMessage()
msg['Subject'] = 'Email Subject'
msg['From'] = '[email protected]'
msg['To'] = some_variable
msg.set_content('Please move car')

with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
[python]

But it returns the error: NameError: name 'some_variable' not defined

But if I change
[python]
msg['To'] = some_variable
[python]
to my own email address it will successfully send the email. I just can't get it to send the email to (sheet.cell_value(i, 3)) :(
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help send email by Python using smtplib hangme 6 6,206 Jan-25-2020, 03:31 AM
Last Post: shapeg
  sending email with python shahpy 4 14,158 Oct-03-2016, 10:00 PM
Last Post: shahpy

Forum Jump:

User Panel Messages

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