CFMAIL not working - coldfusion

I'm testing out a contact form and I can't figure out why I'm not receiving any of the emails. I have checked my spam folder and my applications developer assures me that the email server is working correctly. I have tested all the variables with CFOUTPUT.
<cfmail
from="#form.email#"
to="myemail#gmail.com"
subject="Request a Quote"
type="html">
Name: #form.name#<br/>
Email: #form.email# <br/>
Phone: #form.phone#<br />
City: #form.city#<br />
State: #form.state#<br />
Wheel: #form.wheel#<br />
<cfif isdefined("form.size")>
Size: #form.size#<br />
</cfif>
<cfif isdefined("form.vehicle_info")>
Vehicle: #form.vehicle_info#<br />
</cfif>
<cfif isdefined("form.finishes")>
Finishes: #form.finishes#<br />
</cfif>
</cfmail>
I'm not getting any errors, but I am not receiving any of the emails

put tag before <cfmail and end of "</cfmail tag" Then for value from must be in format email address even it is not exist. example from="abcd#abc.com"

Related

How to display image in email using coldfusion?

I've pasted a image in CKEditor and stored into DB. After retrive the data and sent to a mail. The Text content is displaying into the email but not displaying the image. I'm not sure how to display the image in email without cfmailparam. I've stored those content in cfsavecontent and put the variable into the cfmail tag. Exmple code given following..
<cfsavecontent variable="MailBody">
<cfoutput>
Test comment with Image<br /> <br /> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAA5CAYAAADUS9LZAAAgAElEQVR4nO2cZ3wUV5qvu429O7t7d2Y8YefO7O7d3Uswygnl0N2SWjnngGWwwUOyMZiMQUKARJDIOdlgvAM2BmyQkEAJRVAAJCFEEpiclEBSd3V/ee6H6i61JPDYHsC+gHsUyRAAAAAElFTkSuQmCC" /><br /> <br /> test signature<br /> thanks,<br /> tester
</cfoutput>
</cfsavecontent>
Note: The img src data is rough value.
<cfmail from="tester#mail.com" subject="TestEmail" to="dev#email.com" server="SMTP">
#MailBody#
</cfmail>
Now the email sending without the image. Its working fine in CF2010 and not working in CF2016.
How can I display that image into the mail? Please guide me I'm a new guy for the CF technology.
Thanks in Advance!
Instead of img tag use cfimage tag with isBase64="yes" attribute. Like this,
<cfsavecontent variable="MailBody">
Test comment with Image<br /><cfimage action = "writeToBrowser" source ="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." isBase64= "yes">
<br /> <br /> <br /> test signature<br /> thanks,<br /> tester
</cfsavecontent>
<cfmail from="tester#mail.com" subject="TestEmail" to="dev#email.com" server="SMTP">
<cfmailpart type="text/html">
#MailBody#
</cfmailpart>
</cfmail>

How to end the session after logging out in ColdFusion

