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

cfmail and JavaMail

Explorer ,
Mar 10, 2012 Mar 10, 2012

Copy link to clipboard

Copied

Hi All,

  My applicatoin needs to send some email notifications with some registration codes included to my customers. So they can register an account by using this code to verify that the owns the email addresses. In my local machine, I try to implement the email functionality. I encountered some problems, however. 5 hours are gone for such a beautify Saturday. I am alittle tired. So I come here for help again. Greatly appreciated for any help offered. Here are two of my questions.

1. cfmail does not work in Developer's edition?

   Of course cfmail tag is the simplest way to do emailing. In Administrator page I have entered "smtp.gmail.com" (without quotation) as the Mail Server, and my gmail user name and password as the authentication. Then I try cfmail tag in ColdFusion page. It does not work, neither does it display any error message. Also, in Administrator page I am not able to check "Verify mail server connection" checkbox. If I check it and click "submit changes" button, the checkbox remains unchecked and the check mark I put them disappear. I suspect that cfmail tag does not work in Developer edition, right?

2. Second question: I went ahead try to write a program myself using JavaMail. I have done so before in some Java project. So it did not take me long to reuse some code from before. After fully tested it, I moved the Java class files to C:\ColdFusion9\wwwroot\WEB-inf\classes. Then I invoked this Java class in ColdFusion page, the system gave me this error message below. I did try to find the solution myself. But it turned out to be far more complited than I thought. Someone suggests removing activation.jar file in C:\ColdFusion9\lib folder. But if I do this, my java program would not work at all. I know the error below is caused by different classloader version. Yet I have no idea how to and where to tweak it. Anyone has experience in this or related problems before? Much much Thanks!!

Error casting an object of type com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler to an incompatible type. This usually indicates a programming error in Java, although it could also mean you have tried to use a foreign object in a different way than it was designed.

com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler

Views

5.3K

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 , Mar 11, 2012 Mar 11, 2012

I know where goes wrong. It has nothing to do with the mail server, User name, and password fileds. These fields are filled correctly. The problem is related to port number and SSL and TLS. First port 25 does not work for smtp.gmail.com. If you only set port 25 in administrator page, the page will complete succesffully but the mail won't go to your inbox. Instead I need to specify both port number 465 used and SSL checked, or both port number 587 used and TLS checked. I can't specify port 465 in

...

Votes

Translate

Translate
Community Expert ,
Mar 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

ffcai wrote:

Hi All,

  My applicatoin needs to send some email notifications with some registration codes included to my customers. So they can register an account by using this code to verify that the owns the email addresses. In my local machine, I try to implement the email functionality. I encountered some problems, however. 5 hours are gone for such a beautify Saturday. I am alittle tired. So I come here for help again. Greatly appreciated for any help offered. Here are two of my questions.

1. cfmail does not work in Developer's edition?

   Of course cfmail tag is the simplest way to do emailing. In Administrator page I have entered "smtp.gmail.com" (without quotation) as the Mail Server, and my gmail user name and password as the authentication. Then I try cfmail tag in ColdFusion page. It does not work, neither does it display any error message. Also, in Administrator page I am not able to check "Verify mail server connection" checkbox. If I check it and click "submit changes" button, the checkbox remains unchecked and the check mark I put them disappear. I suspect that cfmail tag does not work in Developer edition, right?

As far as I know, CFmail does work on the Developer Edition of ColdFusion 9. I suspect the gmail settings in the Administrator had mistakes.

I would advise you to try and fix this, rather than to bring in JavaMail. Did you check the logs? There will likely be something there.

For a start, google: coldfusion smtp.gmail.com.You will see how others got it to work.


2. .....I did try to find the solution myself. But it turned out to be far more complited than I thought. Someone suggests removing activation.jar file in C:\ColdFusion9\lib folder.

Almost never a wise thing to do.

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 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

Good to see you again BKBK!

I am a little frustrated. Now I can get the cfmail to work. But things are still weird. I copied this code snippet from inernet and replaced with my info. It works.

<cfset mailAttributes = {

server="smtp.gmail.com",

username="myAddress@gmail.com",

password="myPassword",

from="fromAddress@gmail.com",

to="toAddress@hotmail.com",

subject="Eat my shorts, man!"

}

/>

<cfmail port="465" useSSL="true"

attributeCollection="#mailAttributes#"

>port 465, SSL enabled</cfmail>

Now I am trying to modify my version according to the above. Surpirsingly, the below does not work. Everything is the same!

<cfmail subject="#form.subject#"  from="fromAddress@gmail.com" to="#form.toAddress#"

                    username="myAddress@gmail.com" password="myPassword" useSSL="yes" port="465">

#form.messageBody#

</cfmail>

Then I added one more attribute to the list: server="smtp.gmail.com". This make it happy! But I already have the Mail server, User name, and password in place in Administrator page. I should not need to provide them here. Surpisingly I have to. If I omit the username attribute, it gives me this error:

This exception was caused by: javax.mail.AuthenticationFailedException: failed to connect.

If I omit the password attribute, the page finished normally. No error shown. No error in application.txt log file either. But the email was not sent to my email address. Its like nothing happened.

So I have to manually key in all these three attributes even though I have specified them in the Administrator. I have no idea what is going on...

Also if I omit the useSSL attribute and change port number to 25, it does not work either. The page finished normally. But no errors at all. application.txt log file does not show any error too.

I am glad I have a working version to use now. But I am frustrated about why the other version do not work. They should.

Do you have any ideas?

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
Valorous Hero ,
Mar 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

So I have to manually key in all these three attributes even though I have specified them in the Administrator. I have no idea what is going on...

1) You should review the documentation. Some attributes only work in combination with others. So if one of the required elements is missing all of the related settings in that group may be ignored.

2) You should be using debug=true . That generates extremely detailed information. Note, the output is not sent to standard mail.log. See the documentation for the log file location.

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 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

I read the cfmail doc already. It does not say anything helpful to my question. For example, I already filled in Mail server, User name, password in administrator page, why I have to specify them again in the cfmail tag? The same mail server, username, password, port number works in JavaMail, why it does not work in ColdFusion? Clearly it has nothing to do with gmail account settings, otherwise my JavaMail program would not work. I also used "verify mail server connection" checkbox in Administrator page to verify the connection between CF and gmail server, it told me "Connection Verification Successful."


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 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

You are right Ffcai. If you include attributes in the cfmail tag that have already been set in the Administrator, then it shouldn't really matter. That is, so long as the attribute values are valid. The values in the cfmail tag overrule those of the Administrator (Hope I remember correctly).

What you're witnessing might be just a tiny bug that needs ironing out. On the whole, cfmail is a tried and tested tool.

The documentation says the only 3 required attributes are from, to and subject. So what happens when you set port, SSL use, server, and so on in the Administrator, and do just this:

<cfmail

from="fromAddress@gmail.com",

to="toAddress@hotmail.com",

subject="Eat my shorts, man!">

Blah, blah, blah.

</cfmail>

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 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

I know where goes wrong. It has nothing to do with the mail server, User name, and password fileds. These fields are filled correctly. The problem is related to port number and SSL and TLS. First port 25 does not work for smtp.gmail.com. If you only set port 25 in administrator page, the page will complete succesffully but the mail won't go to your inbox. Instead I need to specify both port number 465 used and SSL checked, or both port number 587 used and TLS checked. I can't specify port 465 in the administrator page and enable SSl in ColdFusion page. This won't work. I never see things like this. Why I have to specify both in one place or another. CF is not smart enough to figure out.

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
Valorous Hero ,
Mar 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

Why I have to specify both in one place or another.

The two settings generally go hand in hand so I am not sure why you would want to separate them ... what is the benefit?

I think ColdFusion speed up development time only when you get used to all this weird behaviors..

Not weird. It is well documented that gmail is very particular about the proper mail settings . It sounds like you were not using the correct settings initially and without detailed log information ended up chasing your tail for while 😉 That is why the "debug" option is a must IMO. It has certainly saved my sanity many a time.

Message was edited by: -==cfSearching==-

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
Guide ,
Mar 12, 2012 Mar 12, 2012

Copy link to clipboard

Copied

Quite, I'm not sure you can "blame" the issue on ColdFusion. Out of interest, why not just run an SMTP engine on the server itself? Far easier and more reliable than relying on some public relay which can be down or blacklisted at any time.

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 13, 2012 Mar 13, 2012

Copy link to clipboard

Copied

I am sure on this particular issue I can "blame" ColdFusion. If I specify any argument in the ColdFusion code, it should use that one. If I do not specify any argument, go to the Administrator to find it. This is how Application.cfc is implemented. ColdFusion needs to understand the definition of consistency and common sense.

ColdFusion is convenient in most places. But admit it, there are inconsistencies in several places. Also I just notice the hosting fee is much higher than other web development langages. So if one chooses to use ColdFusion, he needs to pay some more money each money for hosting. AND, he needs to deal with all these inconsistencies. AND get "blamed" for not regonize such problems.

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 13, 2012 Mar 13, 2012

Copy link to clipboard

Copied

The two settings generally go hand in hand so I am not sure why you would want to separate them ... what is the benefit?

We are not talking about benefit here. The question is we can't do it. We are not allowed to do this simple and legitimate operation.

Not weird. It is well documented that gmail is very particular about the proper mail settings . It sounds like you were not using the correct settings initially and without detailed log information ended up chasing your tail for while 😉 That is why the "debug" option is a must IMO. It has certainly saved my sanity many a time.

