如何使用maven javax接收邮件?

时间:2015-10-25 17:36:22

标签: java maven javafx

我希望使用javafx从任何指定的电子邮件ID接收邮件,但是获取MojoExecutionException异常。  我的pom.xml依赖项和下面提供的完整源代码请帮我解决这个问题。

<dependencies>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>javax.mail-api</artifactId>
        <version>1.5.0-b01</version>
        <type>jar</type>
    </dependency>
    <dependency>
<groupId>org.jvnet.mock-javamail</groupId>
<artifactId>mock-javamail</artifactId>
<version>1.9</version>

我的Javax代码是

 try {


 Properties properties = new Properties();  
 properties.put("mail.pop3.host", pop3Host);  
 Session emailSession = Session.getDefaultInstance(properties);  

POP3Store emailStore = (POP3Store) emailSession.getStore(storeType);  
emailStore.connect(user, password);  

 //3) create the folder object and open it  
 Folder emailFolder = emailStore.getFolder("INBOX");  
 emailFolder.open(Folder.READ_ONLY);  

 //4) retrieve the messages from the folder in an array and print it  
  Message[] messages = emailFolder.getMessages();  
 for (int i = 0; i < messages.length; i++) {  
 Message message = messages[i];  
 System.out.println("---------------------------------");  
 System.out.println("Email Number " + (i + 1));  
 System.out.println("Subject: " + message.getSubject());  
 System.out.println("From: " + message.getFrom()[0]);  
 System.out.println("Text: " + message.getContent().toString());  
 }  

 //5) close the store and folder objects  
 emailFolder.close(false);  
 emailStore.close();  

  } catch (NoSuchProviderException e) {e.printStackTrace();}   
  catch (MessagingException e) {e.printStackTrace();}  
 catch (IOException e) {e.printStackTrace();}  
}  

public  void excute() throws MessagingException {  

 String host = "xyz.com";//change accordingly  
 String mailStoreType = "pop3";  
 String username= "xyz@pqr.com";  
  String password= "cccccc";  

 receiveEmail(host, mailStoreType, username, password);  

 }  
public void start(Stage stage) throws Exception {

Parent root=FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));

    Scene scene = new Scene(root);
    scene.getStylesheets().add("/styles/Styles.css");

    stage.setTitle("JavaFX and Maven");
    stage.setScene(scene);
    stage.show();
  }
  public static void main(String[] args) throws MessagingException {
     receiveEmail obj=new receiveEmail();
     obj.excute();
     launch(args);
  }

0 个答案:

没有答案