sitelink1 https://sites.google.com/site/parn755/home/java 
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  

I tried to find out how to connect gmail server and retrieve mails but most information seem to be too old/ambigous or they do not show complete code. 

So I'm trying to make valid sources. Below code just makes connection to pop3 server.

 

 

 

referenced links:

https://javamail.java.net/nonav/docs/JavaMail-1.5.pdf : Javamail API document ver 1.5

http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes : Javamail FAQ

 

 

 

 

 

Source: 

 

import java.util.Properties;

import javax.mail.Folder;

import javax.mail.MessagingException;

import javax.mail.Session;

import javax.mail.Store;

import javax.mail.URLName;

 

public class ReadTest {

 static String protocol = "pop3";

 static String host = "pop.gmail.com";

 static String user = "gmail ID";

 static String password = "password";

 static String port = "995";

 static String url = null;

 static String root = null;

 static String pattern = "%";

 static boolean recursive = false;

 static boolean verbose = false;

 static boolean debug = true;

 

 public static void main(String[] args) {

  // Get a Properties object

  Properties props = System.getProperties();

  

  // Let's check out what's in default Properties

  System.out.println(props.toString());

  

  //Before opening session, set port number and ssl authentication

  props.put("mail.pop3.port", "995");

  props.put("mail.pop3.ssl.enable", "true");

  

  //properties are added correctly?

  System.out.println(props.toString());

  

  // Get a Session object

  Session session = Session.getInstance(props, null);

  

  // let's see what's going on by setting debug as true

  session.setDebug(debug);

  // Get a Store object

  Store store = null;

  Folder rf = null;  

  

  

  try {

   if (url != null) {

    URLName urln = new URLName(url);

    store = session.getStore(urln);

    store.connect();

   } else {

    if (protocol != null) {

     store = session.getStore(protocol);

    }

    else {

     store = session.getStore();    

    }

    // Connect

    if (host != null || user != null || password != null) {   

     store.connect(host, user, password);

    }

    else {

     store.connect();

    }

   }

  } catch (MessagingException e) {

   // TODO Auto-generated catch block

   e.printStackTrace();

  }

 }

 

}

 

 

 

 

 

 

Result (omitted properties values)

 

DEBUG: setDebug: JavaMail version 1.5.0

DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]

DEBUG POP3: mail.pop3.rsetbeforequit: false

DEBUG POP3: mail.pop3.disabletop: false

DEBUG POP3: mail.pop3.forgettopheaders: false

DEBUG POP3: mail.pop3.cachewriteto: false

DEBUG POP3: mail.pop3.filecache.enable: false

DEBUG POP3: mail.pop3.keepmessagecontent: false

DEBUG POP3: mail.pop3.starttls.enable: false

DEBUG POP3: mail.pop3.starttls.required: false

DEBUG POP3: mail.pop3.apop.enable: false

DEBUG POP3: mail.pop3.disablecapa: false

DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL true

+OK Gpop ready for requests from 61.75.27.199 yw8pf6744109pac.0

CAPA

+OK Capability list follows

USER

RESP-CODES

EXPIRE 0

LOGIN-DELAY 300

TOP

UIDL

X-GOOGLE-VERHOEVEN

X-GOOGLE-RICO

.

DEBUG POP3: authentication command trace suppressed

DEBUG POP3: authentication command succeeded

 

 

번호 제목 글쓴이 날짜 조회 수
271 [HttpURLConnection, HttpsURLConnection] 코드참조용 샘플프로젝트 secret 황제낙엽 2019.01.18 0
270 Iterator.next() - NoSuchElementException 황제낙엽 2018.10.28 344
269 OracleJDK 유료화 FAQ (Oracle Java 의 유료화에 대한 어느분의 정리) 황제낙엽 2018.10.11 128
268 메일서버(daum.net)에 POP3를 이용하여 메일 가져오기 예제 file 황제낙엽 2018.10.09 940
267 Sending mail through Java using SMTP of gmail file 황제낙엽 2018.09.13 163
266 Read or get mails using pop in java (using gmail) file 황제낙엽 2018.09.13 861
265 Collections.sort() , Comparator 황제낙엽 2018.08.23 48
» JavaMail - Connecting Gmail pop3 server. 황제낙엽 2018.08.20 206
263 JavaMail - 네이버 메일 수신하기(POP3) 황제낙엽 2018.08.20 1413
262 JavaMail - POP3로 메일 읽어오기 - 단순샘플 황제낙엽 2018.08.20 107
261 [HttpURLConnection, HttpsURLConnection] Response 로 받은 데이터가 압축되어 있는 경우(gzip, deflate) 황제낙엽 2018.08.16 254
260 [HttpURLConnection, HttpsURLConnection] 자바 Http / https 의 결과를 주고받을때 세션을 유지 황제낙엽 2018.08.12 77
259 [HttpURLConnection] 자바(Java) URL 접속 및 세션 관리 file 황제낙엽 2018.08.12 109
258 json-rpc 에서 한글 문제 황제낙엽 2018.08.08 175
257 org.apache.commons.io.FilenameUtils (getExtension) 황제낙엽 2018.04.01 1209
256 이미지 파일의 화면사이즈와 포맷(확장자) 구하기 황제낙엽 2018.04.01 472
255 File 을 다루기 위한 유틸 클래스 file 황제낙엽 2018.02.28 99
254 상수의 데이터 타입 황제낙엽 2018.01.26 33
253 Java에서 User-Agent 파써 사용하기 황제낙엽 2017.11.20 418
252 현재 월,일,시간,분,초 등등 가져오기 황제낙엽 2017.11.02 858