# Way to get email address of smtpProfile?

**URL:** <https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [April 12, 2023, 3:20pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359 "2023-04-12T15:20:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 12, 2023, 3:20pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/1 "2023-04-12T15:20:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 12, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/2 "2023-04-12T15:52:28Z")

</div>

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](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/com/inductiveautomation/ignition/gateway/smtp/SmtpManager.html#getProfileNames())

I am just testing and right now I have

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2023, 4:07pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/3 "2023-04-12T16:07:51Z")

</div>

You need to get the existing instance of SMTPManager from the GatewayContext, not create your own.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 12, 2023, 4:08pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/4 "2023-04-12T16:08:28Z")

</div>

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](https://forum.inductiveautomation.com/search?q=GatewayContext%20order%3Alatest)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2023, 4:09pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/5 "2023-04-12T16:09:58Z")

</div>

NB - in 8.1.24 and later, you want `getEmailProfileManager` off GatewayContext; `getSmtpManager` is deprecated.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 12, 2023, 5:16pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/6 "2023-04-12T17:16:56Z")

</div>

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

```auto
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](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/com/inductiveautomation/ignition/gateway/smtp/SmtpSettings.html#%3Cinit%3E())

But I don't see a way to get the SmtpSettings from the GatewayContext the way I do with `getSmtpManager` on this page [GatewayContext](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/com/inductiveautomation/ignition/gateway/model/GatewayContext.html)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2023, 5:25pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/7 "2023-04-12T17:25:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 12, 2023, 5:52pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/8 "2023-04-12T17:52:51Z")

</div>

Ah that explains this at top of the documentation

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2023, 5:53pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/9 "2023-04-12T17:53:46Z")

</div>

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')`

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 12, 2023, 6:07pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/10 "2023-04-12T18:07:11Z")

</div>

Awesome. Some weird behavior with this

```auto
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  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/f/ef9f5ab1df93923f555d20af860681cb7ea2c6e6.png)  
that never goes away unless I interrupt script console or close designer.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 12, 2023, 6:11pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/11 "2023-04-12T18:11:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 12, 2023, 6:26pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/12 "2023-04-12T18:26:23Z")

</div>

You're right it was unable/refusing to return it. I have all my logs on default settings though and with this

```auto
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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/539dbf9427ffbd21f2e6f2c03241356fa9da3701.png)

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

```auto
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

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [June 3, 2025, 1:23pm UTC](https://forum.inductiveautomation.com/t/way-to-get-email-address-of-smtpprofile/72359/13 "2025-06-03T13:23:47Z")

</div>

Hello,

I tired to use your solution in version 8.1.36, but it does not work, some classes are deprecated.

```python
def getEmailSenderFromSMTPProfile(profile="default"):
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	emailProfileManager = IgnitionGateway.get().getEmailProfileManager()
	defaultEmailProfile = emailProfileManager.getProfile(profile)
	
	return str(defaultEmailProfile.get().getProfile().getAuthCredential().getUsername())

```

I found this alternative solution, this may help someone.
