java - javax.mail.AuthenticationFailedException: 535 authentication failed (#5.7.1) -
i making auto send email java project using javamail api. when send mail using smtp.gmail.com host, works. when use own host server mail.sitename.com...it shows exception..my username , password right. please me sort out problem... exception is:-
javax.mail.authenticationfailedexception: 535 authentication failed (#5.7.1) @ com.sun.mail.smtp.smtptransport$authenticator.authenticate(smtptransport.java:826) @ com.sun.mail.smtp.smtptransport.authenticate(smtptransport.java:761) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:685) @ javax.mail.service.connect(service.java:317) @ javax.mail.service.connect(service.java:176) @ javax.mail.service.connect(service.java:125) @ javax.mail.transport.send0(transport.java:194) @ javax.mail.transport.send(transport.java:124) @ com.zenga.servlet.mailnotification.sendmail(mailnotification.java:130) @ com.zenga.servlet.mailnotification.dopost(mailnotification.java:45) @ javax.servlet.http.httpservlet.service(httpservlet.java:641) @ javax.servlet.http.httpservlet.service(httpservlet.java:722) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:224) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:169) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:168) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:98) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:928) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:407) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:987) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:539) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:300) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source)
codes:---
a) using dao pattern data fetching to(email id ) purpose b) jsp file take start , limit fetch no of connection gonna send emails.. c) servlet file given below...
package com.zenga.servlet; import java.io.*; import java.security.generalsecurityexception; import java.util.*; import com.sun.mail.util.mailsslsocketfactory; import com.zenga.dao.daofactory; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import javax.mail.*; import javax.mail.internet.*; /** * servlet implementation class send */ @webservlet("/send") public class mailnotification extends httpservlet { private static final long serialversionuid = 1l; @suppresswarnings("unchecked") protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub hashmap<string, string>list = new hashmap<string, string>(); set<?> set = null; iterator<?> itr = null; int start = 0; int limit = 0; map.entry<string, string> me = null; try { daofactory dao = daofactory.getdao(); start = integer.parseint(request.getparameter("start")); limit = integer.parseint(request.getparameter("end")); list = dao.insertlimit(start,limit); set = list.entryset(); itr = set.iterator(); while(itr.hasnext()) { me = (map.entry<string, string>)itr.next(); sendmail(me.getkey(),me.getvalue(),request,response); } } catch (exception e) { } } private void sendmail(string tousername, string to,httpservletrequest request,httpservletresponse response) throws ioexception, generalsecurityexception { final string = "xyz@sitename.com"; final string subject = "a subject"; final string password = "password"; final string host = "mail.sitename.com"; string msg = getmessage(tousername); //set host smtp address /*mailsslsocketfactory socketfactory= new mailsslsocketfactory(); socketfactory.settrustallhosts(true); properties properties=system.getproperties(); properties.put("mail.smtp.host", host); properties.put("mail.smtp.user", from); properties.put("mail.smtp.password", password); //properties.put("mail.smtp.starttls.enable","true"); properties.put("mail.smtp.ssl.socketfactory", socketfactory); properties.put("mail.smtp.enablessl.enable","true"); // properties.put("mail.smtp.ssl.enable","false"); properties.put("mail.smtp.ssl.trust",host); properties.put("mail.protocol.ssl.trust", host); properties.put("mail.smtp.socketfactory.port", "587"); properties.put("mail.smtp.socketfactory.class", "javax.net.ssl.sslsocketfactory"); properties.put("mail.smtp.port", "587"); properties.put("mail.smtp.auth", "true"); */ properties properties=system.getproperties(); properties.put("mail.smtp.host",host); properties.put("mail.smtp.user",from); properties.put("mail.smtp.password",password); properties.put("mail.smtp.port","587"); properties.put("mail.smtp.auth","true"); // properties.put("mail.smtp.starttls.enable","true"); properties.put("mail.smtp.ssl.enable","false"); properties.put("mail.smtp.starttls.enable","false"); authenticator auth = new authenticator(){ public passwordauthentication getpasswordauthentication() { return new passwordauthentication(from,password); } }; session session=session.getdefaultinstance(properties,auth); response.setcontenttype("text/html"); try{ // create message mimemessage message=new mimemessage(session); // set , address // internetaddress addressfrom = new internetaddress(from); message.setfrom(new internetaddress(from)); //internetaddress addressto = new internetaddress(to); message.addrecipient(message.recipienttype.to,new internetaddress(to)); // setting subject , content type message.setsubject(subject); // create , fill first message part mimebodypart msgbodypart = new mimebodypart(); msgbodypart.settext(msg,"ascii","hmtl"); // create multipart , add parts multipart multipart=new mimemultipart(); multipart.addbodypart(msgbodypart); // add multipart message message.setcontent(multipart); // set date: header message.setsentdate(new date()); transport.send(message); success++; } catch(messagingexception me) { failed++; me.printstacktrace(); } } /** * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response) */ }
i have tried in comment nothing worked. read many stackoverflow examples , no 1 solving correctly.
got solution.... javax.mail.authenticationfailedexception: 535 authentication failed (#5.7.1) occurs when host not authenticate user upto limit using code...as called host send mail approax 500 users @ 1 program running.so sendmail() called 500 times , got server hanged. hence blocked authentication coding site yet can access using browser. figured out solution when created new account , in coding made thread sendmail() called on 10 sec interval , send 100 users in go. host network solutions email login. hope if can give solution sort of problem. :)
Comments
Post a Comment