响应服务器535 5.7.1 unab,java - javax.mail.AuthenticationFailedException: 535 authentication failed (#5.7...

i am making an auto send email java project using javamail api. when i send this mail using smtp.gmail.com host, it works. But when i use my own host server mail.sitename.com...it shows exception..my username and password are right. Please anyone help me to sort out this problem...

Exception is:-

javax.mail.AuthenticationFailedException: 535 authentication failed (#5.7.1)

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)

at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)

at javax.mail.Service.connect(Service.java:317)

at javax.mail.Service.connect(Service.java:176)

at javax.mail.Service.connect(Service.java:125)

at javax.mail.Transport.send0(Transport.java:194)

at javax.mail.Transport.send(Transport.java:124)

at com.zenga.servlet.MailNotification.sendMail(MailNotification.java:130)

at com.zenga.servlet.MailNotification.doPost(MailNotification.java:45)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Codes:---

a) i am using DAO pattern for data fetching for to(email id ) purpose

b) a jsp file to take start and limit to fetch no of connection to those i am gonna send emails..

c) Servlet file is 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

HashMaplist = new HashMap();

Set> set = null;

Iterator> itr = null;

int start = 0;

int limit = 0;

Map.Entry 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)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 from = "xyz@sitename.com";

final String subject = "a subject";

final String password = "password";

final String host = "mail.sitename.com";

String msg = getMessage(toUsername);

//Set the 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 a message

MimeMessage message=new MimeMessage(session);

// set the from and to 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 the Subject and Content Type

message.setSubject(subject);

// create and fill the first message part

MimeBodyPart msgBodypart = new MimeBodyPart();

msgBodypart.setText(msg,"ascii","hmtl");

// create the Multipart and add its parts to it

Multipart multipart=new MimeMultipart();

multipart.addBodyPart(msgBodypart);

// add the Multipart to the message

message.setContent(multipart);

// set the 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 everything that is in comment as well but nothing worked. i read many stackoverflow examples and no one is solving it correctly.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用中提到的javax.mail.AuthenticationFailedException: 535 authentication failed (#5.7.1) 是一个邮件身份验证失败的异常。引用中的问题描述了一个使用javamail api发送邮件时遇到的身份验证失败问题。 这个异常可能是由于以下几个原因导致的: 1. 提供的用户名或密码不正确。请确保你提供的用户名和密码是正确的,特别是在使用自己的主机服务器时。 2. 邮件服务器的设置有误。请检查你的邮件服务器的设置,确保你使用的是正确的主机地址和端口号,并且启用了SMTP身份验证。 3. 防火墙或安全设置阻止了邮件发送。有时候,防火墙或安全设置可能会阻止邮件发送。你可以尝试通过修改防火墙或安全设置来解决这个问题。 为了解决这个问题,你可以尝试以下几个方法: 1. 确认你的用户名和密码是正确的,并且与邮件服务器的要求一致。 2. 检查你的邮件服务器的设置,并确保你使用的是正确的主机地址和端口号。 3. 如果你遇到了防火墙或安全设置的问题,你可以尝试联系你的网络管理员或主机提供商,寻求帮助解决这个问题。 总结一下,当你遇到javax.mail.AuthenticationFailedException: 535身份验证失败(#5.7.1)这个异常时,你需要检查你提供的用户名和密码是否正确,确保邮件服务器的设置正确,并尝试解决防火墙或安全设置的问题。希望这些方法可以帮助你解决这个问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值