"that domain isn't allowed to be relayed thru this MTA " : Problem and fix

I am using Java mail to send emails out at work through my web email account.

Sometimes it works fine, but after a while, it gives me the following error :

javax.mail.SendFailedException: Invalid Addresses;

nested exception is:

com.sun.mail.smtp.SMTPAddressFailedException: 553 sorry, that domain isn't allowed to be relayed thru this MTA (#5.7.1)

at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196)

at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584)

I waited for a few days, and tried one more time, it worked again for a few emails, then it failed again. I went into my Thunderbird where I had this web account set up so I can both send and receive emails, I tried to send out an email, it worked, then I used my Java email program to send email from work through this web account, it works again. It seems Thunderbird can fix the problem for me. Does any one know how I can fix it in Java so I don't have to start Thunderbird and send an email to fix the error ?

Frank

[1064 byte] By [Ni_Mina] at [2007-11-27 9:02:25]
# 1
These FAQ entries probably apply: http://java.sun.com/products/javamail/FAQ.html#norelay http://java.sun.com/products/javamail/FAQ.html#checkpop3firstYou're probably doing the latter, which causes the former to work.
bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

In the same day my Java program was at first able to send emails, then it failed because of those errors, after I ran Thunderbird it succeed again. So why did it failed after a few successful emails ? Someone did something on the server ?

The FAQ says : "make sure you connect to your POP3 Store on that mail server before sending mail".

How to do that in Java mail ? Any sample code ? Thanks.

Frank

Message was edited by:

Ni_Min

Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

> In the same day my Java program was at first able to

> send emails, then it failed because of those errors,

> after I ran Thunderbird it succeed again. So why did

> it failed after a few successful emails ? Someone did

> something on the server ?

Possibly your POP3 authentication only allows you to send

SMTP messages for a limited time.

> The FAQ says : "make sure you connect to your POP3

> Store on that mail server before sending mail".

>

> How to do that in Java mail ? Any sample code ?

Tons. Haven't you found the JavaMail sample code yet?

It's in the JavaMail download bundle.

Oh, and the FAQ answers this question. READ IT!!! Please?

bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
So that means I need to set it repeatedly ? Is there a way to find from the server how often I need to reset it ?Frank
Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

> So that means I need to set it repeatedly ?

Before every attempt to send a message, you need to have logged in

to your POP3 mailbox "recently".

> Is there a way to find from the server how often I need to reset it ?

No.

This is not a standard, this is a kludge used by some ISPs to prevent

people from using their mail servers to send spam.

bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Thanks. When you say : "you need to have logged in", does that mean I have to log in from a browser , an email client like Thunderbird, or can I be "logged in" from my Java email program (from my program make a connection and verify id/password ...), because my program doesn't keep cookies info like a browser does, would it make a difference ?

Frank

Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

You can do it using JavaMail by successfully connecting to your POP3

server and providing the correct username and password.

Remember, this whole conversation is based on assumptions of what

your ISP is doing. I have no idea who your ISP is or what they're actually

doing.

bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

That makes it more clear. But I still have another question, when I first encountered the problem, it was about "that domain isn't allowed to be relayed thru this MTA", since I was running my JavaMail program at work, and according to the FAQ, it's because the server at work is not allowing sending(relaying) emails from an outside address to another outside address, but after I ran Thunderbird, this problem went away, why ? It's still relaying from one outside address to another outside address, and the config of the server at work was still the same which didn't allow relaying, this part has nothing to do with the ISP where I have my web account, right ? Only after I was able to successfully relay, then how often I need to connect to the POP kicks in, is this a correct statement ?

Frank

Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
I have searched the sample programs in the demo dir, but haven't found any one that shows how to "connect to your POP3 Store on that mail server ", could you give me more pointers ? Thanks.Frank
Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10

You're confusing things here by using your ISP's mail server at work instead

of your work mail server.

Still, your ISP's mail server is probably imposing similar restrictions as your

work mail server. It doesn't want to allow just anyone to connect and send

mail to anywhere. That's how spam is sent. Most people control this by requiring

you to login to the SMTP server before it will let you send mail. Some people use

the hack of requiring you to login to the POP3 server first, and then it will allow

