Integrating SendGrid’s SMTP API with CFMAIL - coldfusion

I am using SendGrid’s SMTP API (not WEB API) and am considering sending an email using cfmail. If I use cfmail to send the email, and want to use the X-SMTPAPI header somewhere, do you think that cfmail is a place to do that? Please clarify.

You would do this by adding a custom header, using the cfmailparam tag. As such:
<cfmailparam
name="X-SMTPAPI"
value="{\"category\":\"Cool Emails\"}">
In context of the cfmail tag it would be as follows.
<cfmail
from="you#example.com"
to="nick#sendgrid.com"
subject="I am using CF Mail to do this!">
<cfmailparam
name="X-SMTPAPI"
value="{\"category\":\"Cool Emails\"}">
Look at my awesome use of cfmail!
</cfmail>
More can be found in the Adobe Documentation

This is what worked for me.
The above suggestion threw errors.
<cfmailparam
name="X-SMTPAPI"
value='{"category":["Cool Emails"]}'>

Related

Not able to send mail from ColdFusion 10

In my application I am using ColdFusion 10. I am not able to send any mail using the cfmail tag.
When I log into the administrator and click on the Undelivered Mail button, it is throwing the following error:
Error retrieving markup for element mailBody : Client verification failure. [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
Error invoking CFC /CFIDE/administrator/mail/undeliveredmail.cfc : Client verification failure. [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
Can anyone tell me what is wrong?
It sounds like you have a bad CF installation. The admin should not be throwing errors, this looks like a permissions issue at first glance.
Have you tried setting all the params within the cfmail tag (eg, mailserver, username, pwd) instead of using the values set in CFadmin?
Do you get an error when you create a single CFM page with just a CFMAIL tag in it?
You need to ensure your CF install is up to date with all the hotfixes and that they are installed correctly.
see http://forums.adobe.com/thread/884947
or post the error message you are getting when you use your CFMAIL tag

Getting the Named Anchor using ColdFusion

How can I get the URL using ColdFusion?
I tried the following but it did not return the Named Anchor.
For example http://www.makeup.edu/test/#abc
<cfdump var=#cgi#>
You can't, 'cause although it is in the URL, it is only meant for the client. It will not be sent to the server, therefore you can never find that in the CGI scope.
As Henry says, you can't get them with ColdFusion because they are never sent with the request. What you need to do is to pull them out with Javascript (which can access them), and then send them back to the server via some other mechanism, like putting them in a cookie or something. It depends on the situation as to how you tackle that part, but it's probably a different question anyhow.
Bottom line: the info is never transmitted with the request, so the web server doesn't get it, so the web server cannot pass it to ColdFusion, so ColdFusion does not receive it.
Add an additional url parameter to identify the anchor. So you could create the link http://www.makeup.edu/test/?anchor=1#abc
The user clicks on the link and the anchor goes to the right place and then you could use:
<cfif ISDEFINED("url.anchor")>
<cfif url.anchor EQ 1>
... do stuff here...
</cfif>
</cfif>

coldfusion spooler not working

I have a coldfusion mail spooler locking up on me everytime I send out an email using this code:
<cfmail TO="xxxx#gmail.com"
FROM="xxxx#xxxxxx.com"
SUBJECT="Your Order!!!!!" type="html">
hello
</cfmail>
Only way I can get this thing to email out of the spooler is to stop IIS and start IIS.
Then it flushes through.
If I use
<cfmail TO="xxxx#gmail.com"
FROM="xxxx#xxxxxx.com"
SUBJECT="Your Order!!!!!" spoolEnable="false" type="html">
hello
</cfmail>
Then the email goes straight through no problem, I would like to use the spooler since it has a less lag for the user.
What's going on with my coldfusion spooler??
I am running 9,0,0,251028 (standard)
BTW: I have tried doing (with no luck):
<cfset sFactory = CreateObject("java","coldfusion.server.ServiceFactory")>
<cfset MailSpoolService = sFactory.mailSpoolService>
<cfset MailSpoolService.stop()>
<cfset MailSpoolService.start()>
This issue seems to be around since at least CF6.x and we haven't been able to find a permanent solution for it. Restarting the mail service is far from perfect.
Some have found that excluding the CF mail spooling directory from the virus scans helped, others say that sending emails with CFMAIL instead of with a cfscript did the job.
Here's a similar SO post and here's one from the Adobe forums

Coldfusion uses wrong (cached?) variables at random

We have a dedicated server running CentOS and Coldfusion 8.
All cfmail email is routed through Google with cfmail and smtp.
Every now and then, when cfmail is used, the 'FROM' field uses an address from a totally different website.
For instance:
Use form on Site A
Get an email: "Subject: On Site A From: siteb#siteb.com"
Where the from is a completely different variable in another set of code on another part of the server- there is no reason it should see this.
On the other side, sometimes sending an email to sitea#sitea.com has email wind up in Site B inbox, a completely different Google account.
What causes this to happen? Some kind of memory/cache issue? Or is there a funky DNS record causing issue?
Example:
Application.cfm (starts with some UDF includes, and then):
<cfinvoke component="#request.componentPath#.variables" method="getGlobal" />
Variables.cfc (a lot of variables defined within, but here is the cfmail vars):
<cffunction name="getGlobal" access="public" output="false" returntype="void">
<cfscript>
request.siteEmail = "email#mysite.com";
request.siteMailServer = "smtp.gmail.com";
request.siteMailUsername = "root#mysite.com";
request.siteMailPassword = "[redacted]";
</cfscript>
</cffunction>
It sounds like it's possible it could be a var scoping issue, but we can't know for sure until you share some code...
Looks like you're running multiple sites? there's a setting in the CF caching page in admin to do with caching web server paths:
From http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf3638e6-7ffc.html :
Disabling the cacheRealPath attribute To ensure that ColdFusion always returns pages from the correct server, disable Cache Web Server Paths in the Caching page of the ColdFusion Administrator. (When you use the multiserver configuration, set the cacheRealPath attribute to false for the ProxyService in the jrun_root/servers/servername/SERVER-INF/jrun.xml file.)
Might not be it, but it's at least quick to try out.

CFMail with catchall email addresses

I can't believe I've never noticed this before, but it seems that CFMail won't send to an email address that isn't explicitly set up on the destination mailserver.
This means that if I'm using 'info#somedomainorother.com' and have that set up to catch all email on the domain, CFMail won't send to 'test#somedomainorother.com'.
This causes a massive amount of problems for me, as I'm using CFMail to send out order confirmations, member activations and all manner of other bits and pieces.
Whatever your views on using catchall addresses, it can't be denied that people do use them So, in any case that a user enters a made-up address into one of my sites, they won't receive their email.
There must, simply MUST be a way around this - can anyone help?
For refernece, the message that appears in the logs when sending to a catchall address is 'Invalid Addresses'.
EDIT: Here's the CFMail syntax I'm using -
<cfmail to="#Arguments.sEmailAddress#" from="#Application.sAppEmailAddress#" subject="Stock reminder confirmation: #Local.qGetProductDetails.sProductName# - #Application.sCompanyName#" type="HTML" server="#Application.sAppEmailServer#" username="#Application.sAppEmailAddress#" password="#Application.sAppEmailPassword#">
Translates into:
<cfmail to="thisisatest#somedomainorother.com" from="application#mydomainname.com" subject="Stock reminder confirmation: Some product - My Company" type="HTML" server="mail.mydomainname.com" username="application#mydomainname.com" password="XXXXXX">
All works fine for info#somedomainorother.com but not for randombunchofcharacters#somedomainorother.com.
Important to note of course, that the catch-all is working correctly in all other respects, test emails from mail clients work perfectly.
Its not ColdFusion that cares about email validity, its the SMTP server. CF only cares about well formed email addresses.
If you initiated a telnet session to your mail server and tried to use the same address, I'm sure it would have the same result.
Debugging tips for SMTP Connectivity:
http://www.talkingtree.com/blog/index.cfm/2004/11/22/debug-smtp
Can I see your CFMAIL tag setup? CFMAIL doesn't care as long as the email address is properly formatted.
Urgh!
Turns out it was an issue with the server. For some reason, catchall email accounts serverwide had stopped working properly. After an email to my hosting provider, it's all working fine with no code changes.
They're somewhat cagey as to what caused the issue, and I was still able to use an email client to send mail out to the addresses...
Thanks for the help in any case. ;)