java mail

C

Camel

Hi,

When I ran my email sending program, I got AuthenticationFailedException. I
am very sure my username and password are correct. What else could be the
problem?

Thank you very much in advance.

-------------code begin-----------------

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

class MailTest{

private String
sender,recipient1,mailHost,mailPort,mailProtocol,mailUser,mailPassword,mailContent,mailSubject;
Authenticator auth;

public MailTest() {

sender = "(e-mail address removed)";
recipient1 = (e-mail address removed);
mailHost = "myhost.com";
mailPort = "26";
mailProtocol = "smtp";
mailUser = "username";
mailPassword = "mypass";
mailSubject = "Hello";
mailContent = "How are you";
auth = new MyAuthenticator();

}

public void sendMail() {
try {
Properties props = new Properties();
props.setProperty("mail.transport.protocol", mailProtocol);

props.put("mail.transport.protocol", mailProtocol);
props.put("mail.smtp.host", mailHost);
props.put("mail.smtp.port", mailPort);
props.put("mail.smtp.user", mailUser);
props.put("mail.smtp.password", mailPassword);

props.put( "mail.smtp.auth", "true" );

Session mailSession = Session.getInstance(props, auth);
Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
message.setContent(mailContent, "text/plain");
message.setSubject(mailSubject);
message.setSender(new InternetAddress(sender));
message.setFrom(new InternetAddress(sender));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(recipient1));

transport.connect();
transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));
transport.close();

}
catch(Exception ex) {
System.out.println(ex.toString());
}

}

public static void main(String[] args) {
MailTest mail = new MailTest();
mail.sendMail();

}

class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailUser, mailPassword);
}
}
}
 
S

shakah

Camel said:
Hi,

When I ran my email sending program, I got AuthenticationFailedException. I
am very sure my username and password are correct. What else could be the
problem?

Thank you very much in advance.

-------------code begin-----------------

[...code snipped...]

mailPort = "26";

[...more code snipped...]

Starting with the simpler things, are you sure the SMTP server is
listening on port 26 and not port 25? Can you telnet to that box on
port 26 and send e-mail?
 
C

Camel

yes, I know it is port 26. This server is my company's mail server.

I can connect to the server and send email on my company's internal network,
either through port 25 or 26. If I connect to my SBC account (through dial
up), I have to use port 26 because 25 is blocked. I tried telnet to the
server, I got "220 mycompany.com ESMTP CommuniGate Pro 4.3.6" and empty
prompt. I typed "help" and got command list. I typed several command and got
"501 Unknown Command".

That is it.

Thank you for help.

shakah said:
Camel said:
Hi,

When I ran my email sending program, I got AuthenticationFailedException.
I
am very sure my username and password are correct. What else could be the
problem?

Thank you very much in advance.

-------------code begin-----------------

[...code snipped...]

mailPort = "26";

[...more code snipped...]

Starting with the simpler things, are you sure the SMTP server is
listening on port 26 and not port 25? Can you telnet to that box on
port 26 and send e-mail?
 
S

shakah

Camel said:
yes, I know it is port 26. This server is my company's mail server.

I can connect to the server and send email on my company's internal network,
either through port 25 or 26. If I connect to my SBC account (through dial
up), I have to use port 26 because 25 is blocked. I tried telnet to the
server, I got "220 mycompany.com ESMTP CommuniGate Pro 4.3.6" and empty
prompt. I typed "help" and got command list. I typed several command and got
"501 Unknown Command".

You can try setting mailSession.setDebug(true) to see what the SMTP
server is saying, with some luck you might see something of interest
(e.g. "auth scheme not supported" in response to your AUTH request).
Capturing the network traffic directly (e.g. with truss, snoop, or a
proxy) might yield some clues, too.

Going back to the simple things, though, I assume things don't work
with mail.smtp.auth set to false?
 
C

Camel

It does not work if set auth false. I added setDebug(true) in code and got
these:

DEBUG: setDebug: JavaMail version 1.3.2
DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "my.host.com", port 26, isSSL false

220 host.com ESMTP CommuniGate Pro 4.3.6
DEBUG SMTP: connected to host "my.host.com", port: 26

EHLO REPORT_SERVER
250-host.com domain name should be qualified REPORT_SERVER
250-DSN
250-SIZE 209715200
250-STARTTLS
250-AUTH=MSN
250-AUTH=LOGIN
250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5 MSN
250-ETRN
250-TURN
250-ATRN
250-NO-SOLICITING
250-8BITMIME
250-HELP
250-PIPELINING
250 EHLO
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "209715200"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH=MSN", arg ""
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN CRAM-MD5 DIGEST-MD5
MSN"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "ATRN", arg ""
DEBUG SMTP: Found extension "NO-SOLICITING", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "HELP" arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "EHLO", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
amhl
334 UGFzc3dvcmQ6
<some encoded pass here>
535 (515) incorrect password or account name
javax.mail.AuthenticationFailedException

I checked my username and password, the encode is correct too.
Very strange error.

Thank you very much.
 
G

GaryM

I checked my username and password, the encode is correct too.
Very strange error.

It might be due to the host name, though I doubt it. Can you manually
telnet net and conduct the session successfully? BTW, I would change
your password very quickly if I were you. That is very weak encrpytion
you just posted to public USENET.
 
C

Camel

I tried to send mail using telnet and failed. The problem is authentication.
I guess my company's smtp server uses a non-standard encode method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top