2016-05-24 44 views

回答

0

你有兩個選擇:

使用本機命令,如:

Process p = new ProcessBuilder("command", "opt1", "opt2", "arg").start(); 

或使用JavaMail

+0

我不明白這個過程? – kati

+0

請參閱[javadoc](https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html) –

+0

但我的問題是關於發送和接收電子郵件 – kati

0

使用Java郵件用戶創建後發送電子郵件

final String username = "[email protected]"; 
     final String password = "password"; 

     Properties props = new Properties(); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.starttls.enable", "true"); 
     props.put("mail.smtp.host", "smtp.gmail.com"); 
     props.put("mail.smtp.port", "587"); 

     Session session = Session.getInstance(props, 
      new javax.mail.Authenticator() { 
      protected PasswordAuthentication getPasswordAuthentication() { 
       return new PasswordAuthentication(username, password); 
      } 
      }); 

     try { 

      Message message = new MimeMessage(session); 
      message.setFrom(new InternetAddress("[email protected]")); 
      message.setRecipients(Message.RecipientType.TO, 
       InternetAddress.parse("[email protected]")); 
      message.setSubject("Testing Subject"); 
      message.setText("New user created"); 
      Transport.send(message); 
     } catch (MessagingException e) { 
      throw new RuntimeException(e); 
     } 
    } 

請看這裏:JavaMail API – Sending email

+0

感謝您的回覆,但這個解決方案是用來發送電子郵件的,在我的情況下,我希望在用戶註冊到網站時註冊信息在我的收件箱中收到一封電子郵件,抱歉我的英語不好 – kati

+0

是的,那是我的想法,在註冊用戶到您的網站的方法獲取用戶的詳細信息,並通過郵件發送到您的郵件帳戶 – KLajdPaja

+0

是的,我嘗試它,但我想要的電子郵件adresse,我把我的配置文件是接收器不是發件人 – kati