I need a library that allows me to do email operations(e.g Sent/Receive mail) in Gmail using Java.
+7
A:
Have you seen g4j - GMail API for Java?
GMailer API for Java (g4j) is set of API that allows Java programmer to communicate to GMail. With G4J programmers can made Java based application that based on huge storage of GMail.
Galwegian
2009-01-27 11:32:56
What about using pop3? And does g4j stay current when/if gmail updates/changes their html rendererd client?
Zombies
2010-05-18 02:16:27
+1
A:
Hello,
First, configure your Gmail account to accept POP3 access. Then, simply access your mail account using Javamail !
romaintaz
2009-01-27 11:35:46
A:
You can use the Javamail for that. The thing to remember is that GMail uses SMTPS not SMTP.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class SimpleSSLMail {
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final int SMTP_HOST_PORT = 465;
private static final String SMTP_AUTH_USER = "[email protected]";
private static final String SMTP_AUTH_PWD = "mypwd";
public static void main(String[] args) throws Exception{
new SimpleSSLMail().test();
}
public void test() throws Exception{
Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", SMTP_HOST_NAME);
props.put("mail.smtps.auth", "true");
// props.put("mail.smtps.quitwait", "false");
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Testing SMTP-SSL");
message.setContent("This is a test", "text/plain");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]"));
transport.connect
(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
}
RealHowTo
2009-01-27 12:27:16
+2
A:
Variations of this question have been addressed in several earlier posts:
- Getting mail from GMail into Java application using IMAP
- How do you send email from a Java app using Gmail?
The general approach is to use IMAP/SMTP via JavaMail. The FAQ even has a special entry for working with Gmail.
Zach Scrivena
2009-01-27 12:30:56