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

Sending an email

Explorer ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

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.  

Views

187

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

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)

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 29, 2024 Mar 29, 2024

Copy link to clipboard

Copied

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

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 29, 2024 Mar 29, 2024

Copy link to clipboard

Copied

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)

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

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

 

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

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. 

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 29, 2024 Mar 29, 2024

Copy link to clipboard

Copied

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!

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 29, 2024 Mar 29, 2024

Copy link to clipboard

Copied

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)

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 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

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. 

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 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

LATEST

You're right that it's not a great idea to embed secrets in your source code. But there are a couple of things you can do about that. First, you could just put all that information into the Mail section of CF Administrator and just use a CFMAIL tag without SERVER, PORT, USERNAME or PASSWORD. Second, you could encrypt the specific file using the cfcompile.bat file that comes with CF (I don't know if it also works with Lucee, but it's worth playing around and finding out.) I recommend the first approach.

 

Dave Watts, Eidolon LLC

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