本文整理汇总了Java中javax.mail.Folder.getMessages方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.getMessages方法的具体用法?Java Folder.getMessages怎么用?Java Folder.getMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Folder
的用法示例。
在下文中一共展示了Folder.getMessages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEmail
import javax.mail.Folder; //导入方法依赖的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: deleteMails
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* Connect to the mail server and delete all mails.
*/
public void deleteMails() throws MessagingException {
Folder folder = getStore().getFolder(MAIL_INBOX);
folder.open(Folder.READ_WRITE);
// Get folder's list of messages.
Message[] messages = folder.getMessages();
// Retrieve message headers for each message in folder.
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
folder.fetch(messages, profile);
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
示例3: changeStatus
import javax.mail.Folder; //导入方法依赖的package包/类
public void changeStatus( String folderName, long mailIDs[], Flags.Flag newFlag, boolean value ){
try{
Folder folderToUse = mailStore.getFolder(folderName);
folderToUse.open( Folder.READ_WRITE );
Flags f = new Flags();
f.add( newFlag );
Message mlist[];
if ( folderToUse instanceof UIDFolder )
mlist = ((UIDFolder)folderToUse).getMessagesByUID( mailIDs );
else
mlist = folderToUse.getMessages( returnToInts(mailIDs) );
for ( int x=0; x < mlist.length; x++ )
mlist[x].setFlags( f, value );
folderToUse.close( true );
setData( "succeeded", cfBooleanData.TRUE );
} catch (Exception E ){
setData( "errortext", new cfStringData( E.getMessage() ) );
setData( "succeeded", cfBooleanData.FALSE );
}
}
示例4: getMessages
import javax.mail.Folder; //导入方法依赖的package包/类
protected Message[] getMessages(Folder folder, DeleteMailRequest request) throws MessagingException {
if (request.getMails() != null) {
LOGGER.debug("delete mails: {}", request.getMails());
List<String> messageIds = collectMessageIds(request.getMails());
return getMessagesByIds(folder, messageIds);
} else if (request.getMessageIds() != null) {
LOGGER.debug("delete mails with message ids: {}", request.getMessageIds());
return getMessagesByIds(folder, request.getMessageIds());
} else {
LOGGER.debug("delete mails with message numbers: {}", request.getMessageNumbers());
int[] numbers = request.getMessageNumbers().stream().mapToInt(i -> i).toArray();
return folder.getMessages(numbers);
}
}
示例5: deleteAllEmails
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* Delete all emails in the inbox.
*
* @param protocol protocol used to connect to the server
* @throws MessagingException if we're unable to connect to the store
*/
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
Folder inbox = null;
Store store = getConnection(user, protocol);
try {
inbox = store.getFolder(EMAIL_INBOX);
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
log.info("Deleted email Subject : " + message.getSubject());
}
} finally {
if (inbox != null) {
inbox.close(true);
}
if (store != null) {
store.close();
}
}
}
示例6: isMailReceived
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* Check whether email received by reading the emails.
*
* @param protocol to connect to the store
* @param user whose mail store should be connected
* @param subject the subject of the mail to search
* @return
* @throws MessagingException when unable to connect to the store
*/
public static boolean isMailReceived(String protocol, GreenMailUser user, String subject)
throws MessagingException {
Store store = getConnection(user, protocol);
Folder folder = store.getFolder(EMAIL_INBOX);
folder.open(Folder.READ_ONLY);
boolean isReceived = false;
Message[] messages = folder.getMessages();
for (Message message : messages) {
if (message.getSubject().contains(subject)) {
log.info("Found the Email with Subject : " + subject);
isReceived = true;
break;
}
}
return isReceived;
}
示例7: testSendingAndReceiving
import javax.mail.Folder; //导入方法依赖的package包/类
@Test
public void testSendingAndReceiving() throws MessagingException {
Session session = EmailUtils.getGMailSession(EmailUtils.user, EmailUtils.pass);
String key = (new Long(System.currentTimeMillis())).toString();
EmailUtils.postMail(session, EmailUtils.user, "test" + key, "testmsg" + key);
Folder inbox = EmailUtils.openPop3InboxReadWrite(session);
Folder trash = EmailUtils.openPop3TrashReadWrite(session);
boolean emailReceived = false;
for (Message m : inbox.getMessages()) {
if (m.getSubject().startsWith("test" + key)) {
emailReceived = true;
Message[] m_array = inbox.getMessages(m.getMessageNumber(), m.getMessageNumber());
// delete test mail
inbox.copyMessages(m_array, trash);
m.setFlag(Flags.Flag.DELETED, true);
}
}
EmailUtils.closeFolder(inbox);
EmailUtils.closeFolder(trash);
assertTrue(emailReceived);
}
示例8: main
import javax.mail.Folder; //导入方法依赖的package包/类
public static void main(String[] args) throws MessagingException {
String url = "https://outlook.office365.com/ews/exchange.asmx";
Properties properties = new Properties();
properties.setProperty("org.sourceforge.net.javamail4ews.util.Util.EnableServiceTrace", "true");
Session session = Session.getInstance(properties);
System.out.println("retrieving the store");
//Get the EWS store implementation
Store store = session.getStore("ewsstore");
System.out.println("done");
//Connect to the Exchange server - No port required.
//Also connect() might be used if the session is initalized with the known mail.* properties
System.out.println(String.format("connecting to %s", url));
store.connect(url,
"[email protected]",
"p4ssw0rd");
System.out.println(String.format("connected to %s", url));
System.out.println(String.format("get default folder", url));
Folder folder = store.getDefaultFolder();
System.out.println(String.format("open default folder as read-only"));
folder.open(Folder.READ_ONLY);
System.out.println(String.format("done"));
Message[] messages = folder.getMessages();
System.out.println(String.format("there is %d messages", messages.length));
System.out.println(messages[0].getFrom());
}
示例9: checkInbox
import javax.mail.Folder; //导入方法依赖的package包/类
public void checkInbox(int mode) throws MessagingException, IOException {
if (mode == 0) {
return;
}
boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
System.out.println(action + " INBOX for " + from);
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
if (msgs.length == 0 && show) {
System.out.println("No messages in inbox");
}
for (Message msg2 : msgs) {
MimeMessage msg = (MimeMessage) msg2;
if (show) {
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + msg.getContent());
}
if (clear) {
msg.setFlag(Flags.Flag.DELETED, true);
}
}
inbox.close(true);
store.close();
System.out.println();
}
示例10: checkInboxSave
import javax.mail.Folder; //导入方法依赖的package包/类
public void checkInboxSave(int mode) throws MessagingException, IOException {
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
for (Message msg2 : msgs) {
POP3Message msg = (POP3Message) msg2;
Object object = msg.getContent();
if (object instanceof Multipart) {
Multipart multipart = (Multipart) object;
for (int i = 0, n = multipart.getCount(); i < n; i++) {
MailClient.handlePart(multipart.getBodyPart(i));
}
}
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + object);
}
inbox.close(true);
store.close();
}
示例11: _getEmail
import javax.mail.Folder; //导入方法依赖的package包/类
public MessageWrapper _getEmail( String hostName, MessageFilter[] messageFilters, Map<String, String> propertyMap )
{
Properties mailProps = new Properties();
mailProps.putAll( propertyMap );
List<Message> messageList = new ArrayList<Message>( 10 );
MessageWrapper messageWrapper = null;
try
{
Session emailSession = Session.getDefaultInstance( mailProps );
Store store = emailSession.getStore( propertyMap.get( PROTOCOL ) );
store.connect( hostName, propertyMap.get( USER_NAME ), propertyMap.get( PASSWORD ) );
Folder emailFolder = store.getFolder( propertyMap.get( FOLDER_NAME ) != null ? propertyMap.get( FOLDER_NAME ) : DEFAULT_FOLDER_NAME );
emailFolder.open( Folder.READ_WRITE );
Message[] messages = emailFolder.getMessages();
int messageCount = emailFolder.getMessageCount();
if ( messageCount > MAX_MESSAGES )
messageCount = MAX_MESSAGES;
if ( log.isInfoEnabled() )
log.info( "Processing " + messageCount + " messages" );
for ( int i = 0; i < messageCount; i++ )
{
if ( applyFilters( messages[i], messageFilters ) )
{
messageList.add( messages[i] );
}
}
if ( messageList.size() == 0 )
throw new ScriptException( "Failed to find any email messages that met the criteria" );
Collections.sort( messageList, new DateComparator() );
String messageContent = null;
String contentType = messageList.get( 0 ).getContentType();
if ( contentType.startsWith( "text/" ) )
messageContent = messageList.get( 0 ).getContent().toString();
else if ( messageList.get( 0 ).isMimeType( "multipart/*" ) )
messageContent = getTextFromMimeMultipart( (MimeMultipart) messageList.get( 0 ).getContent() );
else
messageContent = messageList.get( 0 ).getContent().getClass().getName();
messageWrapper = new MessageWrapper( messageList.size(), messageList.get( 0 ).getFrom()[0].toString(), messageList.get( 0 ).getSubject(), messageContent, contentType );
emailFolder.close( false );
store.close();
}
catch ( Exception e )
{
e.printStackTrace();
throw new ScriptException( "Failed to find email" );
}
return messageWrapper;
}
示例12: receive
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* �����ʼ�
*/
public static void receive() throws Exception {
// �����ӷ������ĻỰ��Ϣ
Properties props = new Properties();
props.setProperty("mail.store.protocol", "pop3"); // ��
props.setProperty("mail.pop3.port", "110"); // �˿�
props.setProperty("mail.pop3.host", "pop3.sina.com"); // pop3������
// ����Sessionʵ������
Session session = Session.getInstance(props);
Store store = session.getStore("pop3");
store.connect("[email protected]", "mh899821671104");
// ����ռ���
Folder folder = store.getFolder("INBOX");
/* Folder.READ_ONLY��ֻ��Ȩ��
* Folder.READ_WRITE���ɶ���д���������ʼ���״̬��
*/
folder.open(Folder.READ_WRITE); //���ռ���
// ����POP3Э������֪�ʼ���״̬,����getUnreadMessageCount�õ������ռ�����ʼ�����
System.out.println("δ���ʼ���: " + folder.getUnreadMessageCount());
// ����POP3Э������֪�ʼ���״̬,��������õ��Ľ��ʼ�ն���Ϊ0
System.out.println("ɾ���ʼ���: " + folder.getDeletedMessageCount());
System.out.println("���ʼ�: " + folder.getNewMessageCount());
// ����ռ����е��ʼ�����
System.out.println("�ʼ�����: " + folder.getMessageCount());
// �õ��ռ����е������ʼ�,������
Message[] messages = folder.getMessages();
parseMessage(messages);
//�ͷ���Դ
folder.close(true);
store.close();
}
示例13: main
import javax.mail.Folder; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Properties props = new Properties();
String host = "pop.mailinator.com";
String username = "x-test-m";
String password = "mypwdxxx";
String provider = "pop3";
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore(provider);
store.connect(host, username, password);
Folder inbox = store.getFolder("INBOX");
if (inbox == null) {
System.out.println("No INBOX");
System.exit(1);
}
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("Message " + (i + 1));
messages[i].writeTo(System.out);
}
inbox.close(false);
store.close();
}
示例14: browseMessageFromFolder
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* 根据邮件夹对象浏览邮件
* @param folder
* @throws MessagingException
* @throws IOException
*/
private Object browseMessageFromFolder(Folder folder) throws Exception {
// TODO Auto-generated method stub
folder.open(Folder.READ_ONLY);
System.out.println("总共有"+folder.getMessageCount()+"封邮件");
System.out.println("总共有"+folder.getUnreadMessageCount()+"封未读邮件");
Message[] messages=folder.getMessages();
return call(messages);
/*for (int i = 1; i <=messages.length; i++) {
System.out.println("这是第"+i+"封邮件");
//getMessageHeader(folder.getMessage(i));
writeSubjectToOutPutStream(folder.getMessage(i));;
}*/
//folder.close(false);
}
示例15: receive
import javax.mail.Folder; //导入方法依赖的package包/类
/**
* 接收邮件
*/
public static void receive() throws Exception {
// 准备连接服务器的会话信息
Properties props = new Properties();
props.setProperty("mail.store.protocol", "pop3"); // 协议
props.setProperty("mail.pop3.port", "995"); // 端口
props.setProperty("mail.pop3.host", "pop3.live.com"); // pop3服务器
// 创建Session实例对象
Session session = Session.getInstance(props);
Store store = session.getStore("pop3");
store.connect("[email protected]", "Mo8yOU8u");
// 获得收件箱
Folder folder = store.getFolder("INBOX");
/* Folder.READ_ONLY:只读权限
* Folder.READ_WRITE:可读可写(可以修改邮件的状态)
*/
folder.open(Folder.READ_WRITE); //打开收件箱
// 由于POP3协议无法获知邮件的状态,所以getUnreadMessageCount得到的是收件箱的邮件总数
System.out.println("未读邮件数: " + folder.getUnreadMessageCount());
// 由于POP3协议无法获知邮件的状态,所以下面得到的结果始终都是为0
System.out.println("删除邮件数: " + folder.getDeletedMessageCount());
System.out.println("新邮件: " + folder.getNewMessageCount());
// 获得收件箱中的邮件总数
System.out.println("邮件总数: " + folder.getMessageCount());
// 得到收件箱中的所有邮件,并解析
Message[] messages = folder.getMessages();
parseMessage(messages);
//释放资源
folder.close(true);
store.close();
}