• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFmail extra character in subject line

Explorer ,
Mar 13, 2023 Mar 13, 2023

Copy link to clipboard

Copied

We are running CF2021 2021,0,04,330004 on Centos 7.9.I jsut started noticing extra character in the subject line. I'm not sure where its coming from, I tried to use all combinations of cfmail - script and tag, with subject being a variable and hard coded string. I added the utf-8 to the cfmail without any change.

 

cfmail( to = "me@example.com",
         from = "them@example.com",
        subject = "Example email" )
{
WriteOutput("test")
}

 

savecontent variable="local.mailBody" {
  writeDump(now());
};

variables._mailto = "me@example.com";
variables._mailfrom = "them@example.com";
variables._mailsubj = "Example Email";

local.mailService = new mail(
to = variables._mailto,
from = variables._mailfrom,
//subject = variables._mailsubj,
subject = "Example Email",
body = local.mailBody,
type = 'html'
);

local.mailService.send();

 

mailerService = new mail();
  /* set mail attributes using implicit setters provided */
  mailerService.setTo("me@example.com");
  mailerService.setFrom("them@example.com");
  mailerService.setSubject("Example email");
  mailerService.setType("html");

savecontent variable="mailBody"{
    WriteOutput("TEST");
    }

mailerService.send(body=mailBody);

 

I get the email, but this is the subject:

 

[]Example Email

 

I inserted the variable in the body and it comes without the character in the email.

 

Any thoughts?

 

thanks

Dejan

Views

459

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Apr 19, 2023 Apr 19, 2023

Just so its a complete thread, the issue was that out CF servers where not in the authorized list of server to send out the email on behalf of other domains, and it was trying to append something in brackets to indicate such but it was failing. They added the servers as trusted and that resolved the issue. Thanks!

Votes

Translate

Translate
Community Expert ,
Mar 14, 2023 Mar 14, 2023

Copy link to clipboard

Copied

I confess that I didn't zoom into your code to see where the square brackets are coming from. That is because I immediately see 2 things I consider important:

 

1) Delete the "code-embedded" comment 

//subject = variables._mailsubj,

 

2) Refactor your code. You should not implement Mail as a CFC in ColdFusion 2021, as you now do. That is a risk. It used to be possible to do that after ColdFusion 9, but it is no longer official after ColdFusion 2018. The documentation will tell you, "In ColdFusion (2018 release), script functions implemented as CFCs are deprecated in ColdFusion."

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

Thanks for the tips.

 

I tried this code in CFSCRIPT inside the .CFM file, this is what I would like to actually use. However its still injecting '[]' brackets. Its pretty simple.

 

One thing I noticed is it appears to happen seldom. I would remove cfmailparam and writeoutput or change anything in the file to see if something is causing the issue, then re-run the file multiple times and it seldon it would not have '[]' in the subject, but in most of the tests it would. This is the only code in the file. I'm stumped.

 

<cfscript>
variables._mailto = "me@example.com";
variables._mailfrom = "them@example.com";
variables._mailbcc = "bcc@example.com";
variables._mailsubj = "Example Email";

cfmail( to = variables._mailto,
         bcc = variables._mailbcc,
         from = variables._mailfrom,
         subject = variables._mailsubj,
         type= "html" )
{
cfmailparam( file = expandPath('./path/') & variables.fName & '_'variables.lName & ('.pdf'));

WriteOutput("Dear " & variables.fName & " " & variables.lName & "<br><br>");

WriteOutput("Check the attachment." & "<br>");
}
</cfscript>

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

I fixed the typo (forgot the '&' after '_'), and retried and still an issue.

cfmailparam( file = expandPath('./path/') & variables.fName & '_' & variables.lName & ('.pdf'));

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Strange indeed. I have been testing your code, but cannot reproduce the issue.

<cfscript>
variables.fName="John";
variables.lName="Smith";
variables._mailto = "me@example.com";
variables._mailfrom = "them@example.com";
variables._mailbcc = "bcc@example.com";
variables._mailsubj = "Example Email";

cfmail( to = variables._mailto,
         bcc = variables._mailbcc,
         from = variables._mailfrom,
         subject = variables._mailsubj,
         type= "html" )
{
cfmailparam( file = expandPath('result.xml'));

WriteOutput("Dear " & variables.fName & " " & variables.lName & "<br><br>");

WriteOutput("Check the attachment." & "<br>");
}
</cfscript>
done sending mail

