简体   繁体   English

使用Apache邮件发送电子邮件不会保存在已发送的文件夹中

[英]Sending email using Apache mail is not saved in the sent folder

I am using Apache Commons Mail library to send email (using their simple SMTP email example). 我正在使用Apache Commons Mail库发送电子邮件(使用他们简单的SMTP电子邮件示例)。

The email is sent using one of the famous providers (i used yahoo as an example). 电子邮件是使用其中一个着名的提供商发送的(我以雅虎为例)。 The email was sent successfully. 电子邮件已成功发送。 However when I login to my yahoo account I don't see the email in the sent folder. 但是,当我登录到我的yahoo帐户时,我看不到发送文件夹中的电子邮件。

Is there a flag I need to enable or some other thing I need to code to ensure that email is being saved in the sent folder? 是否需要启用一个标志或我需要编码的其他一些东西,以确保电子邮件保存在已发送的文件夹中?

Please assist. 请协助。 Thank you 谢谢

i just had the same issue an solved it by: 我刚刚遇到了同样的问题,解决了这个问题:

    ...
    // send the org.apache.commons.mail.HtmlEmail
    email.send();
    copyIntoSent(email.getMailSession(), email.getMimeMessage());
}

private void copyIntoSent(final Session session, final Message msg) throws MessagingException
{
    final Store store = session.getStore("imaps");
    store.connect(IMAP_HOST, SMTP_AUTH_USER, SMTP_AUTH_PWD);

    final Folder folder = (Folder) store.getFolder("Sent Items");
    if (folder.exists() == false) {
        folder.create(Folder.HOLDS_MESSAGES);
    }
    folder.open(Folder.READ_WRITE);

    folder.appendMessages(new Message[] { msg });
}

Note that you must use the imap-host here, not the smtp-host. 请注意,您必须在此处使用imap-host,而不是smtp-host。 The difference about these protocols should be clear. 这些协议的区别应该是清楚的。

With kind regards 亲切的问候

davey 戴维

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

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