can i do something in my cfadmin settings so they ...
# cfml-general
g
can i do something in my cfadmin settings so they are always redirected to my account, even the cc and bcc
a
[pls use threads] Do you need them to actually be delivered? Or is it more you specifically don't want them delivered, but still want to see them?
If it's the latter, we use https://github.com/ReachFive/fake-smtp-server, and it's dead handy.
g
> Do you need them to actually be delivered? Or is it more you specifically don't want them delivered, but still want to see them?
exactly it should be delivered to me and not to actual users
r
We take the following approach: on startup, our application figures out what type of server (production, staging, dev) it’s running on. Within the app architecture, our mail-handling service (through which all email generated by the application is routed — it’s just a component we wrote) does a number of things for consistent handling of mail, one of which is forcing all outgoing email on non-production servers to go to our dev email addresses rather than wherever it would normally be addressed. (That’s way better than searching for all of the cfmail tags and preceding each one with some version of an if statement that does effectively the same thing.)
… and on our dev boxes, we use a fake SMTP server, much like a couple listed above so that there’s even less noise in our real inboxes and less risk of leaking emails to the real world from the development environment.
a
That's good architecture, @rstewart
The way these things should be done
r
born from the scars of doing it the wrong way for too long.
😜 2
b
Our mailer component is similar, but it points to an SMTP server that rewrites all recipient addresses so we can do bulk testing and ensure that the correct recipient received a message. So if the message was meant for example@example.com, it would be sent to example__example.com@ourtestdomain.com. Everything then gets dumped into a single inbox so we can see them all in one spot.
2
🙌🏻 1
e
You could always include a function call, or component that always injects BCC your@email. You could setup the mailer to connect to a local mail server such as postfix, maildrop, hmail server, eudora, ectra that appends a BCC to all emails before sending the email. If its just local dev, download xampp and fire off its mailserver for fake mail use or just use cffile to redirect your cfmail tag to a file and be done with it. 🙂
b
We rewrite all the emails so there is no chance it escapes and goes to a user. There are better ways described above, but what we have works for us.
g
@rstewart would you share some an architecture approach by code or it’s cannot be shared Btw the way you explained I am thinking the same way
c
mailtrap.io is another good test mailbox service
j
If you're using coldbox cbmailservices is super handy. You can configure an interceptor to detect the environment (dev, staging, prod, etc.) and then override any of the email settings (to address, subject, cc, bcc, body, etc. ) with test values when you're not running it in prod. So along with changing the to address to a test address, we always prepend a message to the body with information about who it would have gone to and all that if it had run in production. Similarly, we prepend the subject with a "Test - " so it's apparent upon receiving it that it's just a test email.
(You can do all of of this without coldbox and cbmailservices of course, but I find it a lot easier than what we did before we used them.)
c
We use cbmail and have configured it to send differently using different providers in the environmental config - works a treat
👍 1
e
or you could do something like this, then you just push your emails as function args, <!--- Define the function to send email using the default mail server ---> <cffunction name="sendEmail" access="public" returnType="void"> <cfargument name="to" type="string" required="true"> <cfargument name="from" type="string" required="true"> <cfargument name="subject" type="string" required="true"> <cfargument name="message" type="string" required="true"> <cfmail to="#arguments.to#" from="#arguments.from#" subject="#arguments.subject#" server="#this.mail.server#"> <cfmailparam name="bcc" value="bcc@example.com"> <cfmailparam name="cachedafter" value="#now()#"> #arguments.message# </cfmail> </cffunction> <!--- Define functions for each mail server that calls the sendEmail function with the default mail server ---> <cffunction name="funMailserver1" access="public" returnType="void"> <cfargument name="to" type="string" required="true"> <cfargument name="subject" type="string" required="true"> <cfargument name="message" type="string" required="true"> <cfset sendEmail(to=arguments.to, from="default_sender@example.com", subject=arguments.subject, message=arguments.message)> </cffunction> <cffunction name="funMailserver2" access="public" returnType="void"> <cfargument name="to" type="string" required="true"> <cfargument name="subject" type="string" required="true"> <cfargument name="message" type="string" required="true"> <cfset sendEmail(to=arguments.to, from="default_sender@example.com", subject=arguments.subject, message=arguments.message)> </cffunction> <cffunction name="funMailserver3" access="public" returnType="void"> <cfargument name="to" type="string" required="true"> <cfargument name="subject" type="string" required="true"> <cfargument name="message" type="string" required="true"> <cfset sendEmail(to=arguments.to, from="default_sender@example.com", subject=arguments.subject, message=arguments.message)> </cffunction>
r
MailHog is the bomb! See my reply to your other post that you made one minute before this one.