Is there a way to use `cbmailservices` as a `LogBo...
# box-products
d
Is there a way to use
cbmailservices
as a
LogBox
email appender?
w
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
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
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
Thanks, I'll take a look.
w
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
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
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
Thanks, will do