Configuration
You can configure the module by creating a
cbmailservices
key under the moduleSettings
structure in the config/Coldbox.cfc
file. Here you will configure all the different mailers, default protocol, default sending settings and so much more.moduleSettings = {
cbmailServices = {
// The default token Marker Symbol
tokenMarker : "@",
// Default protocol to use, it must be defined in the mailers configuration
defaultProtocol : "default",
// Here you can register one or many mailers by name
mailers : {
"default" : { class : "CFMail" },
"files" : { class:"File", properties : { filePath : "/logs" } },
"postmark" : { class:"PostMark", properties : { apiKey : "234" } },
"mailgun" : { class:"Mailgun", properties : {
apiKey : "234",
domain: 'mailgun.example.com'
} }
},
// The defaults for all mail config payloads and protocols
defaults : {
from : "[email protected]",
cc : "[email protected]"
},
//Whether the scheduled task is running or not
runQueueTask : true
}
}
By default, the mail services are configured to send mail via the
cfmail
tag using a mailer called default
.The
tokenMarker
is used when doing mail merges with variables. The service will look in the body of the email and do replacements according to the following pattern:@{key}@
The name of the mailer key that will be used by default to send mail. The default is called
default
.A structure of mailer protocol registrations by key name. Each mailer is registered with the following pattern:
mailerKey : {
class : "Alias|wireBoxID|CFCPath",
properties : {}
}
A structure of default variables will be seeded into the Mail payload. These are then used by the protocols as defaults. For example, the
CFMail
protocol will use all these as defaults to the cfmail
tag.By default, a task runs every minute to facilitate the sending of emails asynchronously (non-blocking). Setting runQueueTask to false will override the default and the task will not run.
The mail services can send mail via different protocols. The available protocol aliases you can register are:
CFMail
Null
InMemory
File
Mailgun
Postmark
Please note that some of the protocol have property requirements.
defaultProtocol : "default",
mailers : {
// Default CFMail
"default" : {
class : "CFMail"
},
// FileProtocol
"files" = {
class = "File",
// Required Properties
properties = {
filePath = "logs",
autoExpand = true
}
},
// NullProtocol
"null" = {
class = "Null",
properties = {}
},
// InMemoryProtocol
"memory" = {
class = "InMemory",
properties = {}
},
// PostMark
"postmark" = {
class = "Postmark",
// Required properties
properties = {
apiKey = "123"
}
},
// MailGun
"mailgun" = {
class = "Mailgun",
// Required properties
properties = {
apiKey = "123",
domain = "mailgun.example.com",
// Optional property, defaults to https://api.mailgun.net/v3/
// https://documentation.mailgun.com/en/latest/api-intro.html#base-url-1
// https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions-1
baseURL = "https://api.eu.mailgun.net/v3/" // for the EU region
}
};
}
You can also register ANY WireBox ID or classpath as the mailer as well. This will allow you to register mailers that come from your application or any other module.
moduleSettings = {
cbMailservices : {
defaultProtocol : "default",
mailers : {
"default" : { class : "CFmail" },
// Custom amazon mailer from the amazonsns module
"amazon" : { class : "[email protected]" }
}
}
}
Last modified 2mo ago