http://coldfusion.com logo
#box-products
Title
# box-products
d

dick

03/09/2022, 10:54 AM
Is there a way to use
cbmailservices
as a
LogBox
email appender?
w

wil-shiftinsert

03/09/2022, 11:18 AM
Yes there is. The problem with appenders is: they are not created by wirebox, so it is a bit harder to get a reference to your cbmailservices. I am just wondering why you can’t use the Email appender.
d

dick

03/09/2022, 11:23 AM
I can use the regular Email Appender but was trying to reduce the number of credentials I need to keep a track of - just the API Key vs SMTP server, username, password & port
w

wil-shiftinsert

03/09/2022, 11:24 AM
Appenders are not created by wirebox but you can get a reference to coldbox in your appender, so I guess you could also load cbmailservers by doing a
Copy code
var mailservice = variables.coldbox.getWirebox().getInstance("MailService@cbmailservices");
inside your
processQueueElement
method. I described how to create a custom appender and how to access coldbox here https://shiftinsert.nl/logbox-modify-your-message-format/ Be careful with using an email appender for error logging. I have cleared some huge mailqueues several times, because people didn’t realize how many emails some errors would generate (or even errors in error handling which makes this horror recursive). In these scenario’s it would be a lot better to have some email digest which just sends all entries from the last X minutes, so you are not flooding your mailbox
d

dick

03/09/2022, 11:27 AM
Thanks, I'll take a look.
w

wil-shiftinsert

03/09/2022, 11:31 AM
I can use the regular Email Appender but was trying to reduce the number of credentials I need to keep a track of - just the API Key vs SMTP server, username, password & port
You only have to configure them once. And if you are worried about code security, you can store them in environmental variables.
d

dick

03/09/2022, 11:33 AM
Sure, they are only referenced once and I do have them in env vars -- just my tidy mind -- I have an email service, why not use it everywhere :-)
w

wil-shiftinsert

03/09/2022, 11:35 AM
That’s right. cbmailservice has a very nice way of interfacing with all kind of email services. I think it will not be that hard to use cbmailservices in an appender. Just give it a try and feel free to ask if you run into any issues.
d

dick

03/09/2022, 11:36 AM
Thanks, will do
2 Views