problems getting started with cbmailservices

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:

Here is my model, emailService.cfc. I am using the sample code from ForgeBox: ColdBox Mail Services.

`
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="myself@myemail.com",
from="myself@myemail.com",
subject=“Mail Services Rock”,
bodyTokens={ user=“Luis”, product=“ColdBox”, link=event.buildLink( ‘home’ )} );

// Set a Body
oMail.setBody("

Dear @user@,

Thank you for downloading @product@, have a great day!

@link@

");

//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 works fine btw.

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

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

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="myself@myemail.com", …

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

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… :slight_smile: But I will figure it out sooner or later. Thanks for your speedy assistance; I appreciate it!

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!

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!