I'm using CFML for my application. I need help with developing a logout operation that destroys a session. For now, on the logout link I'm calling the login page but when the BACK Button on the browser is clicked the user is still logged in.
<!---LoginForm.cfm>--->
<!---Handle the logout--->
<cfif structKeyExists(URL,'logout')>
<cfset createObject("component",'authenticationService').doLogout() />
</cfif>
<!---Form processing begins here--->
<cfif structkeyExists(form,'submitLogin')>
<!---Create an instane of the authenticate service component--->
<cfset authenticationService=createObject("component",'authenticationService') />
<!---Server side data validation--->
<cfset aErrorMessages=authenticationService.validateUser(form.userEmail,form.userPassword)>
<cfif ArrayisEmpty(aErrorMessages)>
<!---Proceed to the login procedure --->
<cfset isUserLoggedIn=authenticationService.doLogin(form.userEmail,form.userPassword) >
</cfif>
</cfif>
<!---Form processing ends here--->
<cfform>
<fieldset>
<legend>Login</legend>
<cfif structKeyExists(variables,'aErrorMessages') AND NOT ArrayIsEmpty(aErrorMessages)>
<cfoutput>
<cfloop array="#aErrorMessages#" index="message" >
<p >#message#</p>
</cfloop>
</cfoutput>
</cfif>
<cfif structKeyExists(variables,'isUserLoggedIn') AND isUserLoggedIn EQ false>
<p class="errorMessage">User not found.Please try again!</p>
</cfif>
<cfif structKeyExists(session,'stLoggedInUser')>
<!---display a welcome message--->
<p><cfoutput>Welcome #session.stLoggedInUser.userFirstName# </cfoutput>
<p>Logout</p>
<cfelse>
<dl>
<dt>
<label for="userEmail">Email address</label>
</dt>
<dd>
<cfinput type="email" name="userEmail" required="true" >
</dd>
<dt>
<label for="userEmail">Password</label>
</dt>
<dd>
<cfinput type="password" name="userPassword" required="true" >
</dd>
</dl>
<cfinput type="submit" name="submitLogin" value="Login" />
</fieldset>
</cfif>
</cfform>
<cfdump var="#session#">
<!---authenticationService.cfc--->
<cfcomponent>
<cffunction name="validateUser" access="public" output="false" returntype="array">
<cfargument name="userEmail" type="string" required="true" />
<cfargument name="userPassword" type="string" required="true" />
<cfset var aErrorMessages=ArrayNew(1) />
<!---Validate the email--->
<cfif NOT isValid('email',arguments.userEmail)>
<cfset arrayAppend(aErrorMessages,'Please,provide a valid email address') />
</cfif>
<!---Validating the Password--->
<cfif arguments.userPassword EQ ''>
<cfset arrayAppend(aErrorMessages,'Please, provide a password') />
</cfif>
<cfreturn aErrorMessages />
</cffunction>
<!---doLogin() Method--->
<cffunction name="doLogin" access="public" output="false" returntype="boolean">
<cfargument name="userEmail" type="string" required="true" />
<cfargument name="userPassword" type="string" required="true" />
<!---create the isUserLoggedIn variable--->
<cfset var isUserLoggedIn=false />
<!---get the user data from the database--->
<cfquery datasource="myapp" name="getInfo">
select * from Info
where emailid='#form.userEmail#' and password='#form.userPassword#'
</cfquery>
<!---Check if the query returns one and only one user--->
<cfif getInfo.recordcount eq 1 >
<!--- log the user in --->
<cflogin>
<cfloginuser name="#getInfo.username#" password="#getInfo.password#" roles="#getInfo.role#">
</cflogin>
<!--- save user data in session scope --->
<cfset session.stLoggedInUser={'userFirstName'=getInfo.username} />
<!---change the isUserLoggedIn variable to true--->
<cfset var isUserLoggedIn=true />
</cfif>
<!---return the isUserLoggedIn variable --->
<cfreturn isUserLoggedIn />
</cffunction>
<!---doLogout() Method--->
<cffunction name="doLogout" access="public" output="false" returntype="any">
<!---delete user from session scope--->
<cfset structDelete(session,'stLoggedInUser') />
<!---log the user out--->
<cflogout />
</cffunction>
</cfcomponent>
Regarding the back button after logout, the situation being that someone could log off and walk away from their computer without closing the browser or locking it. Then anyone else could go back on their browser and view the data they had been viewing before logging out.
We solved this for a financial application by implementing a Pragma: no-cache header on every page request. This forces requests to the page to reload from the server, not just load what's in the browser's cache. This means the back button will request the previous URL from the server, which will check session and kick you to your logged out landing page.
It will throw off some users who are used to navigating your site a certain way, but it will make it much more secure.

coldfusion 9 audit trail

I want to audit how many times a certain page is executed. I was hoping to add <cfinclude template="audit.cfm"> to the end of the page and log simple data, like user, date, script name.
Question: how do I pass a current script name into <cfinclude>?
I am using CF9 and application.cfm. I thought I can add code to onSessionEnd(), but I don't think it will work. Here is my onSessionEnd() and onRequestEnd()
<cffunction name="onSessionEnd">
<cfset SESSION.session_time = TimeFormat(Now() - SessionScope.started, "H:mm:ss")> <=== want to do this!!!
<cfset structClear(SESSION)> <=== currently in place
</cffunction>
<cffunction name="onRequestEnd">
<cfif NOT isDefined("URL.contentonly")>
<p align="right">
<cfoutput>
<font size="2" face="sans-serif" color="black">
<i>©#Year(Now())# Seattle Pacific Industries Inc</i><BR>
</cfoutput>
</p>
</cfif>
</cffunction>
Thanks,

When using Cfmail is it possible to see the email before sending?

