Skip to main content
Inspiring
March 28, 2024
Question

Sending an email

  • March 28, 2024
  • 3 replies
  • 955 views

So, on my website I have this code that works when it comes to sending an email to the website owner. This is from contact form. Somebody will populate stuff and send to the owner. 

 

 

            <!--- Send email after successful registration --->
            <cfmail
                server="131.153.102.58"
                from="support@almarsguides.com"
                to="#form.email#"
                subject="Sample CF e-mail">
                This is the body of a test email.
            </cfmail>

 

 

However, I want to make registration where user will recieve email to finish registration, however, this is what is happening. 

 

 

<cfmail
  server="smtp.gmail.com"
  port="587"
  useSSL="false"
  username="AlmarsGmailEmail"
  password="TEST"
  from="support@almarsguides.com"
  to="#form.email#"
  subject="Sample CF e-mail">
  
  This is the body of a test email.
  
</cfmail>

 

 

 

 

I changed password here for obvious reasons but other info is correct. Now here me out. If I would to use first part of the code, page loads fine and I can finish registration but there is no mail sent. However, when I use the second code (and it doesn't matter in what way I change it), I am getting error 500.  

    This topic has been closed for replies.

    3 replies

    Inspiring
    March 29, 2024

    Hello everyone, I solved the issue by making new email (noreply) and adding username and pass (new one). It seems that data I used before was incorrect. 

    Thank you all for the help!

    Charlie Arehart
    Community Expert
    Community Expert
    March 29, 2024

    I would be surprised to hear that alone was the solution, given the error message you got above. 

     

    Did you end up creating a simple test page? If so, you could easily test if that cfmail above (to that ip and port) would work or not, with or without a username/password, etc.

     

    If indeed you get that specific error when only the problem is the username or password, that would be useful to hear. Others seeing this in the future would be be benefited, so I hope you'll please try it. 

     

    BTW, note that you can also more easily diagnose things by adding spoolenable="false" to the cfmail, and then the attempt to send the email would happen immediately, rather than going to the spool. More important, any error would happen then immediately in that request, without need to look in that mail.log.

     

    To be clear, you don't NORMALLY want to do that, as if you create many emails, letting it spool them makes the process asynchronous (the request need not wait for the email to be sent to the smtp server, or not). 

    /Charlie (troubleshooter, carehart. org)
    Inspiring
    April 2, 2024

    I have additional question regarding this. I have a code like this (html of content is cut off)

     

    <cfmail
      server=""
      port="587"
      username=""
      password=""
      from="donotreply@almarsguides.com"
      to="#form.email#"
      subject="Registration confirmation"
      type="html">

     

    I removed server, from, username and password here. But my question is, how can I hide this blunt info so that I can somewhat protect it? I am not sure how safe is it to enter this data just like that. 

    Community Expert
    March 28, 2024

    In the original forum email I received, the password you had looked like this:

    !!Faroutbrotherdood#34

     

    Hashmarks or pound signes are special characters in CF and need to be doubled in order to be escaped.

     

    !!Faroutbrotherdood##34

     

    Dave Watts, Eidolon LLC

     

    Dave Watts, Eidolon LLC
    Inspiring
    March 28, 2024

    This made error 500 vanish but email is still not sent. I will have to look up the reason for this as @Charlie Arehart said above. 

    Charlie Arehart
    Community Expert
    Community Expert
    March 28, 2024

    Aleksandar, please look at the mail.log in the CF logs folder (such as in cfusion/logs, or [instancename]/logs for those using multiple CF instances). That will show the error that happens when email is sent.

     

    You may find the destination mail server (in the server attribute) is either momentarily unavailable, or it may be blocking your email (for any of many reasons, which will be reported in that log line), or the mail server may rejecting the mail due to your temporarily exceeding limits which THAT mail server imposes (CF has no such limit), and so on.

     

    Also, please consider when writing such a request for help to whether you need to offer all the verbiage about how the app works (which in this case is inconsequential). More important, you would help yourself to create simply a small sample template that just does the email. And then test the two differnet forms, in that test page alone.

     

    You will almost surely find that the problem has nothing to do with "how your app works" (or on what basis you decide to send emails) and is solely about the cfmail and the values you use (though again it could vary based on "when" you try it, if you exceed some limits in sending too many emails, where the mail server--in that case gmail--might reject it.)

     

    As always, just trying to help. Let us know how things go.

    /Charlie (troubleshooter, carehart. org)
    Inspiring
    March 29, 2024

    This is the error I am getting (for example)

     

    "ERROR","Thread-1356960","03/29/2024","04:49:53","mail","Could not connect to SMTP host: 131.153.102.58, port: 587;Could not connect to SMTP host: 131.153.102.58, port: 587;lucee.runtime.exp.NativeException: Could not connect to SMTP host: 131.153.102.58, port: 587
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2211)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
    at javax.mail.Service.connect(Service.java:366)
    at lucee.runtime.net.smtp.SMTPSender.run(SMTPSender.java:60)
    Caused by: javax.mail.MessagingException: Could not connect to SMTP host: 131.153.102.58, port: 587;
    nested exception is:
    javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
    ... 4 more

    Charlie Arehart
    Community Expert
    Community Expert
    March 29, 2024

    That error indicates "Could not connect to SMTP host: 131.153.102.58, port: 587", which would imply that your cf machine cannot reach the mail server at that ip address and port (assuming they work for anyone sending email to it). 

    /Charlie (troubleshooter, carehart. org)