Whatever message this page gives is out now! Go check it out!
Mode | Syntax |
Creating the service | new mail() or createObject("component", "mail") |
Initializing the attributes | Any one of the following:
|
Executing the service action | mailService.send(_attribute-value_pair_) |
from | to | subject | bcc |
cc | charset | debug | failto |
group | groupcasesensitive | mailerid | maxrows |
mimeattach | password | port | priority |
query | replyto | server | spoolenable |
startrow | timeout | type | username |
useSSL | useTLS | wraptext | remove |
body |
<cfmail from="#form.mailFrom#"> |
mailerService.setFrom(form.mailFrom); |
Description | Used to add cfmailparam tags. For example, to attach a file or add a header to an e-mail message. |
Syntax | mailService.addParam(attribute-value pair) |
Returns | Nothing |
Arguments | All attributes supported by the cfmailparam tag can be used as attribute-value pairs. |
Description | Used to add cfmailpart tags. For example, one part of a multipart e-mail message. |
Syntax | mailService.addPart(attribute-value pair) |
Returns | Nothing |
Arguments | All attributes supported by the cfmailpart tag can be used as attribute-value pairs. |
Description | Used to invoke the mail service to send an e-mail message. |
Returns | Nothing |
Syntax | mailService.send(attribute-value pair) |
Arguments | All attributes supported by the cfmail tag. |
Description | Sets attributes for the mail function. |
Returns | Nothing |
Syntax | mailService.setAttributes (attribute-value pair) |
Arguments | All attributes supported by the cfmail tag. |
Description | Gets attributes that were set for the mail function. |
Returns | Returns a struct with all or some of the attribute values. |
Syntax | mailService.get_Attributes_ (attributelist) |
Arguments | A comma-separated list of attributes. If no list is specified, all defined attributes are returned. |
Description | Removes all attributes added for the mail function. |
Returns | Nothing |
Syntax | mailService.clearAttributes(attribute_list) |
Arguments | A comma-separated list of attributes. |
Description | Removes cfmailparam tags that were added using the addParam method. |
Returns | Nothing |
Syntax | mailService.clearParams() |
Arguments | None |
Description | Removes cfmailpart tags that were added using the addPart method. |
Returns | Nothing |
Syntax | mailService.clearProcResults() |
Arguments | None |
Description | Removes all attributes, cfmailparam tags, and cfmailpart tags that were added using the methods addParam and addPart. |
Returns | Nothing |
Syntax | mailService.clear() |
Arguments | None |
<h3>Sending mail in cfscript</h3>
<cfscript>
/* create mailer service */
mailerService = new mail();
if(IsDefined("form.mailto"))
{
if(form.mailto is not "" AND form.mailfrom is not "" AND form.Subject is not ""
and form.attachment is not "")
{
savecontent variable="mailBody"{
WriteOutput("This message was sent by an automatic mailer built with cfmail:
= = = = = = = = = = = = = = = = = = = = = = = = = = =" & "<br><br>" & form.body);
}
/* set mail attributes using implicit setters provided */
mailerService.setTo(form.mailto);
mailerService.setFrom(form.mailFrom);
mailerService.setSubject(form.subject);
mailerService.setType("html");
/* add mailparams */
mailerService.addParam(file=expandpath(form.attachment),type="text/plain",remove
=false);
/* send mail using send(). Attribute values specified in an end action like "send" will not persist after the action is performed */
mailerService.send(body=mailBody);
writeoutput("<h3>Thank you</h3>" & "<p>Thank you, " & mailfrom & "<br>" & "Your message, " & subject & ", has been sent to " & mailto & "</p>");
}
}
</cfscript>
<p>
<form action = "mail1.cfm" method="POST">
<table>
<tr>
<td>TO</td>
<td><input type = "Text" name = "MailTo"></td>
</tr>
<tr>
<td>FROM</td>
<td><input type = "Text" name = "MailFrom"></td>
</tr>
<tr>
<td>SUBJECT</td>
<td><input type = "Text" name = "Subject"></td>
</tr>
<tr>
<td>ATTACHMENT</td>
<td><input type = "file" name = "attachment"></td>
</tr>
</table>
<hr>
MESSAGE BODY:
<br>
<textarea name ="body" cols="40" rows="5" wrap="virtual"></textarea>
<!--- Establish required fields. --->
<input type = "hidden" name = "MailTo_required" value = "You must enter a recipient">
<input type = "hidden" name = "MailFrom_required" value = "You must enter a sender">
<input type = "hidden" name = "Subject_required" value = "You must enter a subject">
<input type = "hidden" name = "Body_required" value = "You must enter some text">
<input type = "hidden" name = "attachment_required" value = "You must select a file">
<p><input type = "Submit" name = ""></p>
</p>
</form>