|
Mailing Lists
|
Home /
Groups /
ColdFusion Newbie (CF-Newbie)
ColdFusion schedule
Hi,John Barrett 02/11/12 05:30 P > In the CF admin, I set the mail server as 127.0.0.1, but theJustin Scott 02/13/12 07:02 A Hi Justin,John Barrett 02/15/12 09:32 P > I am using the Mac OS X, and I don't think that it comes with aJustin Scott 02/16/12 02:43 A Hi Justin,John Barrett 02/17/12 01:56 A Hi, I am trying to test a cf schule task without using the CF admin, that is using <cfschedule> In the CF admin, I set the mail server as 127.0.0.1, but the mail is not being delivered, is there anything else I have to do in the CF admin to test cfmail locally? I have to set this up using the <cfschedule> tags as my hosting company does not support scheduled tasks, as they told me to set up a cron task in cpanel, which I don't even know what that is. I want to make sure everything is working on my localhost before I try it on my hosting server. Doing it this way, how can I get the file scheduler.cfm to run without use of the CF admin. my scheduled task(scheduler.cfm): <cfschedule action="update" task="GetDate" operation="httprequest" url="http://localhost/~honoluluhosting/schedule/get_date.cfm" startdate="2/11/2012" starttime="6:00 PM" interval="Daily"> DailyTips task has been set up,... the file that it calls(getDate.cfm): <cfset date = #CreateODBCDate(now())#> <!---<cfset time = Now()> <cfset time = dateadd("h",-6,time) />---> <!--- Get tips from the tips table---> <!---record_id, tipdate, dailytip, consumer_link, research_link---> <cfquery name="rs_date" datasource="#REQUEST.dataSource#"> SELECT * FROM users </cfquery> <!--- Get users & their email from the users table---> <cfquery name="GetUsers" datasource="#REQUEST.dataSource#"> SELECT * FROM users </cfquery> <cfloop query="GetUsers"> <cfmail To="#GetUsers.email_address#" From="johnbarr@hawaii.edu" Subject="Today's Date" type="HTML" server="localhost"> Hello, #name#, today's date is: <br> <em>#DateFormat(date, "mmmm d, yyyy")#</em><br /> </cfmail> </cfloop> > In the CF admin, I set the mail server as 127.0.0.1, but the > mail is not being delivered, is there anything else I have to > do in the CF admin to test cfmail locally? So you have an e-mail server installed and configured on your computer? ColdFusion will attempt to deliver the message to whatever e-mail server is specified and that server is expected to then relay it out to its final destination. If you're on Windows you can use the IIS SMTP service to handle this for you if it's configured properly. Once the code is at your ISP, use their e-mail server name for outgoing e-mail. If you do have a mail server configured, I would check the e-mail logs that ColdFusion keeps under its log folder which will give you more information as any issues it's running into. > I have to set this up using the <cfschedule> tags as my hosting > company does not support scheduled tasks, as they told me to > set up a cron task in cpanel, which I don't even know what that is. FYI, the CFSCHEDULE tag creates a ColdFusion scheduled task in the CF admin. I don't recall off-hand if scheduled tasks in CF can be disabled completely, but if they have disabled CF's scheduled tasks entirely then the CFSCHEDULE tag won't work either. Linux has a scheduling program called "cron" which is essentially its way of handling scheduled tasks for the operating system. The tasks that get scheduled are referred to as "jobs", hence "cron jobs". Their web hosting control panel (cpanel) allows you to add your own tasks to the scheduler. Since you need to call a URL, you would need to look into adding a cron job that uses the "curl" program (short for "call url") to hit the URL for you instead of the CF scheduler if it's not supported. > SELECT * Unrelated, but it's generally considered bad practice to use * in a select statement unless you really need to. Generally, your queries will be easier to understand and perform better if you specify the columns to select out. > <cfloop query="GetUsers"> > <cfmail To="#GetUsers.email_address#" Also unrelated, but one trick I usually put in with a case like this is wrapping the CFMAIL tag with a check to ensure the e-mail address is valid, such as: <cfloop query="GetUsers"> <cfif isValid("email", GetUsers.email_address)> <cfmail to="#GetUsers.email_address#" ...> ... </cfmail> </cfif> </cfloop> This ensures that a malformed e-mail address won't gum up the works and unexpectedly break your scheduled process. -Justin Scot Hi Justin, Thanks so much for your detailed expiation! I am using the Mac OS X, and I don't think that it comes with a SMTP mail server like you describe in windows. I do see the mails in the CF admin/undelivered mail. I thought that it would be a nice way to test to see if everything is working before I upload it tot the server. Yes the other host(I switched to hostek) told me that if I wanted the scheduled task to run automatically I would have to set up cron jobs. They gave me examples of how to set up cron jobs for the e-mails in the database, but not how to set up a url. This is why I switched hosting, as now I can use the cfschedule tag with no problems. Thanks for the advice of using the wildcard "*" I did not now that would affect performance. I like you idea about checking to see if the e-mail is valid. When the user signs up, I check to see if it is a real email, but people do sign up with bad e-mails, like exampl123@gmail.com or something like that, so it passes the test that it is a real e-mail, but some of the them are not real e-mails, and get bounced back. I will be looking into you idea about checking to see if it is a real e-mail in the cfloop Would I do something like this? I don't know if I need to set "email" as a variable. Also, since the application gets all the e-mails from the database and sends a message, I assume that the files email_address is being used. thanks so much, below is the code John <cfset tipdate = #CreateODBCDate(now())#> <!---record_id, tipdate, dailytip, consumer_link, research_link---> <cfquery name="rs_dailytip" datasource="#REQUEST.dataSource#"> SELECT email_address FROM dailytips WHERE tipdate = #tipdate# </cfquery> <!--- Get users & their email from the users table---> <cfquery name="GetMembers" datasource="#REQUEST.dataSource#"> SELECT email_address FROM email_alerts </cfquery> <cfloop query="GetMembers"> <cfif isValid("email", GetUsers.email_address)> <cfmail To="#GetMembers.email_address#" From="gotnutr@hawaii.edu" Subject="Got Nutrients? Daily Tip" type="HTML"> <em>#DateFormat(tipdate, "mmmm d, yyyy")#</em><br /> #rs_dailytip.dailytip#<br /> <br> Consumer Related Article:<br /> <cfoutput><a href="#rs_dailytip.consumer_link#"> #rs_dailytip.consumer_text#</a></cfoutput> <br /> Research Related Article:<br /> <cfoutput><a href="#rs_dailytip.research_link#"> #rs_dailytip.research_text#</a></cfoutput> </cfif> </cfmail> </cfloop> > I am using the Mac OS X, and I don't think that it comes with a > SMTP mail server like you describe in windows. I don't have much experience with Mac OS X, so I'm not sure if an SMTP server ships with it or not. I'm sure there are SMTP engines that can be installed to use for testing, though I can't make a specific recommendation for Mac. Worst case, you can have CF use your ISP's e-mail server as an outgoing relay in most cases, though you may run into port blocks on port 25 (in which case you can try port 587 with authentication enabled). > I like you idea about checking to see if the e-mail is valid. Just to clarify, the isValid() function will check for a valid e-mail format, not whether the e-mail address actually exists out on the Internet. The intent in using it in this case is just to check the format to ensure that the loop won't be broken if a malformed address sneaks into the database somehow. You will still end up with typos and otherwise non-working, but well-formed, addresses which will need to be weeded out from time to time. -Justin Scott Hi Justin, I don't think that Mac OS X has a SMTP server, I am going to ask my Dad about this, as he knows a lot about networks, and maybe he can find a solution to the problem. I will also look for SMTP servers for the mac. My Dad also knows the ISP (Comcast) that we are using so maybe we can find a solution tot he problem. I have a host, that I can test on too, but I like to do everything locally before I upload, maybe it is just me. Thanks alot for explaining about the isValid() function, and that it only checks to see if it is a real e-mail, like somebody@gmail.com. That is that it is a well formatted e-mail. I plan to incorporate this into the code, just as a double check. Yes we get alot of bad e-mails. I am thinking about setting it up as when the users signs up, they will have to verify their e-mail. not sure how to do this yet, but I think that it will not be that hard(I hope). thanks o much for all your help! John
|
May 23, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||