Forums Register Login
JavaMail step-by-step
Hello! Can I be forwarded to a page that describes in detail
what steps to take to write a simple java mail-client?
I write one but it throws exceptions.
I need to know if I have to install smth additional.
Say I have a mail server running on another host with IP .......
I have an email account.
And all I want to do is to send a simple text(for beginning)into my
inbox folder.
If you could provide a simple example yourself with
protocol, url, username and password specified it would be great.
Thank you!
You'll probably get more replies if you post what you tried and what exceptions you got.
java almanachas a simple program to send email
You may try the example codes in the liks below:

Sending e-mail using JavaMail API

How to send an email with a file attachment
[ December 28, 2005: Message edited by: Casper Maxwell ]
Good day!
I give my thanks to you.
Everything worked fine.

I have another question.
The code whick worked is this

import javax.mail.*;
import javax.mail.internet.*;

public class simplemail {
public static void send(String smtpHost, int smtpPort,
String from, String to,
String subject, String content) {


java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", ""+smtpPort);
Session session = Session.getDefaultInstance(props, null);
//Store store = session.getStore();
//Folder folder = store.getFolder("INBOX");

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

}catch(Exception e){e.printStackTrace();}

public static void main(String[] args) throws Exception {

send("myhostname", 25, "Fedai@bankrespublika.az", "fedai@bankrespublika.az",
"Driving away", "I'm firing you");

When I uncomment the commented part it throws the exception

javax.mail.NoSuchProviderException: Invalid protocol: null
at javax.mail.Session.getProvider(Session.java:265)
at javax.mail.Session.getStore(Session.java:363)
at javax.mail.Session.getStore(Session.java:343)
at javax.mail.Session.getStore(Session.java:329)
at simplemail.send(simplemail.java:17)
at simplemail.main(simplemail.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)

Where in this code do I have to configure protocol?
Thank you!
My Transport object is normaly like this:

This isnt what I want!
I want to retrieve a specified message for the INBOX folder.
That's it.
How will this

Transport transport = session.getTransport("smtp");
transport.connect(hostname, username, password);

provide that?
I used this.

Store store = session.getStore("smtp");
Folder folder = store.getFolder("INBOX");
Message[] message = folder.getMessages();

Although my INBOX folder contains a lot of messages it throws
the ArrayIndexOutOfBoundsException exception. (0>=0)

As I understand the getMessages method retrieves the messages from the INBOX folder and puts them into the message array. If my INBOX folder isnt empty then it must contain smth.
But it doesnt work.
What is the matter?
OK, you are trying to do two thing at once - send and recive mail at the same time.

Try read this
Using the JavaMail API
Introducing the JavaMail API

[ December 29, 2005: Message edited by: Rene Larsen ]
Thank you very much!
It worked!
And another question.
I am not familiar with JMS. I've just read couple of things on it.
If a create a java application on one machine and another one on another
machine. Can JMS be used here to make them communicate?
If yes forward me to a page describing how this can be done, please?
Thank you!
The short answer to JMS is - YES

It depends on the use of the JMS queue � will the queue be located in a database e.g. Oracle, DB2� � then the answer is always YES � but will the queues be file based, then both applications must share the files location and a lot of other things � the answer is MAYBE.

This JMS Tutorial will give you the basic: Java Message Service Tutorial

Maybe you should read about RMI (Remote Method Invocation) also.

You will get a lot of information by doing a search on e.g. google.

[ December 30, 2005: Message edited by: Rene Larsen ]
I have no more questions.
If you want you can close the topic.
Thank you!

This thread has been viewed 4202 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 23, 2018 21:06:24.