My company wants it so that whenever someone sends out an email from Ignition, they want the sender to also be a recipient.
We use the smtpProfile method to email things out so the email user/password is configured on the gateway.
Is there a way to get the email associated with the smtpProfile so I can just add that to the BCC argument to sendEmail, or is this something I will need to keep track of manually?
I'm lacking java knowledge but I am almost there I think. Seems to have to be run on the gateway so I have a message handler setup.
I am looking at this - SmtpManager
I am just testing and right now I have
def gwGetProfileNames():
import com.inductiveautomation.ignition.gateway.smtp.SmtpManager as t
return t.getProfileNames()
def getProfileNames():
return system.util.sendRequest(project='PSM4_Project', messageHandler='getSMTPProfiles')
Which gives me the issue that getProfileNames expected 1 argument but got 0. Usually to me that means to me something has to be instantiated first (since the docs don't show an argument) but if I try something like
def gwGetProfileNames():
import com.inductiveautomation.ignition.gateway.smtp.SmtpManager as t
smtpManager = t()
return t.getProfileNames()
I get
TypeError: can't instantiate abstract class (com.inductiveautomation.ignition.gateway.smtp.SmtpManager)
So I am missing some piece of the puzzle here.
You need to get the existing instance of SMTPManager from the GatewayContext, not create your own.
2 Likes
You are importing a class, not an instance. You generally need to get a GatewayContext instance, and use its methods to get other stuff. Start here:
https://forum.inductiveautomation.com/search?q=GatewayContext%20order%3Alatest
2 Likes
NB - in 8.1.24 and later, you want getEmailProfileManager
off GatewayContext; getSmtpManager
is deprecated.
2 Likes
That part always trips me up. Thank you and @pturmel for the link. I've done it only a handful of times before so I need to refresh myself.
I am able to get the SmtpManager and the profile names with
def gwGetProfileNames():
from com.inductiveautomation.ignition.gateway import IgnitionGateway
return IgnitionGateway.get().getSmtpManager().getProfileNames()
But it is just a list of the names of the SmtpProfile, which is what the docs say so it's not surprising but I don't know where to go from here with these names to getting info out of the actual smtp profile.
There is this which looks promising SmtpSettings
But I don't see a way to get the SmtpSettings from the GatewayContext the way I do with getSmtpManager
on this page GatewayContext
It gets complicated, fast. You can't retrieve the EmailNotificationSettingsRecord you need in a type-safe way, because you aren't going to be in the right classloader. From your gatewaycontext, you can access the persistence interface and issue a raw query looking for the right row, as SQL against the internal DB.
2 Likes
Ah that explains this at top of the documentation
java.lang.Object
simpleorm.dataset.SRecordInstance
com.inductiveautomation.ignition.gateway.localdb.persistence.PersistentRecord
com.inductiveautomation.ignition.gateway.smtp.SmtpSettings
I think I am almost there but I am doing something wrong
def gwGetProfileNames():
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import com.inductiveautomation.ignition.gateway.smtp.SmtpSettings as SmtpSettings
import simpleorm.dataset.SQuery as SQuery
import simpleorm.dataset.SRecordMeta as SRecordMeta
query = SQuery(SRecordMeta(SmtpSettings, 'SMTPSETTINGS')).eq(SmtpSettings.Name,'My Name')
return IgnitionGateway.get().getPersistenceInterface().query(query)
Gives me the error
java.lang.NullPointerException: java.lang.NullPointerException
I know thanks to Kindling the query I really want to write is SELECT USERNAME FROM SMTPSETTINGS WHERE NAME='Some Name'
but this is not working.
From what I was reading it seems like this IgnitionGateway.get().getPersistenceInterface().query(query)
the query I feed it must be an SQuery, which I think I have correct, but to form that SQuery I need a SRecordMeta and I think that is where I am doing somtehing wrong - I suspect it is SRecordMeta(SmtpSettings, 'SMTPSETTINGS')
this piece of code.
It feels like I am not importing it correctly, like how before I was just importing the gateway class but not the instance that was running my intuition is I am doing the same here but I don't see how I would get the SmtpSettings instance?
SmtpSettings has a public static final field META that's an instance of SRecordMeta.
So it should be:
SQuery(SmtpSettings.META).eq(SmtpSettings.Name,'My Name')
1 Like
Awesome. Some weird behavior with this
def gwGetProfileNames():
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import com.inductiveautomation.ignition.gateway.smtp.SmtpSettings as SmtpSettings
import simpleorm.dataset.SQuery as SQuery
import simpleorm.dataset.SRecordMeta as SRecordMeta
query = SQuery(SmtpSettings.META).eq(SmtpSettings.Name,'Brian NotRealLastName')
return IgnitionGateway.get().getPersistenceInterface().query(query)
This runs quickly and gives me an empty list []
which is to be expected since there is no Brian NotRealLastName
smtp profile, and calling this with a system.util.sendRequest
.
However when I put in a real name that does exist in SMTPSETTINGS, the task never finishes, I get the

that never goes away unless I interrupt script console or close designer.
The results of PersistenceInterface::query
can't be returned to a client, PersistentRecord
doesn't exist in that scope.
There's probably some ugly error in the gateway logs.
2 Likes
You're right it was unable/refusing to return it. I have all my logs on default settings though and with this
def gwGetProfileNames():
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import com.inductiveautomation.ignition.gateway.smtp.SmtpSettings as SmtpSettings
import simpleorm.dataset.SQuery as SQuery
import simpleorm.dataset.SRecordMeta as SRecordMeta
logger = system.util.getLogger("Email Testing")
query = SQuery(SmtpSettings.META).eq(SmtpSettings.Name,'Brian Karabinchak')
result = IgnitionGateway.get().getPersistenceInterface().queryOne(query)
logger.info("Result")
logger.info(str(result))
logger.info(str(type(result)))
return result
all I see is
Worse I was able to get was just a timeout error on the client side.
Either way I was able to get it working with this
def gwGetProfileNames():
from com.inductiveautomation.ignition.gateway import IgnitionGateway
import com.inductiveautomation.ignition.gateway.smtp.SmtpSettings as SmtpSettings
import simpleorm.dataset.SQuery as SQuery
import simpleorm.dataset.SRecordMeta as SRecordMeta
query = SQuery(SmtpSettings.META).eq(SmtpSettings.Name,'Brian RealName')
result = IgnitionGateway.get().getPersistenceInterface().queryOne(query)
return result.getUsername()
Thanks for the help everyone. Was another learning experience