Note that there are some explanatory texts on larger screens.

plurals
  1. POAre there any good short code examples that simply read a new gmail message?
    primarykey
    data
    text
    <p>I have been trying to write an app that periodically parses the contents of gmail messages. I have been through the JavaMail FAQ and I have looked at a number of examples in the JavaMail download package but have been unable to get this to work. The code below currently causes the following gmail error: </p> <blockquote> <p>Host is unresolved: imaps.gmail.com:993</p> </blockquote> <p>I have also tried imap.gmail.com:143 but get: </p> <blockquote> <p>Host is unresolved: imap.gmail.com:143</p> </blockquote> <p>Any help or advice would be greatly appreciated. GMailReader is the class I am using to try and return gmail imap messages: </p> <pre><code>public class GMailReader extends javax.mail.Authenticator { private String mailhost = "imaps.gmail.com"; private String user; private String password; private Session session; public GMailReader(String user, String password) { this.user = user; this.password = password; Properties props = new Properties(); props.setProperty("mail.transport.protocol", "imaps"); props.setProperty("mail.imaps.host", mailhost); props.put("mail.imaps.auth", "true"); props.put("mail.imaps.port", "993"); props.put("mail.imaps.socketFactory.port", "993"); props.put("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.imaps.socketFactory.fallback", "false"); props.setProperty("mail.imaps.quitwait", "false"); session = Session.getDefaultInstance(props, this); } public synchronized Message[] readMail() throws Exception { try { Store store = session.getStore("imaps"); store.connect("imaps.gmail.com", user, password); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message[] msgs = folder.getMessages(1, 10); FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); folder.fetch(msgs, fp); return msgs; } catch (Exception e) { Log.e("readMail", e.getMessage(), e); return null; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload