Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

NTLM Authentication

843834Jun 22 2010 — edited Jun 24 2010
Hi

I am writing a method to forward an email, however, I am getting an exception when I try to login to the microsoft exchange server.
Here is the output that I get when debug is turned on:
 
DEBUG 2010-06-22 10:12:09,299 [main] main.java.Poller: Forwarding email
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "host", port 25, isSSL false
220 frg.services.net Microsoft ESMTP MAIL Service ready at Tue, 22 Jun 2010 10:12:08 +0200
DEBUG SMTP: connected to host "host", port: 25

EHLO 
250-frg.services.net Hello [172.19.172.151]
250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250 XRDST
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM"
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "XRDST", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: mechanism LOGIN not supported by server
DEBUG SMTP: mechanism PLAIN not supported by server
DEBUG SMTP: mechanism DIGEST-MD5 not supported by server
DEBUG NTLM: type 1 message: 4E 54 4C 4D 53 53 50 00 01 00 00 00 03 B2 00 00 04 00 04 00 2A 00 00 00 0A 00 0A 00 20 00 00 00 72 6D 62 2D 6A 61 67 31 2D 77 46 52 47 53 
AUTH NTLM TlRMTVNTUAABAAAAA7IAAAQABAAqAAAACgAKACAAAABybWItamFnMS13RlJHUw==
334 TlRMTVNTUAACAAAACAAIADgAAAAFgoECAix4k8WDpZMAAAAAAAAAANoA2gBAAAAABgByFwAAAA9GAFIARwBTAAIACABGAFIARwBTAAEAFABGAFIARwBTAFQATgBDAEgAMAAxAAQALABzAGUAcgB2AGkAYwBlAHMALgBmAGkAcgBzAHQAcgBhAG4AZAAuAG4AZQB0AAMAQgBGAFIARwBTAFQATgBDAEgAMAAxAC4AcwBlAHIAdgBpAGMAZQBzAC4AZgBpAHIAcwB0AHIAYQBuAGQALgBuAGUAdAAFACwAcwBlAHIAdgBpAGMAZQBzAC4AZgBpAHIAcwB0AHIAYQBuAGQALgBuAGUAdAAHAAgAJBpWnOIRywEAAAAA
DEBUG NTLM: type 3 message: 4E 54 4C 4D 53 53 50 00 03 00 00 00 18 00 18 00 6A 00 00 00 18 00 18 00 82 00 00 00 08 00 08 00 40 00 00 00 0E 00 0E 00 48 00 00 00 14 00 14 00 56 00 00 00 00 00 00 00 9A 00 00 00 01 82 00 00 46 00 52 00 47 00 53 00 4A 00 41 00 47 00 5C 00 4A 00 41 00 47 00 72 00 6D 00 62 00 2D 00 6A 00 61 00 67 00 31 00 2D 00 77 00 A2 79 E3 08 BE 8B B4 E9 44 C2 0E 10 3C CF 77 C0 BD ED 9B 28 02 24 8C C2 3B B5 BC 07 53 4F 4A FD 3B 6C B2 79 BB 0A B7 D0 3E 09 61 77 E9 A6 C4 6D 
TlRMTVNTUAADAAAAGAAYAGoAAAAYABgAggAAAAgACABAAAAADgAOAEgAAAAUABQAVgAAAAAAAACaAAAAAYIAAEYAUgBHAFMASgBBAEcAXABKAEEARwByAG0AYgAtAGoAYQBnADEALQB3AKJ54wi+i7TpRMIOEDzPd8C97ZsoAiSMwju1vAdTT0r9O2yyebsKt9A+CWF36abEbQ==
535 5.7.3 Authentication unsuccessful
ERROR 2010-06-22 10:12:14,439 [main] main.java.Poller: javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

	at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:782)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:717)
	at javax.mail.Service.connect(Service.java:291)
	at javax.mail.Service.connect(Service.java:172)
	at main.java.Poller.forwardEmail(Poller.java:279)
	at main.java.Poller.startPolling(Poller.java:136)
	at main.java.Poller.main(Poller.java:302)
A9 EXAMINE INBOX
* 253 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS ()] Permanent flags
* OK [UIDVALIDITY 38293] UIDVALIDITY value
* OK [UIDNEXT 563] The next unique identifier value
A9 OK [READ-ONLY] EXAMINE completed.
A10 CLOSE
A10 OK CLOSE completed.
DEBUG: added an Authenticated connection -- size: 1
A11 LOGOUT
* BYE Microsoft Exchange Server 2007 IMAP4 server signing off.
A11 OK LOGOUT completed.
DEBUG: IMAPStore connection dead
DEBUG: IMAPStore cleanup, force false
DEBUG: IMAPStore cleanup done
Here's the method that I use:
private void forwardEmail(Session session, Message message, EmailData emailData){
    	log.debug("Forwarding email");
    	
    	 // Create the message to forward
        Message forward = new MimeMessage(session);

        try{
        // Fill in header
        forward.setSubject("Fwd: " + message.getSubject());
        forward.setFrom(new InternetAddress(emailData.getFrom()));
        forward.addRecipient(Message.RecipientType.TO, new InternetAddress(getEmailAddress()));

        // Create your new message part
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText("Oiginal message:\n\n");

        // Create a multi-part to combine the parts
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);

        // Create and fill part for the forwarded content
        messageBodyPart = new MimeBodyPart();
        messageBodyPart.setDataHandler(message.getDataHandler());

        // Add part to multi part
        multipart.addBodyPart(messageBodyPart);

        // Associate multi-part with message
        forward.setContent(multipart);

        // Send message
        
        Transport trans = session.getTransport("smtp");
        trans.connect(getSmtpServer(),getUsername(),getPassword()); // The exception is thrown at this line
        forward.saveChanges();
        trans.sendMessage(forward, forward.getAllRecipients());
        trans.close();
        log.debug("Forwarding complete.");
        }
        catch(MessagingException e){
        	log.error(e,e);
        }
    }
I have set the following properties:
host = props.getProperty("host").trim();
username = props.getProperty("username").trim();
password = props.getProperty("password").trim();
protocol = props.getProperty("protocol").trim();
smtpServer = props.getProperty("mail.smtp.host").trim();

props.put("mail.imap.auth.plain.disable", "true");
props.put("mail.imap.auth.ntlm.disable", "true");
props.put("mail.smtp.auth", "true");
	
Please can someone tell me what to do so that the application will be able to authenticate correctly?

Thank You

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 22 2010
Added on Jun 22 2010
4 comments
5,050 views