当前位置: 首页>>代码示例>>Java>>正文


Java Folder.create方法代码示例

本文整理汇总了Java中javax.mail.Folder.create方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.create方法的具体用法?Java Folder.create怎么用?Java Folder.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.Folder的用法示例。


在下文中一共展示了Folder.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTestMessages

import javax.mail.Folder; //导入方法依赖的package包/类
public void createTestMessages() {
    try {
        GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");

        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();
        user.deliver(createMimeMessage("[email protected]", subject, body, null));
        user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
        user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
        user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
        user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
        user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom", 
                 Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));

        Session imapSession = greenMail.getImap().createSession();
        Store store = imapSession.getStore("imap");
        store.connect(TEST_RECIP, "password");
        
        Folder defaultFolder = store.getDefaultFolder();  
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
        
        Folder ads = defaultFolder.getFolder("Ads");
        ads.create(Folder.HOLDS_MESSAGES);   
        
        Folder spam = defaultFolder.getFolder("Spam");
        spam.create(Folder.HOLDS_MESSAGES); 
    } catch (MessagingException ex) {
        Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:32,代码来源:TestMailUtil.java

示例2: createFolder

import javax.mail.Folder; //导入方法依赖的package包/类
public void createFolder( String newFolder ){
	if ( newFolder.length() == 0 )
		return;
	
   try{
   
     Folder folderToUse = mailStore.getFolder( newFolder );
		
		if ( !folderToUse.exists() ){
			folderToUse.create( Folder.HOLDS_FOLDERS | Folder.HOLDS_MESSAGES );
		}
		
     setData( "succeeded", 	cfBooleanData.TRUE );
   
   } catch (Exception E ){
     setData( "errortext", 	new cfStringData( E.getMessage() ) );
     setData( "succeeded", 	cfBooleanData.FALSE );
   }
	
	setTotalMessages( 0 );
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:22,代码来源:cfImapConnection.java

示例3: send

import javax.mail.Folder; //导入方法依赖的package包/类
public String send()
{
  Session session = _getSession();
  Message msg = _setupMessage(new MimeMessage(session));
  if (msg == null)
  {
    _LOG.info("Could not create Message object for " + getSubject());
    return null;
  }

  try
  {
    Transport.send(msg);
  }
  catch (MessagingException me)
  {
    _showSendException(me);
    return null;
  }

  _LOG.info("Sent succesfully");

  try
  {
    Store store = _account.getStore();
    // =-=AEW Hardcoding "Sent" as the folder to save "Sent" messages
    Folder folder = store.getFolder("Sent");
    if (folder == null)
    {
      // Can "folder" be null here?
      throw new IllegalStateException("\"Sent\" folder was null");
    }
    else
    {
      if (!folder.exists())
        folder.create(Folder.HOLDS_MESSAGES);

      folder.appendMessages(new Message[]{msg});
    }
  }
  // Need to do something better;  like a "Warning: message sent, but not
  // saved" message for the user?
  catch (Exception e)
  {
    _LOG.log(Level.WARNING, "Couldn't save message in \"Sent\" folder", e);
  }

  return "sentMessage";
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:50,代码来源:NewMessageBackingBean.java

示例4: saveAsDraft

import javax.mail.Folder; //导入方法依赖的package包/类
public String saveAsDraft()
{
  _LOG.info("Beginning send of message " + getSubject());

  Session session = _getSession();
  Message msg = _setupMessage(new MimeMessage(session));
  if (msg == null)
  {
    _LOG.info("Could not create Message object for " + getSubject());
    return null;
  }

  try
  {
    Store store = _account.getStore();
    // =-=AEW Hardcoding "Drafts" as the folder to save drafts
    Folder folder = store.getFolder("Drafts");
    if (folder == null)
    {
      // Can "folder" be null here?
      throw new IllegalStateException("\"Drafts\" folder was null");
    }
    else
    {
      if (!folder.exists())
        folder.create(Folder.HOLDS_MESSAGES);
      
      folder.appendMessages(new Message[]{msg});
    }
  }
  // Need to do something better...
  catch (Exception e)
  {
    _showSendException(e);
    return null;
  }
  
  // And go back to the current message folder
  // =-=aew Should be a "popView" thing
  return "messages";
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:42,代码来源:NewMessageBackingBean.java


注:本文中的javax.mail.Folder.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。