| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

javaMail收邮件报错问题

0
Java Spring C/C++ 15811 次浏览
最近在做javaMail收邮件时,报了这个错误,avax.mail.AuthenticationFailedException: The system was unable to log shaufmu in.  Maildrop opened for exclusive access by another user.
 at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:128)
 at javax.mail.Service.connect(Service.java:236)
 at javax.mail.Service.connect(Service.java:137)
 at javax.mail.Service.connect(Service.java:86)
 at email.MailReceive.getMailReceiveByMail(MailReceive.java:415)
 at com.ceair.apm.service.communication.impl.CommunicationServiceImpl.getMailReceiveByMail(CommunicationServiceImpl.java:115)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 at $Proxy39.getMailReceiveByMail(Unknown Source)
 at com.ceair.apm.service.communication.impl.ReceiveEmailServiceImpl.saveReceiveEmail(ReceiveEmailServiceImpl.java:342)
 at com.ceair.apm.service.communication.impl.ReceiveEmailServiceImpl.addReceiveEmail(ReceiveEmailServiceImpl.java:330)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
 at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 at $Proxy67.addReceiveEmail(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
 at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)
 at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
 at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
 at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)请问有遇到过的没!!

6个答案

0
好长的代码,最好有整体的介绍。
0
····很久前用的javamail现在不是很清楚了
0
错误的意思大概是:”邮件投递独占访问模式下 打开了另一个用户"(可能是邮件正在发送中,你有在其他地方使用正在发送邮件的账号,导致发送异常),你一次启动几个发送客户端?每个客户端中有几个用户(邮件发送者)? 在邮件接收后执行什么操作?
建议延迟接收邮件( Thread.sleep()) 试试看
0
发送没有问题,是接收的问题?  单纯的接收邮件有没有问题?
0
建议:1.先把药发送邮件内容写死,单个测试邮件是否可以正常发送,如果可以发送,则说明不是邮件发送的问题,
          2.你是不是少加入了 J2EE1.4 库 ?
我写的java邮件发送类,可以参考:
发送邮件类代码如下:
import java.util.Date; 
import java.util.Properties; 
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Address; 
import javax.mail.Message; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 

/**
 *mail.jar和activation.jar
 * @author 
 */
public final class MailUtil {
   // 邮件发送者地址 
    private static final String SenderEmailAddr = "zhenmin_zhang2009@163.com";

    // 邮件发送者邮箱用户 
    private static final String SMTPUserName = "zhenmin_zhang2009";
     
    // 邮件发送者邮箱密码 
    private static final String SMTPPassword = "*********";

    // 邮件发送者邮箱SMTP服务器 
    private static final String SMTPServerName = "smtp.163.com"; 

    // 传输类型 
    private static final String TransportType = "smtp"; 

    // 属性 
    private static Properties props; 

    /** 
     * 私有构造函数,防止外界新建本实用类的实例,因为直接使用MailUtil.sendMail发送邮件即可 
     * 
     */ 
    private MailUtil() { 

    } 

    /** 
     * 静态构造器 
     */ 
    static { 
        MailUtil.props = new Properties(); 

        // 存储发送邮件服务器的信息 
        MailUtil.props.put("mail.smtp.host", MailUtil.SMTPServerName); 
        // 同时通过验证 
        MailUtil.props.put("mail.smtp.auth", "true"); 
    } 

    /** 
     * 发送邮件 
     * @param emailAddr:收信人邮件地址 
     * @param mailTitle:邮件标题 
     * @param mailConcept:邮件内容 
     */ 
    public static void sendMail(String emailAddr, String mailTitle, 
            String mailConcept) { 
        // 根据属性新建一个邮件会话,null参数是一种Authenticator(验证程序) 对象 
        Session s = Session.getInstance(MailUtil.props, null); 

        // 设置调试标志,要查看经过邮件服务器邮件命令,可以用该方法 
        s.setDebug(false); 
         
        // 由邮件会话新建一个消息对象 
        Message message = new MimeMessage(s); 
        try { 
            // 设置发件人 
            Address from = new InternetAddress(MailUtil.SenderEmailAddr); 
            message.setFrom(from); 

            // 设置收件人 
            Address to = new InternetAddress(emailAddr); 
            message.setRecipient(Message.RecipientType.TO, to); 

            // 设置主题 
            message.setSubject(mailTitle); 
            // 设置信件内容 
            message.setText(mailConcept); 
            // 设置发信时间 
            message.setSentDate(new Date()); 
            // 存储邮件信息 
            message.saveChanges(); 

            Transport transport = s.getTransport(MailUtil.TransportType); 
            // 要填入你的用户名和密码; 
            transport.connect(MailUtil.SMTPServerName, MailUtil.SMTPUserName, 
                    MailUtil.SMTPPassword); 

            // 发送邮件,其中第二个参数是所有已设好的收件人地址 
            transport.sendMessage(message, message.getAllRecipients()); 
            
           // transport.sendMessage(message, message.getAllRecipients()); 
            transport.close(); 

            System.out.println("发送邮件,邮件地址:" + emailAddr + " 标题:" + mailTitle 
                    + " 内容:" + mailConcept + "成功!"); 
        } catch (Exception e) { 
            System.out.println(e.toString()); 
            System.out.println("发送邮件,邮件地址:" + emailAddr + " 标题:" + mailTitle 
                    + " 内容:" + mailConcept + "失败! 原因是" + e.getMessage()); 
        } 
    } 

    /** 
     * 测试邮件发送情况 
     * @param args 
     */ 
    public static void main(String[] args){ 
        MailUtil.sendMail("379685868@qq.com", "预警信息提醒", "发起方账户为:62250001 ,发生金额为:5000 单笔交易金额超过了:1000 上限 ");
    }
 
 
 2.使用 javax.mail 发送邮件 ,需要给项目中 加入 J2EE1.4 库 
具体操作为:  Build Path->config build path->add library  J2EE1.4
不然会报(发送失败) :  javax.mail.NoSuchProviderException: smtp  
 并且如果发送中文会报(发送失败):
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/BEncoderStream 
0
这个应该程序没有关系。检查一下邮件服务器的POP3