如何在Android中使用Java邮件将应用程序电子邮件同步到服务器电子邮件? [英] How to synchronize application email to server email using Java mail in Android?

查看:95
本文介绍了如何在Android中使用Java邮件将应用程序电子邮件同步到服务器电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时更改电子邮件应用程序中的更改,然后自动更改服务器电子邮件中的更改.例如,我已经在电子邮件应用程序上阅读了未读邮件,然后自动将服务器电子邮件更改为未读邮件来阅读邮件.

I want to change synchronously change in email application then automatic change in server email. For example, I have read the unread message on email application then automatic server email change unread mail to read mail.

我的电子邮件应用程序使用了邮件jar文件,activation.jar和其他jar文件,并使用以下代码将电子邮件应用程序连接到服务器电子邮件:

My email application has use mail jar file, activation.jar and additional jar file use and following code are use for connectivity email application to server email:

Properties props = System.getProperties();
            props.setProperty("mail.store.protocol", "imaps");
            props.put("mail.smtp.starttls.enable","true");
            Authenticator auth = new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication(){
                    return new PasswordAuthentication("USEREMAILID","PASSWORD ");
                    }
            };
            sessioned= Session.getDefaultInstance(props, auth);
            store = sessioned.getStore("imaps");
           store.connect("smtp.gmail.com","USEREMAILID","PASSWORD ");
             inbox = store.getFolder("inbox");
            inbox.open(Folder.READ_ONLY);
            FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
            UNReadmessages = inbox.search(ft);

推荐答案

我已经解决了该问题.
切勿在运行时使用以下代码关闭连接.

I have solved the issue.
Never close the connection on run time, with below code.

   inbox.open(Folder.READ_WRITE);

这篇关于如何在Android中使用Java邮件将应用程序电子邮件同步到服务器电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