Skip navigation
ffcai
Currently Being Moderated

cfmail and JavaMail

Mar 10, 2012 1:27 PM

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

 
Replies
  • Currently Being Moderated
    Mar 11, 2012 12:33 AM   in reply to ffcai

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2012 12:28 PM   in reply to ffcai

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2012 1:22 PM   in reply to ffcai

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2012 1:34 PM   in reply to ffcai

    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==-

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2012 1:38 PM   in reply to ffcai

    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2012 6:57 PM   in reply to ffcai

    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==-

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 12, 2012 1:00 AM   in reply to -==cfSearching==-

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2012 3:29 AM   in reply to ffcai
    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==-

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 14, 2012 4:21 PM   in reply to -==cfSearching==-

    ( 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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points