本文整理汇总了Java中javax.mail.Message.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getContent方法的具体用法?Java Message.getContent怎么用?Java Message.getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Message
的用法示例。
在下文中一共展示了Message.getContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEmail
import javax.mail.Message; //导入方法依赖的package包/类
public void getEmail() throws MessagingException, IOException {
Session session = Session.getDefaultInstance(System.getProperties(),null);
Store store = null;
store = session.getStore("imaps");
// store.connect(this.host, this.userName, this.password);
// Get default folder
Folder folder = store.getDefaultFolder();
folder.getMessages();
folder.getNewMessageCount();
Message m = folder.getMessage(0);
m.getMessageNumber();
m.getAllRecipients();
m.getReceivedDate();
m.getFrom();
m.getSubject();
m.getReplyTo();
m.getContent();
m.getSize();
// Get any folder by name
Folder[] folderList = folder.list();
}
示例2: getMessageContent
import javax.mail.Message; //导入方法依赖的package包/类
/**
* Get the content of a mail message.
*
* @param message
* the mail message
* @return the content of the mail message
*/
private String getMessageContent(Message message) throws MessagingException {
try {
Object content = message.getContent();
if (content instanceof Multipart) {
StringBuffer messageContent = new StringBuffer();
Multipart multipart = (Multipart) content;
for (int i = 0; i < multipart.getCount(); i++) {
Part part = multipart.getBodyPart(i);
if (part.isMimeType("text/plain")) {
messageContent.append(part.getContent().toString());
}
}
return messageContent.toString();
}
return content.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
示例3: getAttachments
import javax.mail.Message; //导入方法依赖的package包/类
/**
* Récupération des pièces jointe d'un mail
* @param message Message javamail
* @return
* @throws Exception
*/
public static Map<String, InputStream> getAttachments(Message message) throws Exception {
Object content = message.getContent();
if (content instanceof String)
return null;
if (content instanceof Multipart) {
Multipart multipart = (Multipart) content;
Map<String, InputStream> result = new HashMap<String, InputStream>();
for (int i = 0; i < multipart.getCount(); i++) {
result.putAll(getAttachments(multipart.getBodyPart(i)));
}
return result;
}
return null;
}
示例4: getTextFromMessage
import javax.mail.Message; //导入方法依赖的package包/类
/**
* Extracts the text content of an email message with support for multipart
* messages
*/
private String getTextFromMessage(Message message) throws Exception {
String result = "";
if (message.isMimeType("multipart/*")) {
MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
result = getTextFromMimeMultipart(mimeMultipart);
} else {
Object content = message.getContent();
result = content.toString();
}
return result;
}
示例5: extractUrlFromMail
import javax.mail.Message; //导入方法依赖的package包/类
public static String extractUrlFromMail(Message message) throws IOException, MessagingException {
String body = (String) message.getContent();
Pattern pattern = Pattern.compile(".*http://localhost:8080(.*)((\r\n)|(\n)).*");
Matcher matcher = pattern.matcher(body);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
示例6: readLatestEmailWithSubject
import javax.mail.Message; //导入方法依赖的package包/类
/**
* Reads the latest email with the given subject from the email inbox.
*
* @param subject
* the email subject
* @return the email body or null if no email was found
* @throws Exception
*/
public String readLatestEmailWithSubject(String subject) throws Exception {
Store store = mailSession.getStore();
store.connect();
Folder folder = store.getFolder(MAIL_INBOX);
folder.open(Folder.READ_WRITE);
Message[] messages = null;
messages = folder.search(new SubjectTerm(subject));
String body = null;
if (messages.length > 0) {
Message latest = messages[0];
for (Message m : messages) {
if (latest.getSentDate().compareTo(m.getSentDate()) < 0) {
latest = m;
}
}
body = (String) latest.getContent();
}
folder.close(false);
store.close();
return body;
}