Welcome to Dream.In.Code
Become a Java Expert!

Join 150,105 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,916 people online right now. Registration is fast and FREE... Join Now!




How to use Java Mail API?

2 Pages V  1 2 >  
Reply to this topicStart new topic

How to use Java Mail API?

fsloke
19 Jun, 2008 - 08:10 PM
Post #1

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
I new in this JAVA MAIL

May I know have any tutorial for this?

Thank you
User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Use Java Mail API?
19 Jun, 2008 - 08:26 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(fsloke @ 19 Jun, 2008 - 09:10 PM) *

I new in this JAVA MAIL

May I know have any tutorial for this?

Thank you


fsloke usually you are not like this ....

Google java mail

should give you a lot of interesting links
User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Java Mail API?
19 Jun, 2008 - 10:16 PM
Post #3

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
ok ok pbl

I try first then If got error I will post it out...

Thank for the motivation. Cheer!!!
User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Java Mail API?
20 Jun, 2008 - 10:14 PM
Post #4

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
I follow step by step in the JavaWorld tutorial

JavaMail quick start
http://www.javaworld.com/jw-10-2001/jw-1026-javamail.html

Now i do not have the SMTP server.
Can I test with my Yahoo/hotmail account?
If yes, what should I put for incoming mail and outgoing mail?
and what type of my mail server?

Thanks
User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Use Java Mail API?
21 Jun, 2008 - 08:25 AM
Post #5

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(fsloke @ 20 Jun, 2008 - 11:14 PM) *


Now i do not have the SMTP server.
Can I test with my Yahoo/hotmail account?
If yes, what should I put for incoming mail and outgoing mail?
and what type of my mail server?

Thanks


If you are connected to the internet, your service provider must have supplied you with an SMTP server.

User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Java Mail API?
21 Jun, 2008 - 08:53 AM
Post #6

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
I have try to run the demo code provided by the JAVAmail

I use gmail for testing

The smtp server for gmail is smtp.gmail.com

after compile theSimpleSender, the I run

java SimpleSender smtp.gmail.com henryJack85@gmail.com fsloke@yahoo.com "Hello" "Just to say Hello."

But it didn't work.... I stuck here...

what should i change for this command:

java com.lotontech.mail.SimpleSender smtp.myISP.net bill@lotontech.com ben@lotontech.com "Hello" "Just to say Hello."


User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Use Java Mail API?
21 Jun, 2008 - 09:22 AM
Post #7

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(fsloke @ 21 Jun, 2008 - 09:53 AM) *


what should i change for this command:

java com.lotontech.mail.SimpleSender smtp.myISP.net bill@lotontech.com ben@lotontech.com "Hello" "Just to say Hello."


You see in the example: "smt.myISP.net"
So it means to use for smtp: myISP so YOUR Internet Service Provider smtp.

I'll try to explain to you short.

OK you have understood that POP server is to receive/retreive mail. SMTP server is to send mail.

OK my my mail account in Outlook is set up with:
- my ISP POP server which is pop.sympatico.ca.
- my ISP SMTP server which is smtp.sympatico.ca

Now as long as I stay connected from home on my labtop I can send and receice mail.

Now most mail system provider have no problem to let users pick up their mail all over the world.
So I can travel all over the world and pickup my mail from pop.sympatico.ca.

Now most mail system provider do not allow user to connect to their SMTP server if they are not physically connected to their network.
Why ? Because they don't have problem for you to pickup your mail but they don't wamt spamer to use their SMTP server to send millions of spams over the net.
If I want to send millions of spams from home, they can always identify me and tell me to stop or charge me for the service.

So that means that if I go you your place and I plug my laptop into your internet connection I can receive mail from pop.sympatico.ca no problem but smtp.sympatico.ca won't be accessible because I am not physically connected to there network. So in my Outlook mail account I'll have to change my SMTP server to your SMTP server no problem.

Another solution is to buy ($) the service from SMTP provider like www.smtp.com. For a few $ a month they will let you connect to their SMTP server from everywhere in the world. So in January, when I take my 2 weeks vacation in the Carabean I rent their services for a month for about $ 20.00. Then I change my SMTP server in Outlook to www.smtp.com and I can then use my laptop for mail from my hotel room.

