You'll have to excuse me a little on this one guys, there's a fair amount of
code involved as I'm unsure as to where the error is occurring.
I've spent today building a mailer service which will handle all the email
processing for the application. This service consists of two elements,
firstly we have the service itself, this contains functions such as setTo(),
setContent(), setSubject() and post(), Anything that involves manipulating
the mail itself. I also have a mail config bean, which contains all the mail
server settings, usernames, passwords and things like this. The config bean
is meant to be passed into the service as a constructor, so I can then
access them for my cfmail tag as #VARIABLES.Instance.Config.getUsername()#
or something like that.
Now the problem I'm having is that when trying to use the service and access
functions such as the server, I get a message saying "The value of the
attribute SERVER is invalid. The length of the string, 0 character(s), must
be greater than or equal to 1 character(s)." Which would suggest that the
config bean is not being created correctly by my Cold Spring framework and
is just full of empty values, or, these values are lost by the time my
mailer service tries to use them.
I set the bean relationships in my ColdSpring XML file like so.
<!-- Mail Configuration -->
<bean id="MailerConfig" class="Model.Mailer.MailerConfigBean">
<constructor-arg name="OutgoingServer">
<value>*******</value>
</constructor-arg>
<constructor-arg name="Username">
<value>******</value>
</constructor-arg>
<constructor-arg name="Password">
<value>********</value>
</constructor-arg>
<constructor-arg name="FromName">
<value>Think Blue Confirmation</value>
</constructor-arg>
<constructor-arg name="FromAddress">
<value>[EMAIL PROTECTED]</value>
</constructor-arg>
<constructor-arg name="ReplyAddress">
<value>[EMAIL PROTECTED]</value>
</constructor-arg>
<constructor-arg name="FailAddress">
<value>[EMAIL PROTECTED]</value>
</constructor-arg>
<constructor-arg name="SpoolEnable">
<value>true</value>
</constructor-arg>
</bean>
<!-- Mailing Service -->
<bean id="MailerService" class="Model.Mailer.MailerService">
<constructor-arg name="Config">
<ref bean="MailerConfig"/>
</constructor-arg>
</bean>
Then inside the mailer service I'm creating a reference to the bean in my
constructor arguments like this:
<!--- Class Constructor Method --->
<cffunction name="init" access="public" output="false"
returntype="MailerService" hint="I'm the class constructor method">
<cfargument name="Config" type="any" required="true"
hint="Configuration for the mailer service" />
<cfscript>
setMailerConfigBean(ARGUMENTS.Config);
</cfscript>
<cfreturn this />
</cffunction>
<!--- Set Mailer Config --->
<cffunction name="setMailerConfigBean" access="public" output="false"
returntype="void" hint="I set the config">
<cfargument name="MailerConfigBean" required="true" type="any"
hint="Instance of the mailer configuration bean" />
<cfscript>
// Set the mail config
VARIABLES.Instance.Config =
ARGUMENTS.MailerConfigBean;
</cfscript>
</cffunction>
Now a quick look at the post function:
<!--- Post Mail --->
<cffunction name="post" access="public" output="false"
returntype="void" hint="I post the mail once its been created">
<cfset var LOCAL = structNew() />
<cfmail from="#VARIABLES.Instance.Config.getFromAddress()#"
to="#VARIABLES.Instance.To#" subject="#VARIABLES.Instance.Subject#"
type="html" server="#VARIABLES.Instance.Config.getOutgoingServer()#"
username="#VARIABLES.Instance.Config.getUsername()#"
password="#VARIABLES.Instance.Config.getPassword()#">
<p>Content Goes Here</p>
</cfmail>
</cffunction>
Now, the service is auto wired into my communications controller using the
following method:
<!--- Set Mailer Service --->
<cffunction name="setMailerService" access="public" returntype="void"
output="false" hint="Autowire for the mailer service">
<cfargument name="MailerService" required="true" type="any"
hint="Instance of the mailer service" />
<cfscript>
// Set Mailer Service
VARIABLES.MailerService = ARGUMENTS.MailerService;
</cfscript>
</cffunction>
And I then create the message and post it from inside the controller with a
simple script within any given function:
// If passed validation then process the mail
VARIABLES.MailerService.setTo("[EMAIL PROTECTED]","Robert
Rawlins"); // Set the to address
VARIABLES.MailerService.setSubject("Enquiry From ThinkBlue.co.uk"); //
Set subject for the mail
VARIABLES.MailerService.setContent("Test"); // Set the body content
for the mail
VARIABLES.MailerService.post(); // Post the mail
I know that's allot of code but I'm at a bit of a loss as to what is causing
my issues, It appears to be passing an empty configuration bean into my
service, with lots of empty variables.
Thanks to anyone who's brave enough to solve this one, if anyone would
prefer the files sent as a .cfc then that's fine, just let me know.
Rob
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create Web Applications With ColdFusion MX7 & Flex 2.
Build powerful, scalable RIAs. Free Trial
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:274441
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4