debug option produces same things as the exception messages throwned on the page, right? I remember they are the same last time I used it as you recommended. I think my main problem is put some arguments in Administrator and the others in the ColdFusion code. I did not do this on purpose. I did not notice the SSL and TLS check boxes in Administrator page initially.



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
Valorous Hero ,
Mar 13, 2012 Mar 13, 2012

Copy link to clipboard

Copied

We are not talking about benefit here. The question is we can't do it. We are not allowed to do this simple and legitimate operation.

No asking what is the benefit or use case is a valid question.  You could separate "username" and "password", but that would not make much sense. It would probably cause problems instead of solve them. Is what you are trying to do commonly necessary and will it typically result in valid mail settings? In your case it did not. In fact separating the settings probably made things worse for you because it was less apparent the gmail settings were incorrect. If there is a vaild need for it, then yes it should be allowed - or at least documented that it is not. But that is still in question... ( All that said, I have not tested any of this. I am just taking your word for it and assuming the settings were not actually mixed up somehow. )

debug option produces same things as the exception messages throwned on the page, right?

No. The debug option produces extremely detailed logs which should have indicated right off the bat that the port or authentication mode was incorrect.  My logs show the port and SSL settings quite clearly.  Are you sure you actually looked at the correct log file? Because some of your comments suggest you did not...  You have to use the tools at your disposal otherwise you are just shooting in the dark 😉  Also, if spooling is enabled, any exceptions would not appear on the page anyway since the mail is sent later.


I think my main problem is put some arguments in Administrator and the others in the ColdFusion code. I did not do this on purpose. I did not notice the SSL and TLS check boxes in Administrator page initially.

Yep, which is why I suggested  keeping the relevant settings in one place. If all mail should use the same server, port and authentication mode it only makes sense to enter all of those settings at the Admin level. Whereas if every mail uses different settings, it should be done at the cfmail level . It is just harder debug which-settings-override-which the more you mix and match and more likely the combined settings will come out wrong if you forget what you entered. (And if you are not using the full debugging logs .. it is no wonder you are frustrated.)  Better not to confuse yourself by splitting the settings unless there is something to be gained by it. 

Message was edited by: -==cfSearching==-

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
LEGEND ,
Mar 14, 2012 Mar 14, 2012

Copy link to clipboard

Copied

( All that said, I have not tested any of this. I am just taking your word for it and assuming the settings were not actually mixed up somehow. )

I did test it. I could split the server or port between admin and <cfmail> tag no problem.

I couldn't split the username / password, but I don't see that as being so surprising.

Oddly I could not specify an SSL override unless I also specified the server.  But the mail is placed in the undeliverable dir, which is something.  And it was logged in the out log too.

TBH, I think trying to split the username/pwd between admin and code, and splitting server/port/ssl the same way seem like a bloody stupid thing to want to do.  However it seems what the OP was trying to do: split the server and port between admin and <cfmail> tag works fine.

So I dunno if their analysis of their problem is terribly sound.

--

Adam

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 14, 2012 Mar 14, 2012

Copy link to clipboard

Copied

LATEST

thank you~

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 14, 2012 Mar 14, 2012

Copy link to clipboard

Copied

Thanks a lot for your kindness help. I learned from it. Lets move on.

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
Valorous Hero ,
Mar 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

I read the cfmail doc already.

Okay, but sometimes when we have been looking at the same thing for a long time we stop seeing it and miss things. CF is different than java mail. Like I said some attributes work only in conjunction with others. If one is missing (ie  "If I omit the password attribute") then all of the linked attributes are ignored. In other words it is the same as if you did not supply any of the attributes. So what I am gently hinting at here is maybe your code is not doing what you think it is ?

Also you did not say whether you tried the debug attribute. That setting logs the entire mail exchange, from start to finish. Did you try it? Because I think the logs would be able to tell you more conclusively whethere is it is a problem with the code or CF.

Message was edited by: -==cfSearching==-

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 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

I forgot to mention. I did try it. When the debug is on, does the error messages go to a separate log file or CF display it on the page?

Based on your hint and BKBK's advices, I think I found out what is wrong now. I will put the answer in the post below.

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
Valorous Hero ,
Mar 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

When the debug is on, does the error messages go to a separate log file or CF display it on the page?

It goes to a separate log file. The location varies by install type, but from the documenation:

  • yes: sends debugging output to standard output. By default, if the console window is unavailable, ColdFusion sends output to cf_root\runtime\logs\coldfusion-out.log on server configurations. On J2EE configurations, with JRun, the default location is jrun_home/logs/servername-out.log. Caution: If you set this option to yes, ColdFusion writes detailed debugging information to the log, including all message contents, and can generate large logs quickly.
  • no: does not generate debugging output.

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 11, 2012 Mar 11, 2012

Copy link to clipboard

Copied

I put the answer above. Thanks for your time.

I think ColdFusion speed up development time only when you get used to all this weird behaviors...

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