you to connect to the SMTP server without logging in and will allow you to send

mail.

You seem to be missing some basic understanding of JavaMail and what it

means to "connect to a mail server". Maybe you don't understand the difference

between a Store and a Transport. POP3 is a Store protocol. SMTP is a Transport

protocol.

The JavaMail demo directory is full of programs that should how to connect to

a mail server (Store) to read messages, the most useful of which is the msgshow.java

demo program. JavaMail doesn't require you to wire in knowledge of the Store

protocol. You can write a program that can connect to any type of Store, and then

tell it at runtime to use the "pop3" protocol. Looking at msgshow.java, if you pass

"pop3" as the protocol argument ("-T pop3"), it will connect to a POP3 mail server.

bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

Yes, you are right, although I've been doing JavaMail for a while, I still don't have a complete view of it, at least not before your last email. I've used the store to get emails, and the transport to send emails, I didn't know where the POP3 fits in. Thanks, now I know where to get some sample code.

In the following situation, which mail server am I using to actually send an email :

<1> I start my Java email program at work

<2> The program logs me into my ISP's web account with Id/Password

<3> I send an email with my email address from this ISP (or another of my address from Yahoo or Gmail) to someone (any address)

In this case, am I using both of my work and ISP email server, or just the ISP server ? Thanks !

Frank

Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12
The mail server that JavaMail talks to is exactly the one you configureit to talk to. Once that server gets the message, it might pass iton to other mail servers on its way to delivering the message to thedestination mailbox.
bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 13
So, in my situation above, it'll bypass the server at work and talk directly to the ISP server ?Frank
Ni_Mina at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 14
Yes.
bshannona at 2007-7-12 21:33:10 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 15
Plz show the code you are using ?
devoma at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 16
http://forum.java.sun.com/thread.jspa?threadID=5171220&start=30&tstart=0
Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 17

POP3 is a Store protocol, is it the only one being used now which works with JavaMail, and is it decided by the server ? If so, can I use another store protocol (if there is another one) to communicate with a server that uses POP3 ?

How to specify the full name in an email address, for example can I use the folllowing string as a valid email address ?

"Joe Smith"<joesmith@yahoo.com>

I see this format in Yahoo Mail.

Frank

Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 18
What is the "URLName" for in the Store object ? How do I get it ?Let's say I have a Gmail account and want to connect to it with JavaMail, what does this URLName look like ? Can it be null ?Frank
Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 19

> POP3 is a Store protocol, is it the only one being

> used now which works with JavaMail, and is it decided

> by the server ?

JavaMail also supports IMAP. Yes, the server decides which

protocols it will support.

> If so, can I use another store

> protocol (if there is another one) to communicate

> with a server that uses POP3 ?

Only if that server also supports the other protocol (e.g., IMAP).

> How to specify the full name in an email address, for

> example can I use the folllowing string as a valid

> email address ?

>

> "Joe Smith"<joesmith@yahoo.com>

See the InternetAddress class.

bshannona at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 20

> What is the "URLName" for in the Store object ? How

> do I get it ?

> Let's say I have a Gmail account and want to connect

> to it with JavaMail, what does this URLName look like

> ? Can it be null ?

The URLName is just a convenient way to specify all the

connection information in a single string. You can see the

information that's required by looking at the URLName

constructor. Some information is optional and will be

defaulted or can be supplied later (e.g., when connecting).

bshannona at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 21

I have a method listed below that tries to connect to a store :

public static void Login_To_Incoming_Server(String url,boolean Show_Alert,String host,String protocol,String port_number,String username,String password)

{

try

{

Properties props=System.getProperties();// Get a Properties object

Session session=Session.getInstance(props,null);// Get a Session object

session.setDebug(Debug);

Store store=null; // Get a Store object

if (url != null)// imap://username:password@mailstore.com|pop3://username:password@mailstore.com

{

// url==mailstore.com

store=session.getStore(new URLName(url.indexOf("://")==-1?protocol+"://"+username+":"+password+"@"+url:url));

if (Show_Alert)

store.addStoreListener(new StoreListener()

{

public void notification(StoreEvent e)

{

String s;

if (e.getMessageType()==StoreEvent.ALERT) s="ALERT: ";

else s="NOTICE: ";

Out(s+e.getMessage());

}

});

store.connect();

}

else

{

if (protocol != null) store=session.getStore(protocol);

else store=session.getStore();

if (host != null || username != null || password != null) store.connect(host,Integer.parseInt(port_number),username,password);

else store.connect();

}

}

catch (Exception e)

{

Out("url="+url+"\nhost="+host+"\nprotocol="+protocol+"\nport_number="+port_number+"\nusername="+username+"\npassword="+password);

e.printStackTrace();

}

}

But every time I use it, I got the following error :

===========================================================

javax.mail.AuthenticationFailedException: invalid user name or password.

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)

at javax.mail.Service.connect(Service.java:275)

or sometimes this :

javax.mail.AuthenticationFailedException: EOF on socket

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)

at javax.mail.Service.connect(Service.java:275)

===========================================================

I've checked the parameters, they work fine in Thunderbird, I can retrieve messages with them, but when I run this method with them, I got the above errors, is there anything wrong the the above function ?

Frank

Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 22

What's the protocol trace show?

Are there any special characters in the username or password that

might need to be escaped in a URL?

How you tried using the URLName constructor that takes the separate

parameters? It will do any needed quoting or escaping of parameters.

bshannona at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 23

How to use "protocol trace" ?

I tried to run both with and without url, when running with null url, the method should create a connection without using the null value, when I pass it a url like : mailstore.com it should create a complete one such as : pop3://username:password@mailstore.com

There was no special characters in them.

Frank

Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 24
> How to use "protocol trace" ?Frank, surely you've found the FAQ by now...
bshannona at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 25

Ok, here are the trace results for all three of my accounts :

==========================================================================================

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]

DEBUG POP3: connecting to host "mail.bellsouth.net", port 110, isSSL false

S: +OK POP3 server ready.

C: USER ***user_id***

S: +OK please send PASS command

C: PASS ***password***

S: -ERR invalid user name or password.

C: QUIT

S: +OK ***user_id*** POP3 server signing off.

........

javax.mail.AuthenticationFailedException: invalid user name or password.

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)

at javax.mail.Service.connect(Service.java:275)

==========================================================================================

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]

DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL false

S: EOF

......

javax.mail.AuthenticationFailedException: EOF on socket

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)

at javax.mail.Service.connect(Service.java:275)

==========================================================================================

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]

DEBUG POP3: connecting to host "mail.nmjava.com", port 110, isSSL false

S: +OK <28415.1183997013@mail54.opentransfer.com>

C: USER ***user_id***

S: +OK

C: PASS ***password***

S: -ERR authorization failed

C: QUIT

S: EOF

javax.mail.AuthenticationFailedException: authorization failed

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)

at javax.mail.Service.connect(Service.java:275)

==========================================================================================

I've set up all three in my ThunderBird to retrieve messages from the web accounts with the same user_ids and passwords that I used in my java method mentioned above, am I doing something wrong with the : Login_To_Incoming_Server(...) function ?

The gmail account needs SSL when sending messages.

Frank

Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 26
Without the details of your username and password, it's hard to say whatyou're doing wrong, but you can see clearly that the servers aren't acceptingyour username or password. Perhaps they all require that you connect usingSSL?
bshannona at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 27

The user_ids and passwords are just plain texts, something like : minfni

Only Gmail requires SSL to send, the other two uses non-SSL connection, I verified that from Thunderbird.

You can try my method with any of your web account, I bet it will fail even if they work with your other email clients, the Java method couldn't do it. Just don't know why, same user_ids/passwords.

Frank

Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 28

In fact, JavaMail works fine for me using many mail servers so clearly the

problem is something specific to the mail servers you're using or the

username and password information you're supplying.

You might try using a network protocol analyzer (e.g., tcpdump on Linux)

to monitor the protocol conversation between Thunderbird and your mail

server to see what's different between what Thunderbird sends and what

JavaMail sends.

You'll also see that the POP3 protocol is incredibly simple. You can try

emulating what JavaMail does and connect to your mail server using

the telnet command, e.g., "telnet mail.bellsouth.net 110" and then issue

the USER and PASS commands yourself.

bshannona at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 29

Thanks for the advice. But if it is so simple and it works, why the method I use (which is a simpler version of the sample code from JavaMail) doesn't work ? Can you see anything wrong with it ? It seems the only weak point is user_id/password info, but I've checked that, exactly the same and no special chars in them. Isn't it strange ?!

Frank

Ni_Mina at 2007-7-21 22:53:35 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 30

I can't tell you what you're doing wrong. But since it works for me and

millions of others, I'm sure it's something about what you're doing or

the environment you're doing it in.

You can believe that if there were something completely basic broken

such that no one anywhere ever could login to a POP3 server, that would

have been discovered a few years ago. :-)

bshannona at 2007-7-21 22:53:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 31

Feel good to hear that, you tried my method and it works for you ? Hard to believe, but I'll take your word for it. I couldn't find anything wrong with it either. I tried to login with both user_name and full email address as user_id.

I need to spend more time looking into it. For Gmail I know it requires SSL to send email, does that automatically mean I also need to use SSL when I get messages through its POP3 ?

Thanks

Frank

Ni_Mina at 2007-7-21 22:53:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 32

"Your method"? It works for me with any of the demo programs

included with JavaMail, as well as many other programs. If all

the demo programs fail for you, the problem is not with the code.

If the demo programs work, but your program fails, the problem is

with your code.

I believe Gmail requires SSL.

bshannona at 2007-7-21 22:53:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 33

Something strange happened. I modified the msgshow.java program, ran by itself and it logged into my ISP's POP3 server, but when I called it from another java program with the same parameters, it couldn't log in, the modified program looks like this :

===========================================================

import java.util.*;

import java.io.*;

import javax.mail.*;

import javax.mail.event.*;

import javax.mail.internet.*;

import javax.activation.*;

public class Show_Email_Message

{

static String protocol,host=null,user=null,password=null,mbox=null,url=null,indentStr="";

static int port=-1,attnum=1,msgnum=-1,level=0;

static boolean verbose=false,debug=false,showStructure=false,showMessage=false,showAlert=false,saveAttachments=false;

static InputStream msgStream=System.in;

/*

Yahoo Mail: Incoming Mail Server - pop.mail.yahoo.com (POP3 - port 110)

Outgoing Mail Server - smtp.mail.yahoo.com (SMPTP - port 25)

Google GMail : Incoming Mail Server - pop.gmail.com (POP3S SSL enabled, port 995)

Outgoing Mail Server - gmail.com (SMPTS SSL enabled, port 465)

*/

public static boolean Login_To_Incoming_Server(String protocol,String host,int port,String user,String password,boolean verbose,boolean debug,String url)

{

Out("protocol="+protocol);

Out("host="+host);

Out("port="+port);

Out("user="+user);

Out("password="+password);

Out("verbose="+verbose);

Out("debug="+debug);

Out("url="+url);

return Show_Message(protocol,host,port,user,password,verbose,debug,url,mbox,showStructure,saveAttachments,showMessage,showAlert,0);

}

public static boolean Show_Message(String protocol,String host,int port,String user,String password,boolean verbose,boolean debug,String url,String mbox,boolean showStructure,boolean saveAttachments,boolean showMessage,boolean showAlert,int msgnum)

{

try

{

Properties props=System.getProperties(); // Get a Properties object

Session session=Session.getInstance(props,null);// Get a Session object

session.setDebug(debug);

if (showMessage)

{

MimeMessage msg;

if (mbox != null) msg=new MimeMessage(session,new BufferedInputStream(new FileInputStream(mbox)));

else msg=new MimeMessage(session,msgStream);

dumpPart(msg);

return true;

}

Store store=null;// Get a Store object

if (url != null)

{

URLName urln=new URLName(url);

store=session.getStore(urln);

if (showAlert)

{

store.addStoreListener(new StoreListener()

{

public void notification(StoreEvent e)

{

String s;

if (e.getMessageType() == StoreEvent.ALERT) s="ALERT: ";

else s="NOTICE: ";

System.out.println(s + e.getMessage());

}

});

}

store.connect();

}

else

{

if (protocol != null) store=session.getStore(protocol);

else store=session.getStore();

// Connect

if (host != null || user != null || password != null) store.connect(host, port, user, password);

else store.connect();

}

if (msgnum==0) return true;

Folder folder=store.getDefaultFolder(); // Open the Folder

if (folder == null)

{

System.out.println("No default folder");

return false;

}

if (mbox == null) mbox="INBOX";

folder=folder.getFolder(mbox);

if (folder == null)

{

System.out.println("Invalid folder");

return false;

}

try { folder.open(Folder.READ_WRITE); } // try to open read/write and if that fails try read-only

catch (MessagingException ex) { folder.open(Folder.READ_ONLY); }

int totalMessages=folder.getMessageCount();

if (totalMessages == 0)

{

System.out.println("Empty folder");

folder.close(false);

store.close();

return true;

}

if (verbose)

{

int newMessages=folder.getNewMessageCount();

System.out.println("Total messages=" + totalMessages);

System.out.println("New messages=" + newMessages);

System.out.println("-");

}

if (msgnum == -1)

{

Message[] msgs=folder.getMessages();// Attributes & Flags for all messages ..

FetchProfile fp=new FetchProfile();// Use a suitable FetchProfile

fp.add(FetchProfile.Item.ENVELOPE);

fp.add(FetchProfile.Item.FLAGS);

fp.add("X-Mailer");

folder.fetch(msgs, fp);

for (int i=0; i < msgs.length; i++)

{

System.out.println("--");

System.out.println("MESSAGE #" + (i + 1) + ":");

dumpEnvelope(msgs[i]);

// dumpPart(msgs[i]);

}

}

else

{

System.out.println("Getting message number: " + msgnum);

Message m=null;

try

{

m=folder.getMessage(msgnum);

dumpPart(m);

}

catch (IndexOutOfBoundsException iex) { System.out.println("Message number out of range"); }

}

folder.close(false);

store.close();

}

catch (Exception ex)

{

System.out.println("Oops, got exception! " + ex.getMessage());

ex.printStackTrace();

return false;

}

return true;

}

public static void out(String message) { System.out.print(message); }

public static void Out(String message) { System.out.println(message); }

public static void main(String argv[])

{

int optind;

for (optind=0; optind < argv.length; optind++)

{

if (argv[optind].equals("-T")) protocol=argv[++optind];

else if (argv[optind].equals("-H")) host=argv[++optind];

else if (argv[optind].equals("-U")) user=argv[++optind];

else if (argv[optind].equals("-P")) password=argv[++optind];

else if (argv[optind].equals("-v")) verbose=true;

else if (argv[optind].equals("-D")) debug=true;

else if (argv[optind].equals("-f")) mbox=argv[++optind];

else if (argv[optind].equals("-L")) url=argv[++optind];

else if (argv[optind].equals("-p")) port=Integer.parseInt(argv[++optind]);

else if (argv[optind].equals("-s")) showStructure=true;

else if (argv[optind].equals("-S")) saveAttachments=true;

else if (argv[optind].equals("-m")) showMessage=true;

else if (argv[optind].equals("-a")) showAlert=true;

else if (argv[optind].equals("--"))

{

optind++;

break;

}

else if (argv[optind].startsWith("-"))

{

Out(" ? optind="+optind+" "+argv[optind]);

System.out.println("Usage: msgshow [-L url] [-T protocol] [-H host] [-p port] [-U user]");

System.out.println("\t[-P password] [-f mailbox] [msgnum] [-v] [-D] [-s] [-S] [-a]");

System.out.println("ormsgshow -m [-v] [-D] [-s] [-S] [-f msg-file]");

System.exit(1);

}

else break;

}

try

{

if (optind < argv.length) msgnum=Integer.parseInt(argv[optind]);

Show_Email_Message demo=new Show_Email_Message();

//Show_Message(String protocol,String host,int port,String user,String password,boolean verbose,boolean debug,String url,String mbox,boolean showStructure,boolean saveAttachments,boolean showMessage,boolean showAlert,int msgnum)

//Out("Show_Message = "+demo.Show_Message("pop3","mail.nmjava.com",110,"webmaster@nmjava.com","webmaster",true,true,null,null,false,false,false,false,msgnum));

//Login_To_Incoming_Server(String protocol,String host,int port,String user,String password,boolean verbose,boolean debug,String url)

Out("Login_To_Incoming_Server = "+demo.Login_To_Incoming_Server("pop3","mail.nmjava.com",110,"webmaster@nmjava.com","webmaster",true,true,null));

}

catch (Exception ex)

{

System.out.println("Oops, got exception! " + ex.getMessage());

ex.printStackTrace();

System.exit(1);

}

}

public static void dumpPart(Part p) throws Exception

{

if (p instanceof Message) dumpEnvelope((Message)p);

/** Dump input stream ..

InputStream is=p.getInputStream();

// If "is" is not already buffered, wrap a BufferedInputStream around it.

if (!(is instanceof BufferedInputStream)) is=new BufferedInputStream(is);

int c;

while ((c=is.read()) != -1) System.out.write(c);

**/

String ct=p.getContentType();

try { pr("CONTENT-TYPE: " + (new ContentType(ct)).toString()); }

catch (ParseException pex) { pr("BAD CONTENT-TYPE: " + ct); }

String filename=p.getFileName();

if (filename != null) pr("FILENAME: " + filename);

if (p.isMimeType("text/plain"))// Using isMimeType to determine the content type avoids fetching the actual content data until we need it.

{

pr("This is plain text");

pr("");

if (!showStructure && !saveAttachments) System.out.println((String)p.getContent());

}

else if (p.isMimeType("multipart/*"))

{

pr("This is a Multipart");

pr("");

Multipart mp=(Multipart)p.getContent();

level++;

int count=mp.getCount();

for (int i=0; i < count; i++) dumpPart(mp.getBodyPart(i));

level--;

}

else if (p.isMimeType("message/rfc822"))

{

pr("This is a Nested Message");

pr("");

level++;

dumpPart((Part)p.getContent());

level--;

}

else

{

if (!showStructure && !saveAttachments)

{

// If we actually want to see the data, and it's not a MIME type we know, fetch it and check its Java type.

Object o=p.getContent();

if (o instanceof String)

{

pr("This is a string");

pr("");

System.out.println((String)o);

}

else if (o instanceof InputStream)

{

pr("This is just an input stream");

pr("");

InputStream is=(InputStream)o;

int c;

while ((c=is.read()) != -1) System.out.write(c);

}

else

{

pr("This is an unknown type");

pr("");

pr(o.toString());

}

}

else pr("");// just a separator

}

// If we're saving attachments, write out anything that looks like an attachment into an appropriately named file. Don't overwrite existing files to prevent mistakes.

if (saveAttachments && level != 0 && !p.isMimeType("multipart/*"))

{

String disp=p.getDisposition();

if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) // many mailers don't include a Content-Disposition

{

if (filename == null) filename="Attachment" + attnum++;

pr("Saving attachment to file " + filename);

try

{

File f=new File(filename);

if (f.exists()) throw new IOException("file exists");// XXX - could try a series of names

((MimeBodyPart)p).saveFile(f);

}

catch (IOException ex) { pr("Failed to save attachment: " + ex); }

pr("");

}

}

}

public static void dumpEnvelope(Message m) throws Exception

{

pr("This is the message envelope");

pr("");

Address[] a;

// FROM

if ((a=m.getFrom()) != null) for (int j=0; j < a.length; j++) pr("FROM: " + a[j].toString());

// TO

if ((a=m.getRecipients(Message.RecipientType.TO)) != null)

{

for (int j=0; j < a.length; j++)

{

pr("TO: " + a[j].toString());

InternetAddress ia=(InternetAddress)a[j];

if (ia.isGroup())

{

InternetAddress[] aa=ia.getGroup(false);

for (int k=0; k < aa.length; k++) pr(" GROUP: " + aa[k].toString());

}

}

}

// SUBJECT

pr("SUBJECT: " + m.getSubject());

// DATE

Date d=m.getSentDate();

pr("SendDate: "+(d != null ? d.toString():"UNKNOWN"));

// FLAGS

Flags flags=m.getFlags();

StringBuffer sb=new StringBuffer();

Flags.Flag[] sf=flags.getSystemFlags();// get the system flags

boolean first=true;

for (int i=0; i < sf.length; i++)

{

String s;

Flags.Flag f=sf[i];

if (f == Flags.Flag.ANSWERED) s="\\Answered";

else if (f == Flags.Flag.DELETED) s="\\Deleted";

else if (f == Flags.Flag.DRAFT) s="\\Draft";

else if (f == Flags.Flag.FLAGGED) s="\\Flagged";

else if (f == Flags.Flag.RECENT) s="\\Recent";

else if (f == Flags.Flag.SEEN) s="\\Seen";

else continue; // skip it

if (first) first=false;

else sb.append(' ');

sb.append(s);

}

String[] uf=flags.getUserFlags();// get the user flag strings

for (int i=0; i < uf.length; i++)

{

if (first) first=false;

else sb.append(' ');

sb.append(uf[i]);

}

pr("FLAGS: " + sb.toString());

// X-MAILER

String[] hdrs=m.getHeader("X-Mailer");

if (hdrs != null) pr("X-Mailer: " + hdrs[0]);

else pr("X-Mailer NOT available");

}

// Print a, possibly indented, string.

public static void pr(String s)

{

if (showStructure) System.out.print(indentStr.substring(0, level * 2));

System.out.println(s);

}

}

===========================================================

Here are the results :

--

<1> Ran by it self [ Started from main() ]

init:

deps-jar:

compile-single:

run-single:

protocol=pop3

host=mail.nmjava.com

port=110

user=webmaster@nmjava.com

password=[***password***]

verbose=true

debug=true

url=null

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]

DEBUG POP3: connecting to host "mail.nmjava.com", port 110, isSSL false

S: +OK <13577.1184958019@mail54.opentransfer.com>

C: USER webmaster@nmjava.com

S: +OK

C: PASS [***password***]

S: +OK

Login_To_Incoming_Server = true

BUILD SUCCESSFUL (total time: 2 seconds)

--

<2> Called from another Java program [ Started by calling : Show_Email_Message.Login_To_Incoming_Server(Incoming_Server_Protocol,Incoming_Server_Host_Name,Integer.parseInt(Incoming_Server_Port_Number),User_Name+"@"+Incoming_Server_Host_Name.substring(Incoming_Server_Host_Name.indexOf(".")+1),Password,true,true,null) ]

init:

deps-jar:

compile-single:

run-single:

protocol=pop3

host=mail.nmjava.com

port=110

user=webmaster@nmjava.com

password=[***password***]

verbose=true

debug=true

url=null

DEBUG: setDebug: JavaMail version 1.4ea

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]

DEBUG POP3: connecting to host "mail.nmjava.com", port 110, isSSL false

S: +OK <8609.1184959318@mail54.opentransfer.com>

C: USER webmaster@nmjava.com

S: +OK

C: PASS [***password***]

S: -ERR authorization failed

C: QUIT

S: EOF

javax.mail.AuthenticationFailedException: authorization failed

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)

Oops, got exception! authorization failed

Login_To_Incoming_Server = false

at javax.mail.Service.connect(Service.java:275)

at Show_Email_Message.Show_Message(Show_Email_Message.java:78)

at Show_Email_Message.Login_To_Incoming_Server(Show_Email_Message.java:32)

at Email_Panel.Check_Email_Host_Availability(Email_Panel.java:1066)

at Email_Panel.run(Email_Panel.java:1565)

at java.lang.Thread.run(Thread.java:619)

===========================================================

The parameters were the same, why the difference in results ? Thanks.

Frank

Ni_Mina at 2007-7-21 22:53:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 34

I have no idea. Are you sure the password is the same in both cases?

Does the password contain any special (non-ASCII or non-printable)

characters?

Since you have a working program and a non-working program, and they

both use the same version of JavaMail, the problem is almost certainly

in your modification to the working program or the way you're calling it.

bshannona at 2007-7-21 22:53:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 35
The pass word is exactly the same and contains just regular characters.Can anyone find anything wrong with the modified program ? I didn't change a lot.Frank
Ni_Mina at 2007-7-21 22:53:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...