Невозможно сохранить почту в папке «Отправленные» - PullRequest
0 голосов
/ 20 апреля 2020

Я разрабатываю клиентское приложение для электронной почты в android. Мой код для отправки электронной почты работает правильно, но когда я пытаюсь сохранить почту в папке «Отправлено», это вызывает проблему. Это говорит о том, что папка "SENT" не существует. Если я изменю имя папки на «INBOX», то она сохранит почту в папке «Входящие». Как решить эту проблему? Заранее спасибо за помощь. мои коды следующие:

   protected Void doInBackground(String... strings) {
   //Date date = null;
    String subject=strings[0];
    String to=strings[1];
    String sendDt=strings[2];
    String msg=strings[3];
    String cc=strings[4];
    String choice=strings[5];
    Properties props = new Properties();

    props.put("mail.smtp.host", "mail.quobotic.in");//smtp.gmail.com
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.setProperty("mail.store.protocol", "imaps");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    try {
        session = Session.getInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(Config.EMAIL, Config.PASSWORD);
                }
            });
        MimeMessage mm = new MimeMessage(session);
        mm.setFrom(new InternetAddress(Config.EMAIL));
        mm.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        if((cc.length() > 0) & choice.equals("1")) {
         Log.i("snt",cc);
            mm.addRecipient(Message.RecipientType.CC, new InternetAddress(cc));
        }
        if(choice.equals("0"))
            mm.setSubject("Re: " + subject);
        else if(choice.equals("1"))
            mm.setSubject("Re: " + subject);
        else if(choice.equals("2"))
            mm.setSubject("Fw: " + subject);

        mm.setText(msg);
        Transport.send(mm);//;, Config.EMAIL, Config.PASSWORD);

        try {
            Store store = session.getStore("imap");
            store.connect("mail.quobotic.in", Config.EMAIL, Config.PASSWORD);
            //Folder[] f = store.getDefaultFolder().list();
            Folder folder = store.getFolder("SENT ITEM");
            folder.open(Folder.READ_WRITE);
            mm.setFlag(Flags.Flag.SEEN, true);
            folder.appendMessages(new Message[] {mm});
            store.close();

        }catch(Exception ex){
            Log.i("snt",ex.toString());
        }


    } catch (MessagingException e) {

        Log.i("snt",e.toString());
    }
    return null;

Я также протестировал с store.getDefaultFolder (). list (), он дает только INBOX.

...