*
The moose likes EJB and other Java EE Technologies and the fly likes help java.net Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "help java.net Exception" Watch "help java.net Exception" New topic
Author

help java.net Exception

blackcarlos Dibia
Greenhorn

Joined: Mar 30, 2005
Posts: 21
pls this is my javamail codes
import java.io.*;
import javax.mail.*;
import java.util.Properties;
import javax.mail.internet.*;
import javax.swing.*;
import java.awt.*;

public class MailOption {
public MailOption()throws Exception {
/*Display the menu options*/
System.out.println("Select Option");
System.out.println("1. Enter SEND to send mail");
System.out.println("2. Enter READ to read mail");
System.out.println("3. Enter QUIT to exit");
/*Accept the option selected by the user */
java.io.BufferedReader bro = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
String s = bro.readLine();
if("SEND".equals(s)) {
SendMail sm=new SendMail();
}
else if("READ".equals(s)) {
ReadMessage rm=new ReadMessage();
}
else if("QUIT".equals(s)) {
System.exit(0);
}
else {
System.out.println("Wrong option selected");
System.exit(0);
}
}
}
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.swing.*;
import java.awt.*;

/* Code the JavaMail app to retrieve mails */
class ReadMessage
{
public ReadMessage() throws Exception
{
/* Accept user input for the IP add of the mail server */
System.out.println("Enter the IP address of the mail server ");
BufferedReader hostAdd = new BufferedReader(new InputStreamReader(System.in));
/* Declare variable to store the IP add of the server */
String hostAddress = hostAdd.readLine();

System.out.println("Enter the Username");
BufferedReader uName = new BufferedReader(new InputStreamReader(System.in));
String userName = uName.readLine();

System.out.println("Enter the Password");
BufferedReader uPass = new BufferedReader(new InputStreamReader(System.in));
String userPass = uPass.readLine();

/* Create an instance of the Properties class */
Properties prop = new Properties();
/* Create a mail session */
Session mailSession = Session.getDefaultInstance(prop,null);
/* Create a store object */
Store mailStore = mailSession.getStore("imap");
/* Connect to the mail store on the mail server */
mailStore.connect(hostAddress,userName,userPass);
/* Open the INBOX folder on the mail server */
Folder mailFolder = mailStore.getFolder("INBOX");
mailFolder.open(Folder.READ_ONLY);
BufferedReader mailReader = new BufferedReader(new InputStreamReader(System.in));
/* Declare an array to store the messages in the mail server */
Message msg[] = mailFolder.getMessages();
/* Retrieve mails from the mail server */
for(int i = 0,j = msg.length; i<j ;i++)
{
/* Print the retrieved message */
System.out.println(i + ":" +msg[i].getFrom() [i] + "\t" + msg[i].getSubject());
System.out.println(" Do you wish to read more messages ?[Enter YES to read/QUIT to end]");

String msgLine = mailReader.readLine();
if("YES".equals(msgLine))
{
/* Display the content of the mail message */
System.out.println(msg[i].getContent());
}
else if("QUIT".equals(msgLine))
{
break;
}
}
/* Close the mail folder and mail store objects */
mailFolder.close(false);
mailStore.close();
System.out.println("Do you wish to perform mail-related operations again ?Enter YES to continue, QUIT to exit ");

String msgLine = mailReader.readLine();
if("YES".equals(msgLine))
{
MailOption mailop = new MailOption();
}
else if("QUIT".equals(msgLine))
{
System.exit(0);
}
}
}

import java.io.*;
import javax.mail.*;
import java.util.Properties;
import javax.mail.internet.*;
import javax.swing.*;
import java.awt.*;

class SendMail
{
public SendMail ()throws Exception
{
/* Accept the user input for the IP address of mail server */
System.out.println("Enter the IP address of the mail server");
BufferedReader hAdd = new BufferedReader(new InputStreamReader(System.in));
String hAddress = hAdd.readLine();


/* Accept the user input for the address of mail sender */
System.out.println("Enter the address of the mail sender");
BufferedReader sAdd = new BufferedReader(new InputStreamReader(System.in));
String sAddress = sAdd.readLine();

/* Accept the user input for the address of mail recipient */
System.out.println("Enter the IP address of the mail recipient");
BufferedReader rAdd = new BufferedReader(new InputStreamReader(System.in));
String rAddress = rAdd.readLine();

/* Create an instance of the Properties class */
Properties prop = System.getProperties();
prop.put("mail.smtp.host", hAddress);

/* Create a mail session */
Session mailSession = Session.getDefaultInstance(prop, null);

/* Create a message object */
MimeMessage msg = new MimeMessage(mailSession);

/* Specify the addresses of the mail sender and mail recipient */
msg.setFrom(new InternetAddress(sAddress));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(rAddress));

/* Set the mail subject */

msg.setSubject("Sending mail");

/*Set the mail content */

msg.setText("Hey McCoy how far?");

/* Send the mail object to the recipient */
Transport.send(msg);
System.out.println("Mail Sent");
System.out.println("Do you wish to continue ? Enter YES to contiue, QUIT to exit");
BufferedReader opt = new BufferedReader(new InputStreamReader(System.in));
String mailopt = opt.readLine();

if("YES".equals(mailopt))
{
MailOption mo = new MailOption();
}
else if("QUIT".equals(mailopt))
{
System.exit(0);
}
}
}

import java.io.*;
import javax.mail.*;
import java.util.Properties;
import javax.mail.internet.*;
import javax.swing.*;
import java.awt.*;


public class UserAuthentication {
public static void main(String [] east) throws Exception {
System.out.println("Please Enter Your User Name");
/* Initialise the reader class to accept user input */
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
String s = br.readLine();
if (s.equals("sanchez") || s.equals("carlito") || s.equals("carlos"))
{
MailOption mo = new MailOption();
}
else {
System.out.println("Sorry, user name is not authentic");
System.exit(1);
}
}

}

all codes compile but when I run the UserAuthentication it reaches a point and throws java.net Exception Connection refused:connect
help needed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help java.net Exception
 
Similar Threads
Mail Retieval
Java mail
How To Turn On the IIS SMTP Server?
Upload attachments by email
Java mail