javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:264)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailS
enderImpl.java:379)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSen
derImpl.java:298)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSen
derImpl.java:284)
at crds.pub.mail.EmailRunner.run(EmailRunner.java:73)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:675)
at java.lang.Thread.run(Thread.java:595)
我的代码流程大概如下:
先通过业务筛选出要发送的邮件地址、正文,开了一个线程循环发送邮件。
代码有点多不好贴。如有需要再贴吧。
5 个解决方案
#1
求高手不吝赐教,浪费了我1天的时间了。
#2
javax.mail.AuthenticationFailedException
认证失败了。我怀疑有2个原因
1 邮件服务器不允许你连续发送邮件
2 你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。
认证失败了。我怀疑有2个原因
1 邮件服务器不允许你连续发送邮件
2 你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。
#3
邮件服务器不允许你连续发送邮件,我也考虑过,不过我把tomcat重新启动又可以发送了,这个应该不是问题。
你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。这个重点只得那里?
public class EmailRunner implements Runnable {
static Logger logger = Logger.getLogger("aixunLog");
protected SimpleMailMessage simpleMailMessage;
protected MimeMessage mimeMessage;
protected JavaMailSender javaMailSender;
protected ExecutorService executorService;
protected List<SimpleMailMessage> smList;
其他方法省略。。。
public void run() {
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
}
你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。这个重点只得那里?
public class EmailRunner implements Runnable {
static Logger logger = Logger.getLogger("aixunLog");
protected SimpleMailMessage simpleMailMessage;
protected MimeMessage mimeMessage;
protected JavaMailSender javaMailSender;
protected ExecutorService executorService;
protected List<SimpleMailMessage> smList;
其他方法省略。。。
public void run() {
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
}
#4
public void run() {
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
#5
代码发的有点不好看。javaMailSender的一些对象都是已经封装好了的,List <SimpleMailMessage>也是封装好的。
public class EmailEntity extends EmailRunner{
public void generateMul_SimpleMailMessage(JavaMailSender javaMailSender, ExecutorService executorService){
if(mul_text!=null && mul_text.length>0){
smList = new ArrayList<SimpleMailMessage>();
super.javaMailSender = javaMailSender;
super.executorService = executorService;
for(int i = 0;i<mul_text.length;i++){
simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setText(mul_text[i]);
simpleMailMessage.setFrom(from);
simpleMailMessage.setTo(to[i]);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setSentDate(new Date());
smList.add(simpleMailMessage);
}
}
}
}
public class EmailEntity extends EmailRunner{
public void generateMul_SimpleMailMessage(JavaMailSender javaMailSender, ExecutorService executorService){
if(mul_text!=null && mul_text.length>0){
smList = new ArrayList<SimpleMailMessage>();
super.javaMailSender = javaMailSender;
super.executorService = executorService;
for(int i = 0;i<mul_text.length;i++){
simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setText(mul_text[i]);
simpleMailMessage.setFrom(from);
simpleMailMessage.setTo(to[i]);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setSentDate(new Date());
smList.add(simpleMailMessage);
}
}
}
}
#1
求高手不吝赐教,浪费了我1天的时间了。
#2
javax.mail.AuthenticationFailedException
认证失败了。我怀疑有2个原因
1 邮件服务器不允许你连续发送邮件
2 你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。
认证失败了。我怀疑有2个原因
1 邮件服务器不允许你连续发送邮件
2 你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。
#3
邮件服务器不允许你连续发送邮件,我也考虑过,不过我把tomcat重新启动又可以发送了,这个应该不是问题。
你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。这个重点只得那里?
public class EmailRunner implements Runnable {
static Logger logger = Logger.getLogger("aixunLog");
protected SimpleMailMessage simpleMailMessage;
protected MimeMessage mimeMessage;
protected JavaMailSender javaMailSender;
protected ExecutorService executorService;
protected List<SimpleMailMessage> smList;
其他方法省略。。。
public void run() {
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
}
你第二次调用时的代码有问题,比如忘了发送认证信息。或者认证信息被第一次给弄坏了。这个重点只得那里?
public class EmailRunner implements Runnable {
static Logger logger = Logger.getLogger("aixunLog");
protected SimpleMailMessage simpleMailMessage;
protected MimeMessage mimeMessage;
protected JavaMailSender javaMailSender;
protected ExecutorService executorService;
protected List<SimpleMailMessage> smList;
其他方法省略。。。
public void run() {
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
}
#4
public void run() {
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
if(smList!=null && smList.size()>0){
for(int i = 0 ; i< smList.size();i++){
this.simpleMailMessage = smList.get(i);
try {
javaMailSender.send(simpleMailMessage);
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//修正发送邮件问题
}
}else{
if (simpleMailMessage != null) {//发送一般邮件
javaMailSender.send(this.simpleMailMessage);
} else if (mimeMessage != null) {//发送复杂邮件
javaMailSender.send(this.mimeMessage);
}
}
}
#5
代码发的有点不好看。javaMailSender的一些对象都是已经封装好了的,List <SimpleMailMessage>也是封装好的。
public class EmailEntity extends EmailRunner{
public void generateMul_SimpleMailMessage(JavaMailSender javaMailSender, ExecutorService executorService){
if(mul_text!=null && mul_text.length>0){
smList = new ArrayList<SimpleMailMessage>();
super.javaMailSender = javaMailSender;
super.executorService = executorService;
for(int i = 0;i<mul_text.length;i++){
simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setText(mul_text[i]);
simpleMailMessage.setFrom(from);
simpleMailMessage.setTo(to[i]);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setSentDate(new Date());
smList.add(simpleMailMessage);
}
}
}
}
public class EmailEntity extends EmailRunner{
public void generateMul_SimpleMailMessage(JavaMailSender javaMailSender, ExecutorService executorService){
if(mul_text!=null && mul_text.length>0){
smList = new ArrayList<SimpleMailMessage>();
super.javaMailSender = javaMailSender;
super.executorService = executorService;
for(int i = 0;i<mul_text.length;i++){
simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setText(mul_text[i]);
simpleMailMessage.setFrom(from);
simpleMailMessage.setTo(to[i]);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setSentDate(new Date());
smList.add(simpleMailMessage);
}
}
}
}