Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mail.cfc conflicts with Adobe's CFC to send mail - "new mail()" #4

Closed
JamoCA opened this issue May 1, 2020 · 6 comments
Closed

mail.cfc conflicts with Adobe's CFC to send mail - "new mail()" #4

JamoCA opened this issue May 1, 2020 · 6 comments

Comments

@JamoCA
Copy link
Contributor

JamoCA commented May 1, 2020

I updated a regular tag-based CFMail to use cfscript and ran into an issue where instead of accessing the built-in function, it used the sendgrid/helpers/mail.cfc library instead.

Here's Adobe's sample CFML code on how to implement CFMail as a CFC.

https://helpx.adobe.com/coldfusion/cfml-reference/script-functions-implemented-as-cfcs/mail.html

// Creating the service
new mail();  /* or createObject("component", "mail") */

CFDocs has a similar code sample:

https://cfdocs.org/cfmail

savecontent variable="mailBody" {
  writeOutput( "Your Email Message!!" );
};

// Create and populate the mail object
mailService = new mail(
  to = "recipient@example.com",
  from = "sender@example.com",
  subject = "Example email",
  body = mailBody
);

// Send
mailService.send();
@mjclemente
Copy link
Owner

Interesting. What version of Adobe ColdFusion?

And could you put together a small reproduction of the error? I'm just interested in what structure results in the conflict/confusion.

@JamoCA
Copy link
Contributor Author

JamoCA commented May 1, 2020

I used the exact sample that I posted from the links. I'm using CF2016u15, but this syntax (according to CFDocs) has been around since CF9. (I initially didn't use many of the early cfscript functions as there were many bugs and not all functions were supported.)

mailService = new mail(
	to = "myemail@company.com",
	from = "myemail@company.com",
	subject = "Example email #Now()#",
	body = "Example email #now()#"
);
mailService.send();

Resulted in this error:

The value of parameter 1 of the function Right, which is now -5, must be a positive integer

The error occurred in C:/CFusion/cfusion/CustomTags/sendgrid/helpers/mail.cfc: line 933
931 :   public any function onMissingMethod ( string missingMethodName, struct missingMethodArguments ) {
932 :     var action = missingMethodName.left( 9 );
933 :     var property = missingMethodName.right( missingMethodName.len() - 9 );
934 : 
935 :     if ( action == 'serialize' ) {

@mjclemente
Copy link
Owner

Ahhh, ok. Maybe this is because you're using it as a Custom Tag?

I typically include this sendgrid.cfc library within my projects, so mail() wouldn't conflict with it, because the mail.cfc helper is located at some.path.sendgridcfc.helpers.mail. I haven't tried to use this as a Custom Tag - I actually haven't used them at all.

It's my understanding that the "Script functions implemented as CFCs" was a bit of a hack on the part of Adobe for ColdFusion 11 I think. The advice I recall (though I'd need to track its source down), is that the scripts-as-cfcs are a bit buggy and more trouble than they're worth. I'm fairly sure that Adobe has since added actual full script support, so you can just use cfmail() within scripts. It's covered in CFDocs.

I know this doesn't entirely resolve you're issue, but does it help/address it at all?

@JamoCA
Copy link
Contributor Author

JamoCA commented May 1, 2020

Sorry, yes... SendGrid is in the shared CustomTags path.

After encountering the error, I upgraded to the CF11+ cfmail() built-in function (versus the CFC hack). I noticed that Adobe provides little documentation regarding the syntax, but it is similar to the tag. The best guide I could find was from LearnCFInAWeek > Mail. (I like to specify both text & HTML message bodies.)

This may not be an issue at all, but could cause problems for CF9 & 10 users that use the same CustomTags approach. Thanks for the quick response!

@mjclemente
Copy link
Owner

Glad that worked out. I can add a note to the README, regarding CustomTags and older versions of Coldfusion. Do you think that would be worthwhile?

@JamoCA
Copy link
Contributor Author

JamoCA commented Oct 15, 2020

I've got mail() working with ColdFusion. I instantiated the mail helper script using this syntax:

mailService = new sendgrid.helpers.mail(
	to = "myemail@company.com",
	from = "myemail@company.com",
	subject = "Example email #Now()#",
	body = "Example email #now()#"
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants