简体   繁体   中英

Javamail cannot connect to postfix localhost server

I am trying to connect to a local postfix+dovecot server using javamail. I have connected to the server successfully using Thunderbird so I know that I have the username and password correct, but I always get

Javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Authentication failed. 
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661)
at javax.mail.Service.connect(Service.java:295)
at servers.MailEngine.initMailServer(MailEngine.java:661);

The only thing that I know that I have done is change the java.security to disable some less secure protocols. what protocols does dovecot need? or am I looking the wrong direction with this.

If this is a protocol problem is there any way that I can pass a parameter to the compiler? I do have other services that I would like to keep from supporting the disabled protocols

EDIT:

Session emailSessionObj;
Store storeObj;
Properties props = new Properties();
props.put("mail.imap.host", 127.0.0.1);
props.put("mail.imap.port", 143);

emailSessionObj = Session.getDefaultInstance(props);
storeObj = emailSessionObj.getStore("imap");

storeObj.connect("127.0.0.1", 143, "username","password");

Here is the code that I used

And Here is the debug output

DEBUG: setDebug: JavaMail version 1.5.0-b01
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
localhost : 143 : from@smsmail.pittsburgfoundry.com : smsmailpass:DEBUG IMAP: trying to connect to host "localhost", port 143, isSSL false
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN] Dovecot (Ubuntu) ready.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: protocolConnect login, host=localhost, user=from@smsmail.pittsburgfoundry.com, password=<non-null>
DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAP: AUTHENTICATE PLAIN command result: A0 NO [AUTHENTICATIONFAILED] Authentication failed.

In the end It ended up being a combination of an outdated javamail and some problems with my map authentication.

Another problems was that the username was enterd as xxx@yyy.zzz and it simply wanted xxx. The debug message from dovecot and pam were too vague to be very helpful as it did not find a username

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM