简体   繁体   English

如何在 android 中使用 javamail api 起草邮件?

[英]How to draft a mail using javamail api in android?

I am trying to use this:我正在尝试使用这个:

public void saveDraftMessage(MimeMessage draftMessage, Store imapsStore) throws MessagingException
    {
        Folder draftsMailBoxFolder = imapsStore.getFolder("inbox");//[Gmail]/Drafts
        draftsMailBoxFolder.open(Folder.READ_WRITE);
        draftMessage.setFlag(Flags.Flag.DRAFT, true);
        MimeMessage draftMessages[] = {draftMessage};
        draftsMailBoxFolder.appendMessages(draftMessages);

    }

Properties set up:属性设置:

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

Session login: Session 登录:

session = Session.getInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(userEmailId, password);
            }
        });
}

Calling from:来自:

store = session.getStore("smtp");

store.connect(userEmailId, password);

MimeMessage mm = new MimeMessage(session);

saveDraftMessage(mm,store);

store.close();

Now getting error is:现在得到的错误是:

javax.mail.NoSuchProviderException: invalid provider javax.mail.NoSuchProviderException:无效的提供者

at javax.mail.Session.getStore(Session.java:575)在 javax.mail.Session.getStore(Session.java:575)

at javax.mail.Session.getStore(Session.java:541)在 javax.mail.Session.getStore(Session.java:541)

at javax.mail.Session.getStore(Session.java:520)在 javax.mail.Session.getStore(Session.java:520)

SMTP is not a store provider it is a transport provider. SMTP 不是存储提供商,而是运输提供商。 You need to adjust all of your properties to connect to IMAP server:您需要调整所有属性以连接到 IMAP 服务器:

Try one of the following:尝试以下方法之一:

store = session.getStore();
//store = session.getStore("imaps");
//store = session.getStore("imap");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM