本文整理汇总了Java中com.icegreen.greenmail.user.GreenMailUser.deliver方法的典型用法代码示例。如果您正苦于以下问题:Java GreenMailUser.deliver方法的具体用法?Java GreenMailUser.deliver怎么用?Java GreenMailUser.deliver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.icegreen.greenmail.user.GreenMailUser
的用法示例。
在下文中一共展示了GreenMailUser.deliver方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTestMessages
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的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);
}
}
示例2: handle
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
private void handle(MovingMessage msg, MailAddress mailAddress) {
try {
GreenMailUser user = userManager.getUserByEmail(mailAddress.getEmail());
if (null == user) {
String login = mailAddress.getEmail();
String email = mailAddress.getEmail();
String password = mailAddress.getEmail();
user = userManager.createUser(email, login, password);
log.info("Created user login {} for address {} with password {} because it didn't exist before.", login, email, password);
}
user.deliver(msg);
} catch (Exception e) {
log.error("Can not deliver message {} to {}", msg, mailAddress, e);
throw new RuntimeException(e);
}
msg.releaseContent();
}
示例3: testReceive
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
@Test
public void testReceive() throws MessagingException, IOException {
//Start all email servers using non-default ports.
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.start();
//Use random content to avoid potential residual lingering problems
final String subject = GreenMailUtil.random();
final String body = GreenMailUtil.random();
MimeMessage message = createMimeMessage(subject, body, greenMail); // Construct message
GreenMailUser user = greenMail.setUser("[email protected]", "waelc", "soooosecret");
user.deliver(message);
assertEquals(1, greenMail.getReceivedMessages().length);
// --- Place your retrieve code here
} finally {
greenMail.stop();
}
}
示例4: receiveMailViaPop3Server
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
@Test(description = "Test the scenario: receiving messages via pop3 server")
public void receiveMailViaPop3Server()
throws IOException, MessagingException, InterruptedException, ServerConnectorException {
// create user on mail server
GreenMailUser user = mailServer.setUser(ADDRESS, USER_NAME, PASSWORD);
// create an e-mail message using javax.mail ..
MimeMessage message = new MimeMessage((Session) null);
message.setFrom(new InternetAddress(EMAIL_FROM));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(ADDRESS));
message.setSubject(EMAIL_SUBJECT);
message.setContent(EMAIL_TEXT, EmailTestConstant.CONTENT_TYPE_TEXT_PLAIN);
// use greenmail to store the message
user.deliver(message);
EmailConnectorFactory emailConnectorFactory = new EmailConnectorFactoryImpl();
TestEmailMessageListener messageListener = new TestEmailMessageListener();
messageListener.setNumberOfEvent(1);
EmailServerConnector emailServerConnector = emailConnectorFactory
.createEmailServerConnector("testEmail", emailProperties);
emailServerConnector.init();
emailServerConnector.start(messageListener);
messageListener.waitForEvent();
Assert.assertEquals(messageListener.subject, EMAIL_SUBJECT);
Thread.sleep(1000);
Message[] messages = mailServer.getReceivedMessages();
Assert.assertEquals(messages.length, 0, "Since the message is deleted by"
+ " the pop3 server after reading the message content, Number of messages in the"
+ " 'INBOX' after processing is 'zero'.");
emailServerConnector.stop();
}
示例5: actionAfterProcessedIsInvalidTestCase
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
@Test(description = "Test the scenario: action after processes invalid one",
expectedExceptions = EmailConnectorException.class)
public void actionAfterProcessedIsInvalidTestCase()
throws IOException, MessagingException, InterruptedException, ServerConnectorException {
// create user on mail server
GreenMailUser user = mailServer.setUser(ADDRESS, USER_NAME, PASSWORD);
emailProperties.put(EmailTestConstant.ACTION_AFTER_PROCESSED, "FLAGGED");
// create an e-mail message using javax.mail ..
MimeMessage message = new MimeMessage((Session) null);
message.setFrom(new InternetAddress(EMAIL_FROM));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(ADDRESS));
message.setSubject(EMAIL_SUBJECT);
message.setContent(EMAIL_TEXT, EmailTestConstant.CONTENT_TYPE_TEXT_PLAIN);
// use greenmail to store the message
user.deliver(message);
EmailConnectorFactory emailConnectorFactory = new EmailConnectorFactoryImpl();
TestEmailMessageListener messageListener = new TestEmailMessageListener();
messageListener.setNumberOfEvent(1);
EmailServerConnector emailServerConnector = emailConnectorFactory
.createEmailServerConnector("testEmail", emailProperties);
emailServerConnector.init();
emailServerConnector.start(messageListener);
messageListener.waitForEvent();
Assert.assertEquals(messageListener.subject, EMAIL_SUBJECT);
Thread.sleep(1000);
Message[] messages = mailServer.getReceivedMessages();
Assert.assertEquals(messages.length, 0, "Since the message is deleted by"
+ " the pop3 server after reading the message content, Number of messages in the"
+ " 'INBOX' after processing is 'zero'.");
emailServerConnector.stop();
}
示例6: doesNotDeleteMessageNotMarkedForDeletion
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
@Test
public void doesNotDeleteMessageNotMarkedForDeletion() throws Exception {
GreenMailUser user = mockPop3Server.setUser(USERNAME, USERNAME, PASSWORD);
user.deliver(createSimpleMessage());
assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
// Let Gerrit handle emails
mailReceiver.handleEmails(false);
// Check that the message is still present
assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
}
示例7: deletesMessageMarkedForDeletion
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
@Test
public void deletesMessageMarkedForDeletion() throws Exception {
GreenMailUser user = mockPop3Server.setUser(USERNAME, USERNAME, PASSWORD);
user.deliver(createSimpleMessage());
assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(1);
// Mark the message for deletion
mailReceiver.requestDeletion(mockPop3Server.getReceivedMessages()[0].getMessageID());
// Let Gerrit handle emails
mailReceiver.handleEmails(false);
// Check that the message was deleted
assertThat(mockPop3Server.getReceivedMessages().length).isEqualTo(0);
}
示例8: testReceive
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
@Test
public void testReceive() throws MessagingException {
GreenMailUser user = greenMail.setUser("[email protected]", "login-id", "password");
user.deliver(createMimeMessage()); // You can either create a more complex message...
GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]",
"subject", "body"); // ...or use the default messages
assertEquals(2, greenMail.getReceivedMessages().length); // // --- Place your POP3 or IMAP retrieve code here
}
示例9: deliverMassage
import com.icegreen.greenmail.user.GreenMailUser; //导入方法依赖的package包/类
/**
* Method implemented to create and deliver the email to green mail server using given parameters.
*
* @param user Instance of GreenMailUser which is going to use.
* @param content Content which is needed to be set in the email.
* @param subject Subject which is needed to be set in the email.
* @param from From Address of the email which is needed to be set in the email.
* @param to To Address which is needed to be set in the email.
* @param cc CC Address which is needed to be set in the email.
* @param bcc BCC Address which is needed to be set in the email.
* @param contentType Content type which is needed to be set in the email.
* @throws MessagingException Throw MessagingException if error is occurred while creating the Message.
*/
private void deliverMassage(GreenMailUser user, String content, String subject, String from, String to, String cc,
String bcc, String contentType) throws MessagingException {
MimeMessage message = new MimeMessage((Session) null);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc));
message.setSubject(subject);
message.setContent(content, contentType);
user.deliver(message);
}