From examples I seen online It seems using cfmail is only to send emails automatically.
Would it be possible to see the email HTML text before sending it the the recipient?
In other words I would be able to change the 'TO:' email part.
Is this possible or cfmail only works sending emails automatically?
Example code of cfm file:
<cfquery....>
select ...
</cfquery>
<cfmail query="test"
to=""
from="mail#mail.com"
.....
type="html">
here is test
<cfoutput>
<p>#data</p>
</cfouput>
</cfmail>
I would do something like this.
<cfquery....>
select ...
</cfquery>
<!--- Save your content to a variable --->
<cfsavecontent variable="content">
here is test
<cfoutput>
<p>#data#</p>
</cfouput>
</cfsavecontent>
<!--- Output that content into a div so the user can see it--->
<div id="email-content">
<cfoutput>#content#</cfouput>
</div>
<button onclick="sendEmail()">send</button>
<!--- When the user clicks send call a JS function --->
<!--- Use ajax to call a send function and use your email content --->
<script type="text/javascript">
function sendEmail()
{
var emailContent = $('#email-content').html();
$.ajax({
type: 'POST',
url: "yourCFCfileToSendEmail?method=sendEmail&content=" + emailContent ,
success: function(){
console.log("email sent");
}
});
}
</script>
<!--- An example of what your email function would look like in the cfc . --->
<cffunction name="sendEmail" access="remote" returntype="string" returnformat="plain">
<cfargument name="toEmail" type="string" required="true">
<cfargument name="fromEmail" type="string" required="true">
<cfargument name="subject" type="string" required="true">
<cfargument name="content" type="string" required="true">
<cfargument name="replyTo" type="string" required="false">
<cfset attributes = decodeParams(params)>
<cfparam name="arguments.replyTo" default="#arguments.fromEmail#">
<cfif NOT Len(Trim(arguments.replyTo))>
<cfset arguments.replyTo = arguments.fromEmail>
</cfif>
<cfmail to="#arguments.toEmail#"
from="#arguments.fromEmail#"
subject="#arguments.subject#"
replyto="#arguments.replyTo#"
type="html">
<h1>#arguments.subject#</h1>
#content#
</cfmail>
</cffunction>
I have not tested this. It will take some tweaking but should point you in the right direction.
This answer is very similar to Will's. It does the job with a bit less code.
Assuming the user submits a form, start with this:
session.mailto = form.mailto;
session.mailfrom = form.mailfrom;
Then do this:
<cfsavecontent variable = "session.mailbody">
code
</cfsavecontent>
Present this to the user:
<a href="javascript:void(0)"
onclick="Emailwin=window.open('SendMail.cfm','thewin',
'width=500,height=500,left=30,top=30');">
<button type="button">Send Mail </button>
SendMail.cfm looks like this:
<cfmail to="#session.mailto#" from="#session.mailfrom#"
subject = "something" type="html">
#session.mailbody#
</cfmail>
<h3>Your mail has been sent. This window will close in 2 seconds.</h3>
<script language="javascript">
winClose=window.setTimeout("window.close()",2000);
</script>
The code which I copied was written a long time ago in an envrionment with locked down computers. If I were to do it again, I would probably use hidden form fields instead of session variables. They are more likely to change unexpectedly these days.
If you are coding for the general public, bear in mind that the user might change his browser preferences to prevent the new window from opening.

'This page cannot be displayed' error on long running ColdFusion 9 page

We have a long running ColdFusion script running on ColdFusion 9 which is erroring with the following message:
This page cannot be displayed
Internal system error while processing the request for this page (http:///www.example.com).
Please retry this request.
If this condition persists please contact your corporate network administrator and provide the code shown below.
Notification codes
(1, INTERNAL_ERROR, http:///www.example.com)
I haven't been able to determine what part of ColdFusion is generating these and don't have any other information as I haven't been able to reproduce the error and only have details from a screenshot.
Does anyone know what might be generating this error or how I can find out more information about it?
Use a try/catch block to wrap your code and have it send you an email with all the error details (or you could log these to your database or write them to a log, etc).
<cftry>
<!--- your code goes here --->
<!--- catch and email any exceptions --->
<cfcatch type="any">
<cfmail to="your-email" from="your-email" subject="something" type="html">
<h3>An Error Occurred on #cfi.script_name#</h3>
<h3><strong>DATE:</strong> #dateFormat(now(), "mm/dd/yyyy") & " " & timeFormat(now(), "hh:mm:ss")#</h3>
<br />
<br />
<cfif isDefined("cfcatch")>
<h5>catch object:</h5>
<cfdump var="#cfcatch#">
<br />
<br />
</cfif>
<cfif isDefined("ERROR")>
<h5>Error object:</h5>
<cfdump var="#ERROR#">
<br />
<br />
</cfif>
<cfif isDefined("cgi")>
<h5>cgi object:</h5>
<cfdump var="#cgi#">
<br />
<br />
</cfif>
<cfif isDefined("variables")>
<h5>variables object:</h5>
<cfdump var="#variables#">
<br />
<br />
</cfif>
<cfif isDefined("form")>
<h5>form object:</h5>
<cfdump var="#form#">
<br />
<br />
</cfif>
<cfif getapplicationMetadata().sessionmanagement and isDefined("session")>
<h5>session object:</h5>
<cfdump var="#session#">
<br />
<br />
</cfif>
<cfif isDefined("local")>
<h5>local object:</h5>
<cfdump var="#local#">
<br />
<br />
</cfif>
</cfmail>
</cfcatch>
</cftry>