File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes JavaMail API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail API" Watch "JavaMail API" New topic
Author

JavaMail API

Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Hi everyone,
I have a little problem because of my "greeness" in JavaMAil API. What is the my Server host? I mean how can I obtain such an information? I believe it's quite stupid question, but.... Thanks in advance...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18881
    
    8

You are asking what is the name of your e-mail server?

If it's the e-mail server for the company you work for, find the administrator and ask them. Yes, really. Just ask.

If it's a web server like Gmail, then there should be some documentation on how to connect to the server using mail programs. For example if you configured Microsoft Outlook to connect to your web mail, you will already have put the name of your e-mail server into its configuration somewhere.

If this doesn't help, then post again with more details about your specific situation.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Well, I just newbie in Java Mail. I started reading Sun's online training about this topic, and stuck with and exercise of creating simple mail sending... I just do not know what is my SMTP Server. How can I find out this, or maybe you can redirect me at some source where I would find this and further explanation.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Alternatively, if it is for own convenience only, then you need to install a mail server yourself. For example Apache James.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Thank you. could you maybe reference me to some written source (book, documentation...) about JavaMAil Api?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
The http://faq.javaranch.com/java/JavaEnterpriseEditionFaq page points to a number of good resources regarding JavaMail, particularly an extensive tutorial on java.sun.com that has many code examples.


Ping & DNS - my free Android networking tools app
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Ok. Well I've started on sun-s tutorial, but as I mentioned above, this is my first encounter to JavaMAil, so I find it a little bit not understandable (Hahh, I stried to create a simpel mail application, just to send a "Hello", but I do not know the host for sending. Can you give me a glimpse on this host-issue?). thanks...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
To send and retrieve mails, you need a mail (SMTP) server.
To interact with a mail server using Java, you use the JavaMail API.

JavaMail is not a mail server and it look like that you thought that it was somehow.
At least, JavaMail itself already provides an excellent FAQ: http://java.sun.com/products/javamail/FAQ.html

If you don't want to install and run a mailserver at your own PC using for example Apache James (or others), then you can also use the mailserver of for example your own ISP, or your company or webbased others like Gmail. But you need to consult their documentation or support team to get the connection details, such as the SMTP host name, port number and so on which you can use in your JavaMail configuration settings.

Edit: I see in your topic history that you are less or more familiar with JSP/Servlet.
You can compare JSP/Servlet API less or more with JavaMail API.
With JSP/Servlet (and HTML) you can use HTTP to transfer data between client (webbrowser) and server (Tomcat or so).
With JavaMail you can use SMTP to transfer data between client (mailprogram) and server (James or so).

Do you got it now?
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Yes you have, that was I need - an outline of mailing - . Thanks a lot.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
One more thing. It seams to me that I, let say, need to have a two servers simultaneously to work, in orde to provide some web application which use JavaMail. I guess that is not pretty good solution. Does J2EE oriented containers have this ability to support both purpose (purpose of Tomcat and James) ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
Well, James is a Java application, so if you dig into its code it should be easy to find its main class, and embed that into your web application (maybe start it in a ServletContextListener). Thus you'd have only a single server.

But the drawback is that if you need to take down one of the servers for any reason (or it goes down on its own), then the other will be down, too.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
So what is solution - to embed those part of James code into our web application, or some containers in production, already have this feature integrated within?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
If I didn't want to have a second server running, I'd probably embed James into a separate web app. That way at least I could start/stop both applications independently of each other.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Ok thanks. Only what I need to do is to integrate James into code (sound pretty easy :-))) hehehe, I could imagine ) For now I wanted just an outlined to be informed about JavaMail and so on.. I believe in a month I'll start grainer study about this topic. Thanks once again of valuable references!
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Hi, a while ago here we were discussed about JavMail. It's considered that I need James server to perform mail sending. I'm now going on j2ee AS, and I found that there is embedded JavaMail API. Is it only API embedded with libraries (so I do not need to download JavaMail API's, and set jar's into classpath), or there is also and James aembedded, or I still need to integrate James in my application?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

It does not include James, so you will need to download and integrate that separately.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Hi. I have a problem during mail sending. I use mu ISP smtp. I can read mail from my code (read from my inbox of my ISP), but I cannot perform mail sending. This is the code for sending :



When I try to read messages from ISP my , I use my pop3.gromnet.netprovider, and messages from ISP (sent and received) were being retrieved. However, when I try to send message, this is the message I get :


So, where do I wrong???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
There doesn't seem to be any authentication code; how are you trying to set the password?
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Of course but I'm newbie in JavaMail. I've just figure out googling that this part of code is necessary :


Could you advice me, refer me, to potential obstacles I'll probably face in JavaMail API? I know this is some general question, but just to prepare me for some inevitable exceptions/errors which may occurs in this API? I'm gonna study it just to understand the base, so I could implement James in my application... Thanks everyone on support..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
The best advice I can give is to work through the tutorial I mentioned earlier. It covers all the basics, and quite a bit more. You might also check out the other JavaMail links on that FAQ page.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

The error message seems to indicate that the ISP's mail server does not allow the relaying. Can you send messages from that address from a "regular" email client such as Outlook (Express) or Thunderbird?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18881
    
    8

Rob Prime wrote:The error message seems to indicate that the ISP's mail server does not allow the relaying.


Well, of course. Any responsible ISP wouldn't allow its SMTP server to be used to send messages claiming to be from a Gmail account which it knows nothing about. For that to work, the "from" address would have to be an address in the ISP's own domain, which appears to be "gromnet.net". And even then the ISP still might require authentication.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Not necessarily. My ISP (and my previous one too) allows me to send emails from my own domain which the ISP knows nothing about, and probably would allow GMail, HotMail and the likes. They simply check if I'm connected to their network, if I am I can use their mail server with virtually any email address. At present I use my ISP's mail address, 4 accounts of my own domain and another account, and all allow sending from them through the same ISP.

Of course this doesn't mean that all ISPs work like that, that's why I suggested the test with Outlook (Express) or Thunderbird. If that has the same problem then the ISP is definitely the issue.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Well, as I said, it was about authentication issue, and I solve it. And yeas, I could sent an email using outlook, but I didn't perform authentication process in my code, which I should (the ISP explicitly denote that authentication is required, which also I must perform in my outlook express). When I refine my code, everything is just fine. But there is another thing:
How can I get all messages from my ISP mailbox? I can retrieve by code, only the messages stored in the INBOX folder, no matter if use 'pop3' or 'imap' (but I found out that pop3 only can manipulate with INBOX folder. So hoe can I access set folder? I use 'imap' provider and try to specify


and get an exception :


However, I've looked at my webmail place on my ISP and find that folder for sent messages are named - 'INBOX Sent'. So I try to rename :


and I get:


So, how can I approach to other folders?
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Hi. I have a problem when I want to retrieve a disposition of message.
Previously I created a message, add attachment to is, and invoke :
The message successfully goes into my INBOX. But when I try to retrieve a messages attributes like in this code

It appears that message.getDisposition() returns null. Why is that???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
Slobodan,
please start new topics for questions that are unrelated to the original problem. It gets hard to follow what's going on if the subjects veers all over the place.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaMail API