connect to Gmail Imap using javamail
2008-08-02 08:15
295 查看
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
public class Program {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String host = "imap.gmail.com";
int port = 993;
String user = "xxxxx@gmail.com";
String password = "xxxxx";
String target_folder = "INBOX";
Properties props = System.getProperties();
Session sess = Session.getInstance(props, null);
// sess.setDebug(true);
Store st = sess.getStore("imaps");
st.connect(host, port, user, password);
Folder fol = st.getFolder(target_folder);
if (fol.exists()) {
for (Folder f : fol.list()) {
System.out.println(f.getName());
}
fol.open(Folder.READ_ONLY);
for (Message m : fol.getMessages()) {
System.out.printf("%s - %d/n", m.getSubject(), m.getSize());
}
fol.close(false);
} else {
System.out.printf("%s is not exist.", target_folder);
}
st.close();
}
}
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
public class Program {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String host = "imap.gmail.com";
int port = 993;
String user = "xxxxx@gmail.com";
String password = "xxxxx";
String target_folder = "INBOX";
Properties props = System.getProperties();
Session sess = Session.getInstance(props, null);
// sess.setDebug(true);
Store st = sess.getStore("imaps");
st.connect(host, port, user, password);
Folder fol = st.getFolder(target_folder);
if (fol.exists()) {
for (Folder f : fol.list()) {
System.out.println(f.getName());
}
fol.open(Folder.READ_ONLY);
for (Message m : fol.getMessages()) {
System.out.printf("%s - %d/n", m.getSubject(), m.getSize());
}
fol.close(false);
} else {
System.out.printf("%s is not exist.", target_folder);
}
st.close();
}
}
相关文章推荐
- Access GMail with imap using java mail api
- Receive Email in Java using JavaMail – GMail IMAP Example
- Java JDBC - How to connect to Oracle using Service Name instead of SID
- Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- ORACLE EBS:Can't connect to X11 window server using '**' as the value of the DISPLAY variable.
- 在linux上,用xmanager 图形化界面建数据库报错“ Can't connect to X11 window server using 'localhost:13.0”
- Using ssh connect to Amazon EC2 instance
- Using Java arrays to insert, retrieve, & update PostgreSQL arrays
- Issues when using the Microsoft.Exchange.WebServices.dll connect to Exchange 2010
- android-java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8080)解决方法
- How to get simple dispatch from this.props using connect w/ Redux?
- using Java to Validate XML
- How to read ini file using Java
- Using IPv6 to connect computer in dorm from our laboratory
- mysql-1862、1820、java.sql.SQLException: Your password has expired. To log in you must change it using a client that supports expired passwords.
- How to set field values using Java reflection
- Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticat
- Connect to Dababase using JDBC in JSP
- Java在Linux下 不能处理图形的解决办法 Can't connect to X11 window server
- using System.Web.Mail to send email