Skip to main content
dk22197913
Inspiring
March 13, 2023
Answered

CFmail extra character in subject line

  • March 13, 2023
  • 2 replies
  • 1164 views

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

    This topic has been closed for replies.
    Correct answer dk22197913

    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!

    2 replies

    Charlie Arehart
    Community Expert
    Community Expert
    March 21, 2023

    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)
    dk22197913
    Inspiring
    April 6, 2023

    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

     

     

    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.

     

     

    dk22197913
    dk22197913AuthorCorrect answer
    Inspiring
    April 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!

    BKBK
    Community Expert
    Community Expert
    March 14, 2023

    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."

    dk22197913
    Inspiring
    March 20, 2023

    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>

     

     

     

    BKBK
    Community Expert
    Community Expert
    March 21, 2023

    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.

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