BKBK_0-1679392340555.png

 

My system consists of:

Windows 10 Pro;

ColdFusion 2021.0.06.330132;

Oracle JDK 11.0.18 (LTS)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Does any of the following help?

  • testing with different values of subject line, for example, "Yet another subject line at #now()#";
  • adding the attribute charset="utf-8" to cfmail;
  • increasing the Java version, for example, to JDK 11.0.18;
  • updating ColdFusion 2021.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

In any case, the issue appears to be a bug. So you should report it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

I thought of yet another test, a curious one. 🙂

What happens when the subject line is an empty string?

cfmail( to = variables._mailto,
         bcc = variables._mailbcc,
         from = variables._mailfrom,
         subject = "",
         type= "html" )
{

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

Yet another test, this one inspired by a question on Stackoverflow about using Unicode characters in cfmail:

variables._mailsubj = "Example Email";
variables._mailsubj = toBase64(variables._mailsubj, "utf-8")

cfmail( to = variables._mailto,
         bcc = variables._mailbcc,
         from = variables._mailfrom,
         subject = "=?utf-8?B?#variables._mailsubj#?=",
         type= "html" )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2023 Apr 05, 2023

Copy link to clipboard

Copied

@dk22197913 , how did you get on? Any update on this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 05, 2023 Apr 05, 2023

Copy link to clipboard

Copied

And did you both see an alternate suggestion I'd offered separately on March 21?


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Dejan, maybe the problems not in cf at all. We can confirm with some different diagnosis. And I'll clarify things for readers who may not understand some of what I'm proposing. 

 

(I propose this alternative to consider since BKBK has confirmed he's been unable to reproduce it, and since his helpful suggestions haven't resolved whatever is the problem for you.)

 

So let's have you look at the email when it ends up in the cf mail spool (such as cfusion/mail/spool). There it's a plain text file ending in .cfmail, and you can open it with any editor. Does it show this extra character there? And do you have any working email you can compare it to? 

 

To be clear, the file appears there only until cf tries to find and send out such mail in the spool, which could be even as little as 15 seconds. That's defined in the cf admin (or on the tags/script to generate an email.) And it's not how much time since you caused the email to be put in the spool: it's just that Cf checks on that interval, over and over. 

 

And this spool is where cf holds it BEFORE it's sent on to the smtp mail server (set in the admin or in code), which then ultimately delivers it to the server/s which then get it to the destination email address/es. As you can see, an email passes through at least  couple other servers before being delivered. So that's why we should start with "considering the source". 

 

Let us know if this helps, or it shows nothing odd to you. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 06, 2023 Apr 06, 2023

Copy link to clipboard

Copied

Hi, thank you both for great suggestions!

I have tried all suggestions except java update to different version, we are on 11.0.7. Basicaly I found that the email going from CF server did not have []. Checking the .cfmail file for one of those emails did not have brackets []:

subject:  Example Email if
X-Mailer:  ColdFusion 2021 Application Server

but when I checked my mailbox, it was there

 

dk22197913_0-1680808665516.png

 

I cannot show the from email, but based on this finding this issue is not caused by ColdFusion, but mail server probably.

 

Interesting thing to all this, the FROM email address that we used - causes this issue. Here is what I found out. We are hosting the CF app for sister company and when the customers fill out the survey, they get an email with PDF attachment. For example, (I'm abfuscating the actual emails). Instead of using our domain

 

variables._mailfrom = "conference@foo.edu";

 

we used their email

 

variables._mailfrom = "conference@sister.edu";

 

However if I use made up from email from our example

 

variables._mailfrom = "them@example.com";

 

I do not get those brackets. So obviously something is being done on the mail server. I'll reach out to our mail admin and see what they think, if its something interesting, I'll add it to this thread.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2023 Apr 19, 2023

Copy link to clipboard

Copied

Just so its a complete thread, the issue was that out CF servers where not in the authorized list of server to send out the email on behalf of other domains, and it was trying to append something in brackets to indicate such but it was failing. They added the servers as trusted and that resolved the issue. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 19, 2023 Apr 19, 2023

Copy link to clipboard

Copied

The mail server filtering was the culprit 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2023 Apr 19, 2023

Copy link to clipboard

Copied

LATEST

A curious one. Thanks for sharing your findings.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation