Not sending emails at all

Posted on
Thu Jul 07, 2022 9:36 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Not sending emails at all

Hello,

what's wrong with my script? It's not sending an email at all:

Code: Select all
emailTo = "merckens@gmx.de"
emailBody = u"Device Name\tDevice ID\tLast Reset Timestamp\tCurrent Power (Watts)\tTotal Energy (kWh)\n"
for dev in indigo.devices.iter("props.SupportsEnergyMeter"):
  emailBody += u"{}\t{}\t{}\t{}\t{}\n".format(dev.name, dev.id, dev.energyAccumBaseTime, dev.energyCurLevel, dev.energyAccumTotal)

import datetime as dt
from datetime import date
today = dt.datetime.now()
yesterday = today - dt.timedelta(days=1)
Str_yesterday=str(yesterday.strftime("%Y%m%d"))
import os.path
save_path = '/Users/smerckens/Desktop/Z-Wave Exporte/'
filename = Str_yesterday+".Export des Tagesverbrauchs.txt"
completeName = save_path+filename   
file1 = open(completeName , "w", encoding='utf-8')
file1.write(emailBody)
file1.close()

# indigo.server.sendEmailTo(emailTo, subject="Stromverbrauch des Vortages ("+Str_yesterday+")", body=emailBody)
subject="Stromverbrauch des Vortages ("+Str_yesterday+")"
props = {   
    'emailTo': emailTo,
    'emailCC': '',
    'emailBCC': '',
    'emailSubject': subject,
    'emailAttachments': filename,
    'emailFormat': 'plain',
    'emailMessage': emailBody
}

plugin = indigo.server.getPlugin("com.indigo.email")
if plugin.isEnabled():
   plugin.executeAction("sendEmail", deviceId=1948829696, props=props)


Calling the script manually log only shows:
Code: Select all
Schedule                        Sende Stromverbrauch täglich + Datei sichern


Thanks in advance for your help!

Bildhauer.
Attachments
Grenzweg.jpg
Grenzweg.jpg (30.57 KiB) Viewed 1618 times

Posted on
Thu Jul 07, 2022 11:10 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Not sending emails at all

When getting the plugin instance try using com.indigodomo.email instead of com.indigo.email.

Image

Posted on
Thu Jul 07, 2022 11:22 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: Not sending emails at all

Thanks,

then I' m getting:

Code: Select all
 Email+ Debug                    sendEmailAction queueing message 'Stromverbrauch des Vortages (20220706)'
   Email+ Debug                    Email+ SMTP Server: SMTP poll, 1 items in queue
   Script Error                    embedded script error:
   Script Error                    unable to convert python exception
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 33, at top level
RuntimeError: unable to convert python exception

Posted on
Thu Jul 07, 2022 11:45 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Not sending emails at all

Simplify your example to not create an email props with an attachment to see if that works.

Also, did anything send? From the log it looks like a message was queued up.

Image

Posted on
Thu Jul 07, 2022 1:05 pm
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: Not sending emails at all

No email was ent.

I'll try without attachment and will come back to you!

Bildhauer

Posted on
Thu Jul 07, 2022 1:08 pm
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: Not sending emails at all

Without attachment email was sent. So the referent to the file is wrong?

Bildhauer

Posted on
Thu Jul 07, 2022 1:15 pm
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: Not sending emails at all

I changed it to:

Code: Select all
emailTo = "merckens@gmx.de"
emailBody = u"Device Name\tDevice ID\tLast Reset Timestamp\tCurrent Power (Watts)\tTotal Energy (kWh)\n"
for dev in indigo.devices.iter("props.SupportsEnergyMeter"):
  emailBody += u"{}\t{}\t{}\t{}\t{}\n".format(dev.name, dev.id, dev.energyAccumBaseTime, dev.energyCurLevel, dev.energyAccumTotal)

import datetime as dt
from datetime import date
today = dt.datetime.now()
yesterday = today - dt.timedelta(days=1)
Str_yesterday=str(yesterday.strftime("%Y%m%d"))
import os.path
save_path = '/Users/smerckens/Desktop/Z-Wave Exporte/'
filename = Str_yesterday+'.Export des Tagesverbrauchs.txt'
completeName = save_path+filename   
file1 = open(completeName , "w", encoding='utf-8')
file1.write(emailBody)
file1.close()

# indigo.server.sendEmailTo(emailTo, subject="Stromverbrauch des Vortages ("+Str_yesterday+")", body=emailBody)
subject="Stromverbrauch des Vortages ("+Str_yesterday+")"
props = {   
    'emailTo': emailTo,
    'emailCC': '',
    'emailBCC': '',
    'emailSubject': subject,
    'emailAttachments': completeName,
    'emailFormat': 'plain',
    'emailMessage': emailBody
}

plugin = indigo.server.getPlugin("com.indigodomo.email")
if plugin.isEnabled():
   plugin.executeAction("sendEmail", deviceId=1948829696, props=props)


And it's working!

Thanks for your support!

Bildhauer

Posted on
Sat Jul 16, 2022 9:18 am
roquej offline
User avatar
Posts: 609
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Not sending emails at all

This is probably very simple, but I am missing it. The below worked in python 2, but getting "unable to convert python exception"

Code: Select all
wsStates = indigo.devices[259796767].states #

def sendAlertEmail(alert, message, expires):
   theSubject = "Miami Weather Alert: %s" % alert
   theBody = "%s\n\nThis weather alert is valid until %s" % (message, expires)

   bePlugin = indigo.server.getPlugin("com.indigodomo.email")
   if bePlugin.isEnabled():
      bePlugin.executeAction("sendEmail", deviceId=762832699,
      props={'emailTo':'email@email.com', 'emailSubject': theSubject, 'emailMessage': theBody})
   return

if str(wsStates[u'alertTitle1']) != ' ':
   sendAlertEmail(wsStates[u'alertTitle1'], wsStates[u'alertDescription1'], wsStates[u'alertExpires1'])

if wsStates[u'alertTitle2'] != ' ':
   sendAlertEmail(wsStates[u'alertTitle2'], wsStates[u'alertDescription2'], wsStates[u'alertExpires2'])

if wsStates[u'alertTitle3'] != ' ':
   sendAlertEmail(wsStates[u'alertTitle3'], wsStates[u'alertDescription3'], wsStates[u'alertExpires3'])

if wsStates[u'alertTitle4'] != ' ':
   sendAlertEmail(wsStates[u'alertTitle4'], wsStates[u'alertDescription4'], wsStates[u'alertExpires4'])

if wsStates[u'alertTitle5'] != ' ':
   sendAlertEmail(wsStates[u'alertTitle5'], wsStates[u'alertDescription5'], wsStates[u'alertExpires5'])

Any suggestions how to fix?

JP

Posted on
Sat Jul 16, 2022 10:00 am
roquej offline
User avatar
Posts: 609
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Not sending emails at all

Sorry folks. I am a certifiable dork. Was using the incorrect SMTP devices.

JP

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest