problems getting started with cbmailservices

48 views
Skip to first unread message

daltec

unread,
Jan 8, 2018, 11:24:25 PM1/8/18
to ColdBox Platform
Hello all, I've been working with ColdFusion for a while now but am new to ColdBox and MVC in general. I've set up a test site and am having problems figuring out how to send emails using the cbmailservices plugin. I have what I hope are some basic newbie questions. I keep getting an error:

No matching function [GETINSTANCE] found

Here is my model, emailService.cfc. I am using the sample code from https://www.forgebox.io/view/cbmailservices.

component accessors="true"{
   
   
// Properties
    property name
='mailService' inject='mailservice@cbmailservices';
    property name
='renderer' inject='provider:coldbox;renderer';

   
/**
     * Constructor
     */

    emailService
function init(){
       
       
return this;
   
}
   
   
function contactUs(event,rc,prc) {
       
       
// build mail and send
       
var oMail = getInstance( "mailService@cbmailservices" )
       
.newMail( to="mys...@myemail.com",
           
from="mys...@myemail.com",
            subject
="Mail Services Rock",
            bodyTokens
={ user="Luis", product="ColdBox", link=event.buildLink( 'home' )} );

       
// Set a Body
        oMail
.setBody("
            <p>Dear @user@,</p>
            <p>Thank you for downloading @product@, have a great day!</p>
            <p><a href='@link@'>@link@</a></p>
        "
);

       
//send it
       
var results = mailService.send( oMail );
       
       
}

}

Here are my settings from conbox.config:
mailsettings = {
            // The default token Marker Symbol
            tokenMarker = "@",
            // protocol
            protocol = {
                class = "cbmailservices.models.protocols.CFMailProtocol",
                properties = {}
            }
        };

Do I need anything else in the config file? Won't coldbox pick up username and password from the Lucee settings? Sending emails with <cfmail> works fine btw.

I sure would appreciate any tips or suggestions! Thanks in advance!

Eric Peterson

unread,
Jan 8, 2018, 11:26:20 PM1/8/18
to col...@googlegroups.com
You don't have access to the `getInstance` function inside models, only handlers (though you could inject wirebox and call it off of the injector).  The good news is you already injected the `mailService` above as a property.  That should be all you need.

Cheers,
Eric
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/0467b088-63c1-49fc-9022-4f171731d1b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

br...@bradwood.com

unread,
Jan 8, 2018, 11:32:33 PM1/8/18
to col...@googlegroups.com
The getInstance() method is not automatically available in models.  You don't need to call that method anyway.  You've already injected the mailservices via the cfproperty as mailService. So just replace that entire method call with a direct reference to the mailService variable.
 
   var oMail = mailService
        
.newMail( to="mys...@myemail.com", ....
 
Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--

daltec

unread,
Jan 8, 2018, 11:51:22 PM1/8/18
to ColdBox Platform
Thanks a lot Eric! When I simply plopped the code from the model into my handler, it did indeed send the email. Which I gather is not the proper way to do it... :-)  But I will figure it out sooner or later. Thanks for your speedy assistance; I appreciate it!

daltec

unread,
Jan 8, 2018, 11:55:30 PM1/8/18
to ColdBox Platform
Thanks a lot Brad! I did not see your message until after I had replied to Eric. I am experimenting now with your suggestions. I am getting more errors, but at least they are new errors! So that is progress, right?

Thanks for the help!

daltec

unread,
Jan 8, 2018, 11:59:06 PM1/8/18
to ColdBox Platform
Please belay my most recent reply; I got it figured out. I had forgotten to update my handler. All is well and I am sending emails!

Thanks Brad and Eric for your help! I really appreciate it!


On Monday, January 8, 2018 at 11:32:33 PM UTC-5, Brad Wood wrote:
Reply all
Reply to author
Forward
0 new messages