Hope this is clearer. Again your ISP must have provided you with an SMTP server.
User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Java Mail API?
21 Jun, 2008 - 05:53 PM
Post #8

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
Thank pbl for the explanation. It quite easy to understood.

Here I have 2 options to go

Option One : Send
============
So, now in order to test the send code. I have to setup a smtp server is it?

Do you have any link or tutorial teach us how to setup a smtp server? (that workable)

Option Two : Receive
==============
From your explanation, mean that I can check/receive mail from my service provider (through POP). So the read mail code can work in my PC that doesn't have smtp server but it can use the service provider smtp server?

Thank
User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Use Java Mail API?
21 Jun, 2008 - 07:39 PM
Post #9

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(fsloke @ 21 Jun, 2008 - 06:53 PM) *

Thank pbl for the explanation. It quite easy to understood.

Here I have 2 options to go

Option One : Send
============
So, now in order to test the send code. I have to setup a smtp server is it?

Do you have any link or tutorial teach us how to setup a smtp server? (that workable)

Option Two : Receive
==============
From your explanation, mean that I can check/receive mail from my service provider (through POP). So the read mail code can work in my PC that doesn't have smtp server but it can use the service provider smtp server?

Thank


I would say....
try the read first... if the read works you prove your achievment

For the write... this is another question..... found your ISP smtp server or register/pay subscibtion to one on the Internet
User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Java Mail API?
21 Jun, 2008 - 08:02 PM
Post #10

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
QUOTE
try the read first... if the read works you prove your achievement


Can I just create a mail through Outlook Express, then read the header, Subject and contain of the mail using JAVAMail?

I create a simple mail already,
Just click on New Message button. Then after finish input all the field, click on Save as from File Menu.

The extension available are .eml, .txt, .html

This is the sample of Hi.eml. It look like this...

CODE

From: "asdf" <kklee0074@yahoo.com>
To: <fsloke@yahoo.com>
Subject: Hi
Date: Sun, 22 Jun 2008 11:55:53 +0800
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----=_NextPart_000_0023_01C8D45E.F4605F30"
X-Priority: 3
X-MSMail-Priority: Normal
X-Unsent: 1
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198

This is a multi-part message in MIME format.

------=_NextPart_000_0023_01C8D45E.F4605F30
Content-Type: text/plain;
    charset="gb2312"
Content-Transfer-Encoding: quoted-printable

Testing 123
------=_NextPart_000_0023_01C8D45E.F4605F30
Content-Type: text/html;
    charset="gb2312"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dgb2312">
<META content=3D"MSHTML 6.00.2900.3243" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Testing 123</FONT></DIV></BODY></HTML>

------=_NextPart_000_0023_01C8D45E.F4605F30--


Then it also can save as Hi.txt file

CODE

From: "asdf" <kklee0074@yahoo.com>
To: <fsloke@yahoo.com>
Subject: Hi
Date: Sunday, June 22, 2008 11:55 AM

Testing 123


It also can save as Hi.htm

CODE

<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=gb2312">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3243" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Testing 123</FONT></DIV></BODY></HTML>


The problem is what JavaMail can support. Which file that I should read?

My target : Using JAVAMail to get the Subject field and the message contain --> prompt out as message box.

Thanks
User is offlineProfile CardPM
+Quote Post

fsloke
RE: How To Use Java Mail API?
23 Jun, 2008 - 04:40 AM
Post #11

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
I successful send my mail using the JAVAWorld code

I having problem with read the mail...

[ The parameter I fixed to hard code ]

The output:
=================================
C:\lab>java -classpath mail.jar;. SimpleReceiver
Number of Message:0
Name:
Message: 0
=================================

The output mean that no Message in my indox.... sad.gif

But my INBOX have a lot of mail.... What happen?
User is offlineProfile CardPM
+Quote Post

lordms12
RE: How To Use Java Mail API?
23 Jun, 2008 - 06:43 AM
Post #12

D.I.C Regular
Group Icon

Joined: 16 Feb, 2008
Posts: 322



Thanked: 17 times
Dream Kudos: 225
My Contributions
QUOTE(fsloke @ 23 Jun, 2008 - 05:40 AM) *
I having problem with read the mail...

If you are using gmail for testing check your mail setting and get sure that POP is enabled.

This post has been edited by lordms12: 23 Jun, 2008 - 06:44 AM
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:56AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month