English 中文(简体)
javax.mail.MessagingException: 在试图使用java邮件收发电子邮件时重新打字
原标题:javax.mail.MessagingException: Connection reset while trying to access gmail using java mail API

I was trying to read through the mails in my gmail account using java mail API. This is the code:

import java.util.*;
import java.io.*;
import java.awt.*;
import javax.mail.*;
import javax.mail.search.FlagTerm; 
import javax.mail.Flags.Flag;
public class MailPharser {
/**
 * @param args
 */
public void mailRead()
{
    Folder inbox; 
    // TODO Auto-generated method stub
     Properties props = System.getProperties();
     props.setProperty("mail.store.protocol", "imaps"); 
     try
     {
         Session session = Session.getDefaultInstance(props, null); 

         Store store = session.getStore("imaps");

         store.connect("imap.gmail.com","<[email protected]>", "<password>"); 
         inbox = store.getFolder("Inbox"); 
         System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());


     }
     catch (Exception ex) 
     { System.out.println("Error caught"); ex.printStackTrace(); }

}

public static void main(String[] args) {
    MailPharser mp = new MailPharser();
    mp.mailRead();
}   

}

在运行期间,正出现以下错误:

javax.mail.MessagingException: Connection reset;
  nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at MailPharser.mailRead(MailPharser.java:26)
at MailPharser.main(MailPharser.java:40)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:548)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:352)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:113)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:111)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:637)
... 4 more

我补充了一点,并看到连接呼吁失败。 做什么错误? 任何帮助都会得到帮助。 页: 1

问题回答

这很可能是一个与 Java邮无关的网络问题,例如你与Gmail之间的代理或防火墙。

如果你想发现其编码是破裂的,还是打破了网络,那么你可以有关的代码。 如果 Java邮法发挥作用,那么你知道你的代码有点错,你可以使用费解法中的 Java邮法改进你的代码。

如果你发现这是一个网络问题,那么 Java邮局也拥有





相关问题
Search email inbox using javax.mail

I was trying to see if there was a way to search an email inbox from javax.mail. Say I wanted to send a query and have the it return emails to us. Can we parse returned HTML and extract data. Also, if ...

How to store mail password on server side?

I need to send e-mails from my application that is deployed on Weblogic 10.0. I try to put mail session properties on server side. Properties like mail.host or mail.debug work OK. But how do I ...

Jetty JNDI Java Mail

I am using Jetty 7 with JBoss Seam and have 2 Java Mail Sessions configured, one for support notifications and another for general notifications. The problem I am having appears to be from JBoss Seam ...

Javax.mail in JNLP

I have a problem with my program. I develop in Netbeans, and when i run the program it is working fine. i built it, created a *.jar file, and updatet it in my JNLP file. here comes the trouble. as i ...

Message charset

How do I get the charset from javax.mail.Message object?

Download attachments using Java Mail

Now that I`ve downloaded all the messages, and store them to Message[] temp; How do I get the list of attachments for each of those messages to List<File> attachments; Note: no thirdparty ...

How to attach a file to an email using JavaMail

I need to send a PDF file using JavaMail. The PDF is currently a byte[]. How do I get it into the DataSource? byte[] pdffile = .... messageBodyPart = new MimeBodyPart(); DataSource source = ??? ...

热门标签