• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need some help me java mail-smtp

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I am new to JavaMail and i am trying to follow the following exercise:
http://java.sun.com/developer/onlineTraining/JavaMail/exercises/MailSetup/

I am using rogers high speed internet connection,so i enter the following:


After searching on net,some guys say to add this,along with having a pop3 provider,along with setting some options to accept messages:

I am pretty confused.When i went to that yahoo link for help,there are no settings for command line.Please tell me how to accomplish this..friends
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Other Java APIs
 
Joel McNary
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you specifying the correct user name and password when you connect. They type of error that you are receiving tells me that there is something wrong with your username/password.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joel,
But i never made any changes to the msgsend.java program provided my sun,and they never asked me for username or password.I didnt even know where to add that pop3 thing,so i avoided that too.But after going through your message i hard-coded the username and password in the program,like this:

But still i get the same error.How can i autheticate myself...wat i have to do.please help me.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you just trying to send a message? If so, why are you using POP3?

Strictly a 503 message means "Bad sequence of commands", which doesn't make any sense, since a "HELO" command is the first message to be sent to the server. Can you post the code you are using? I can't see a msgsend class in that link you posted.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Friend,
But i'm not using tht POP3 thing,i was just asking you guys if that was an option to solve this,anyways here's the whole code frm the sun site,see if you can help me.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Thanks Friend,
But i'm not using tht POP3 thing


Ah, but you are. All that stuff you are doing with Folders and Stores is for either the IMAP or POP3 protocols. What those classes are there for is so you can access and manipulate a "folder" on the server: in the context of POP3 there is only one folder, which is the connected user's INBOX. If you are sure you want to do this, make sure your POP3 server details and authentication credentials are correct. Personally, if you only want to send an email, I would ditch pretty much everthing after Transport.send(message).
[ March 31, 2005: Message edited by: Paul Sturrock ]
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul,
As of now i just want to send an email.So,I got the second example from sun i.e


And I get the following error now:

Paul ,can u help me accomplish this thing now.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, I'll give it a shot.

OK you need to be sure that the SMTP server you are using (smtp.broadband.rogers.com) exists and is one you can access independent of Java Mail. So try telneting to it, or configure your current mail client program to connect to it and see if it can. If you can't do either of those things, contact the admin of smtp.broadband.rogers.com and ask if you can connect to it.

Also, be aware that if there is a proxy server between you and the server JavaMail will not be able to connect, unless it is configured to relay SMTP. Which 99% of them are not.

What I'd recommend you do is google for a product called "dumbster" which lets you test JavaMail code independent of any server configuration issuse. Verify you can create a program which will send SMTP messages correctly with this, then you can tackle the inevitable configuration issues you'll get trying to connect to an SMTP server.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
I tried a few things and this is what i got.
First,My outlook express worked fine with smtp server.I am able to send and recieve messages.
Second,when i telnet,i get this:

Finally,I downloaded "dumbster",but i dont know how to use it.Do i need to have the war file in my classpath,but how to start the server and what url to provide..i dont know.Can you please help me with this.I really appreciate your help.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can connect to your server via method other than you program which is encoraging. This proves you have the correct SMTP server details and you can connect. However, you may still be behind a proxy server. Are you?

