gpt4 book ai didi

Java Mail writeTo 和读回给出 Illegal semicolon 错误

转载 作者:行者123 更新时间:2023-11-29 07:00:07 28 4
gpt4 key购买 nike

我正在使用 java 获取邮件消息并将该消息保存到文件中。当我去读回文件时,我得到一个 javax.mail.internet.AddressException

下面是我用来写消息的代码

Properties mailProps = System.getProperties();
mailProps.setProperty("mail.store.protocol", "imaps");
Session session = null;
Folder inbox = null;
Store store = null;
Message[] messages = null;

try {
session = Session.getDefaultInstance(mailProps, null);
store = session.getStore("imaps");

store.connect(config.getMailHost(), config.getMailUserId(), config.getMailPasswd());

inbox = store.getFolder("inbox");
inbox.open(Folder.READ_WRITE); // Folder.READ_ONLY
logger.info("Total Messages found on Host: <{}>", inbox.getMessageCount());
logger.info("Total Unread Messages on Host: <{}>", inbox.getUnreadMessageCount());

messages = inbox.getMessages();

for (Message currMessage : messages) {

File mailFile = buildMailFileName();
currMessage.writeTo(new FileOutputStream(mailFile));
}
}

我可以看到文件已创建并包含以下行:

To: Name@domain.com;

当我重新读取文件时,出现以下错误:

javax.mail.internet.AddressException: 非法分号,不在字符串 'Name@domain 的组中。

这是我用来读取文件的代码:

Session session = Session.getDefaultInstance(mailProps, null);
FileInputStream fis = new FileInputStream(mailFile);
MimeMessage mime = new MimeMessage(null, fis);
Address[] addresses = mime.getRecipients(Message.RecipientType.TO);

最佳答案

不允许使用分号作为电子邮件地址的分隔符,请改用逗号!

关于Java Mail writeTo 和读回给出 Illegal semicolon 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27487115/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com