This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Sending mail through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sending mail through Java" Watch "Sending mail through Java" New topic
Author

Sending mail through Java

Yashwant Palkar
Greenhorn

Joined: Dec 01, 2010
Posts: 20
I am using following code to send mail through java application




its giving me an error 530 5.7.1 Client was not authenticated
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated


Please help me to solve this issue..

Thanks,
Yashwant
Alpesh Gediya
Greenhorn

Joined: Nov 23, 2009
Posts: 24
Hi Yashwant,

I would sugget you to put java code in Code block.

Go through following link. follow steps mentioned

http://smtp25.blogspot.com/2009/04/530-571-client-was-not-authenticated.html

before that i suggest you to use your mail account credential i.e. smtp username and password.


Alpesh Gediya
Do not re-invent the wheel.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Please UseCodeTags next time. I've added them for you this time.

Yashwant Palkar wrote:its giving me an error 530 5.7.1 Client was not authenticated
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated

It seems you need to login to use this SMTP server.

Try sending like this, instead of using Transport.send(msg):


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Yashwant Palkar
Greenhorn

Joined: Dec 01, 2010
Posts: 20


this methods are not available which API you are using.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
That's the same JavaMail API you're already using. If you're serious about using it, start by working through a thorough tutorial like http://java.sun.com/developer/onlineTraining/JavaMail/contents.html
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

JEE.
Message.saveChanges()
Session.getTransport(String)
Service.connect(String, String, String) (Transport extends Service)
Transport.sendMessage(Message, Address[]) (scroll down; the Address[] won't let me create a direct URL) with Message.getAllRecipients()
Service.close()
Yashwant Palkar
Greenhorn

Joined: Dec 01, 2010
Posts: 20
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
java.lang.ClassNotFoundException: jcifs.ntlmssp.Type1Message
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sonicsw.mf.framework.agent.ClassLoaderFactory$DelegateLoader.loadClass(ClassLoaderFactory.java:595)
at com.sonicsw.mf.framework.agent.ClassLoaderFactory$DelegateLoader.loadClass(ClassLoaderFactory.java:553)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.mail.auth.Ntlm.generateType1Msg(Ntlm.java:65)
at com.sun.mail.smtp.SMTPTransport$NtlmAuthenticator.getInitialResponse(SMTPTransport.java:784)
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:623)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)


I am getting this error while using this code.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
We don't know what "this code" is, but jCIFS is not part of JavaMail or JEE, so it must be used by some other component, possibly the "com.sonicsw.mf.framework" stuff. It has in any case nothing to do with JavaMail.

I advise to get the mail part working as a standalone application -like you did at first- before trying to integrate it elsewhere.
Yashwant Palkar
Greenhorn

Joined: Dec 01, 2010
Posts: 20
I have tried it with simple java code.
still giving same error

This is log I am getting from code.

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: use8bit false
MAIL FROM:<yashwant.palkar@xxx.com>
530 5.7.1 Client was not authenticated
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at TestEMail.main(TestEMail.java:46)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at TestEMail.main(TestEMail.java:46)
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Show us the code that performs the authentication; is it being called?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

Lester Burnham wrote:We don't know what "this code" is, but jCIFS is not part of JavaMail or JEE, so it must be used by some other component, possibly the "com.sonicsw.mf.framework" stuff. It has in any case nothing to do with JavaMail.


I think that's not correct. I believe that recent versions of JavaMail have attempted to include NTLM authentication, and for that they simply used jCIFS to do the authentication. I don't know whether that resulted in a requirement to include jCIFS as a dependency or whether it was somehow included directly in the mail.jar, I'm just saying this based on answers I remember seeing on other forums which were posted by the author of JavaMail.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
I stand corrected: JavaMail doesn't ship with jCIFS, but it can make use of it for NTLM authentication. That's documented in the NTLMNOTES.txt file in the JavaMail distribution.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

Aha. Thanks for doing the research, Lester.
M Massa
Greenhorn

Joined: Sep 03, 2010
Posts: 7
You could try something like this:



Where SMTPAuthenticator is defined as:

Yashwant Palkar
Greenhorn

Joined: Dec 01, 2010
Posts: 20

I tried through Authenticator but getting same error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending mail through Java