You should write Connection and Transport handlers (see the JavaMail docs) so you can properly log Connection and Transport events. Also, run JavaMail in debug mode, so you can see all the SMTP messages it generates (JavaMail docs again, if you don't know how to do this).

Dumbster - you use it in conjuntion with your unit tests. So the thing which runs it is your unit test class (its just a seperate thread pretending to be an SMTP server). The example on their site shows how to use it with a JUnit TestCase. If you don't know what JUnit is, now might be the time to learn. Also its worth reading the linked JavaWorld article.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul,
I really really appreciate your help.Atlast with your guidance,i was able to make it work.Both the "smtp" and "pop3" are working perfectly.First I downloaded a free smtp server called PostCast and tried sending message through it and i was successful.Then I went through the java doc,as you said and I tried to confgure my program accordingly with my isp's smtp server,and everything went off smoothly.And about JUnit,as you said i dont know what it is....but i too feel this is the rite time to go thru it.Anyways thanks...thanks...thanks.
Here's my complete running code both for smtp and pop3,for anyone in future reference:


For pop3,just make these changes in main:

Hope it helps.Cheers!!
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
One last question to ask....like i am trying to make an email tool,which should work like the hotmail or yahoo email thing.And then I would like to encapsulate this tool into a website,so that others can use it and i would like it to be portable,so that i can include it into any website.I need a good user interface for this.Can you suggest me,should i use JSP and Servlets for this,but i read somewhere using servlets with javamail could be problematic.Would love to hear your suggestions.
Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to hear you got this working. Glad I could help.

Servlets/JSP's should be fine with JavaMail. Be aware though that unless you are the administrator for whichever SMTP server you intend to use you will probably be in breach of some "accepted use" policy opening up your account people this way.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having similar problems....

I think the friend from above (Jas) was trying to send emails through the smtp server of his ISP (rogers.com). Am I correct? That's why he used as the source address his email address from that ISP (xyz@rogers.com)

I have a bit different situation:
I am running my java code on one remote server (lets call it provider_1.com), they provide me with an smtp server access but they limit the amount of emails i can send per day, so I cannot really use it for my current project.

You see, there should be a lot of email traffic in this java app.

But I have another remote server (lets call it provider_2.com), they also provide me with an smtp server access and they do NOT limit the amount of emails i can send per day (wonderful!), but they do not suppport java.

What I am trying to do is to make the java code running on domain_1, call the smtp of domain_2 (instead of call the localhost smtp server, i.e. the smtp of domain_1).

I have found in sun's forums a piece of code to do that, how ever it does not work for me. I simply get no email to the destination mail box, I get no exceptions too...

I have asked the owners of the provider_2.com if I need some username+password to access the smtp they gave me. They said no...

Well this is very strange for me. If there is really no need for rusername+password to access (from external domains) the smtp I purchased from them, what could prevent programmers from other domains from using that smpt (on provider_2.com) for spamming the whole world.

Please help me to understand how can I make this code working for me. Or better yet, how can I make the remote smtp_2 responding when I call it from domain_1.com

Here is the code:



(Marilyn edited long line)
[ April 04, 2005: Message edited by: Marilyn de Queiroz ]
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read through the replies posted above. Thgere are plently of things to try listed.

Pay particular attention to:
  • setting JavaMail to use debug mode, so you can see the actual SMTP traffic
  • writing Connection and Transport Handlers which log events properly
  • Find out if you use a proxy.



  • Also, why do you call:

    when you are trying to send a message?
     
    Joseph Sweet
    Ranch Hand
    Posts: 327
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the response.

    I read the above mentioned replies and tried to do what I can.

    maybe you could try helping with the following questions

    0. lots of the code discussed above looks like I have access to the System.out, i.e. someone is running this code on their local machine. I am trying to run the code on a remote server. how can i redirect all that output to some txt file on the tomcat domain_1.com

    1. How can I telnet the smtp.domain_2.com from the domain_1.com machine? i know how to telnet servers from the dos prompt on my machine. how can i do that from a remote machine.

    2. I am sure there are some proxy servers between these two domains as they are in diferrent continents.


    3. I added
    session.setDebug(true);
    to my code, it says debug messages will go to System.out stream. I do not run the code on my local machine, so i cannot see what it prints on there dos window. hoe can I tell in the code to redirect the debug message to some log file on the remote server.

    4. how do I write "Connection and Transport Handlers which log events properly". it is not discussed above.

    5. Why I call message.saveChanges();
    I dont know, it was in the code I took from the sun's site. the remark says not to forget to do that. funny ha.
    Doc says: "Updates the appropriate header fields of this message to be consistent with the message's contents."
    I am not really sure why the message object has header fields and what they are for. is it something like http headers.

    6. it is very intersting for me to know if they really knew what they are talking about when they told me the smtp.domain_2.com does not require username+password to use it from remote servers. it seems impossible for me to find this situation on a commercial server.
    [ April 04, 2005: Message edited by: Joseph Sweet ]
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    0. lots of the code discussed above looks like I have access to the System.out, i.e. someone is running this code on their local machine. I am trying to run the code on a remote server. how can i redirect all that output to some txt file on the tomcat domain_1.com


    Tomcat can be configured to log to a file or files. It does this by default. And the logs are kept in the Tomcat "logs" directory usually. Generally you should not use System.out for any debug/logging statements. There are logging frameworks you should use instead (log4j, or even better Jakarta commons logging). However if you do use System.out the out put should go to the same log file.


    1. How can I telnet the smtp.domain_2.com from domain_1.com machine? i know how to telnet servers from the dos prompt on my machine. how can i do that from a remote machine.


    You could try running telnet in an existsin telnet session. No idea if it works.


    2. I am sure there are some proxy servers between the these two domains as they are in diferrent continents.


    Well, proxy server don't usually relay SMTP traffic. So if there are any, this is probably impossible.


    3. I added
    session.setDebug(true);
    to my code, it says debug messages will go to System.out stream. I do not run the code on my local machine, so i cannot see what it prints on there dos window. hoe can I tell in the code to redirect the debug message to some log file on the remote server.


    See above.


    4. how do I write "Connection and Transport Handlers which log events properly". it is not discussed above.


    It is discussed in the JavaMail documentation though. That should always be your first point of referencefor all JavaMail questions.


    5. Why I call message.saveChanges();
    I dont know, it was in the code I took from the sun's site. the remark says not to forget to do that. funny ha.
    Doc says: "Updates the appropriate header fields of this message to be consistent with the message's contents."
    I am not really sure why the message object has header fields and what they are for. is it something like http headers.


    My advice is don't call methods if you don't know what they do. Difficult I know. In this instance it is an unecessary call, so I'd delete that line.


    6. it is very intersting for me to know if they really knew what they are talking about when they told me the smtp.domain_2.com does not require username+password to use it from remote servers. it seems impossible for me to find this situation on a commercial server.


    Have you tried connecting to the SMTP server form your own machine without authentication? That will tell you whether authentication is required at all.


    Now a question from me: Why are you developing on a remote machine instead of your local machine?
     
    Joseph Sweet
    Ranch Hand
    Posts: 327
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the response.

    1. the tomcat logs directory is empty. why so if you say tomcat by default logs to a file in the logs directory.

    2. existsing telnet session. I know nothing about that.

    3. I can telnet the smtp.domain_2.com server. I get
    220 mail.some_company.com ESMTP

    4. I guess there are proxy servers. Is there anyway I can send emails from java code running on the remote server domina_1.com without using their local host smtp server smtp.domain_1.com ???
    They provide me with their own smtp server ("localhost") but they limit the traffic. not good enough for this app.
    can i install my own smtp server on this domain.

    5. an answer to you question: I develop on my local machine but the app is supposed to run on a remote machine (a commercial server). the app lets clients upload files to the server and I do not want that head ache on my local machine.

    In the code I run on my local tomcat I use either: my ISP's smtp, or I use the JES server I have installed on my local machine.

    I am not sure the remote domain_1.com admin will let me do that.

    Also, I am not sure the emails that are being sent out of the JES or JAMES (whatever I will install there) will not eventually come to their localhost smtp they have provided me, which will make those admins very upset with me.
    [ April 04, 2005: Message edited by: Joseph Sweet ]
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    1. the tomcat logs directory is empty. why so if you say tomcat by default logs to a file in the logs directory.


    Then the configuration has changed. Speak to whoever administers the server (if its not you) and find out how the logging is configured. If you cannot work out where the logs are, give up.


    2. existsing telnet session. I know nothing about that.


    I mean creating a telnet session to one machine and running telnet form that session. Like I say, I've no idea if this works.


    3. I can telnet the smtp.domain_2.com server. I get
    220 mail.some_company.com ESMTP


    That's encoraging. So it looks like you might be able to do the same from this other remote machine.


    4. I guess there are proxy servers. Is there anyway I can send emails from java code running on the remote server domina_1.com without using their local host smtp server smtp.domain_1.com ???


    Absolutely. Just specify another SMTP server.


    can i install my own smtp server on this domain.


    I have no idea. You would have to speak to whoever administers the machine to find this out.


    5. an answer to you question: I develop on my local machine but the app is supposed to run on a remote machine (a commercial server). the app lets clients upload files to the server and I do not want that head ache on my local machine.


    Good. I was worried you were developing remotely, which is horribly difficult. My advice is write and test the app. fully on your local machine. Once its passing 100% of unit tests then upload it and you can get into a dialogue with the admin peaople to try and fix the configuration errors.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic