本文整理汇总了Java中com.icegreen.greenmail.util.GreenMailUtil.sendTextEmail方法的典型用法代码示例。如果您正苦于以下问题:Java GreenMailUtil.sendTextEmail方法的具体用法?Java GreenMailUtil.sendTextEmail怎么用?Java GreenMailUtil.sendTextEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.icegreen.greenmail.util.GreenMailUtil
的用法示例。
在下文中一共展示了GreenMailUtil.sendTextEmail方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAllServices
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testAllServices() throws MessagingException {
// Send messages via SMTP and secure SMTPS
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
"test1", "Test GreenMail Docker service",
ServerSetupTest.SMTP.createCopy(bindAddress));
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
"test2", "Test GreenMail Docker service",
ServerSetupTest.SMTPS.createCopy(bindAddress));
// IMAP
for (ServerSetup setup : Arrays.asList(
ServerSetupTest.IMAP.createCopy(bindAddress),
ServerSetupTest.IMAPS.createCopy(bindAddress),
ServerSetupTest.POP3.createCopy(bindAddress),
ServerSetupTest.POP3S.createCopy(bindAddress))) {
final Store store = Session.getInstance(setup.configureJavaMailSessionProperties(null, false)).getStore();
store.connect("[email protected]", "[email protected]");
try {
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
assertEquals("Can not check mails using "+store.getURLName(), 2, folder.getMessageCount());
} finally {
store.close();
}
}
}
示例2: testremoveAllMessagesInImapMailbox
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testremoveAllMessagesInImapMailbox() throws FolderException {
try (Retriever retriever = new Retriever(greenMailRule.getImap())) {
greenMailRule.setUser("[email protected]", "pwd");
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
"Test subject", "Test message", ServerSetupTest.SMTP);
assertTrue(greenMailRule.waitForIncomingEmail(1));
greenMailRule.purgeEmailFromAllMailboxes();
Message[] messages = retriever.getMessages("[email protected]", "pwd");
assertEquals(0, messages.length);
}
}
示例3: beforeEachTest
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Before
public void beforeEachTest() throws NoSuchProviderException {
user = greenMail.setUser("[email protected]", "pwd");
int numberOfMails = 10;
for (int i = 0; i < numberOfMails; i++) {
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test search " + i,
"Test message content" + i,
greenMail.getSmtp().getServerSetup());
}
greenMail.waitForIncomingEmail(numberOfMails);
store = greenMail.getImap().createStore();
}
示例4: ensureThatMailCanActuallyBeSentToTheAllocatedPort
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void ensureThatMailCanActuallyBeSentToTheAllocatedPort() throws Exception {
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "subject", "body", smtpServerAtPort(greenMail.getSmtp().getPort()));
MimeMessage[] emails = greenMail.getReceivedMessages();
assertThat(emails.length, is(1));
}
示例5: testEscapeSubject
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testEscapeSubject() throws MessagingException, IOException {
String to = "[email protected]";
String subject = "Subject?<>/|\\\\.%\\\"*?:{[]}!";
greenMail.setUser(to, to);
final String from = "[email protected]";
GreenMailUtil.sendTextEmail(to, from, subject, "msg", greenMail.getSmtp().getServerSetup());
greenMail.waitForIncomingEmail(5000, 1);
retrieveAndCheck(greenMail.getPop3(), to, from, subject);
retrieveAndCheck(greenMail.getImap(), to, from, subject);
}
示例6: testRenameINBOXFolder
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
/**
*
* https://tools.ietf.org/html/rfc3501#page-37 :
* <q>
* Renaming INBOX is permitted, and has special behavior. It moves
* all messages in INBOX to a new mailbox with the given name,
* leaving INBOX empty. If the server implementation supports
* inferior hierarchical names of INBOX, these are unaffected by a
* rename of INBOX.
* </q>
*
* @throws MessagingException
* @throws InterruptedException
*/
@Test
public void testRenameINBOXFolder() throws MessagingException, InterruptedException {
greenMail.setUser("[email protected]", "pwd");
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test subject",
"Test message", greenMail.getSmtp().getServerSetup());
final IMAPStore store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
// Create some folders
Folder inboxFolder = store.getFolder("INBOX");
assertTrue(inboxFolder.exists());
inboxFolder.open(Folder.READ_ONLY);
assertEquals(1, inboxFolder.getMessages().length);
Folder inboxRenamedFolder = store.getFolder("INBOX-renamed");
assertFalse(inboxRenamedFolder.exists());
inboxFolder.close(true);
inboxFolder.renameTo(inboxRenamedFolder);
assertTrue(inboxRenamedFolder.exists());
inboxRenamedFolder.open(Folder.READ_ONLY);
assertEquals(1, inboxRenamedFolder.getMessages().length);
inboxFolder = store.getFolder("INBOX");
assertTrue(inboxFolder.exists());
inboxFolder.open(Folder.READ_ONLY);
assertEquals(0, inboxFolder.getMessages().length);
} finally {
store.close();
}
}
示例7: testFolderRequiringEscaping
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testFolderRequiringEscaping() throws MessagingException {
greenMail.setUser("[email protected]", "pwd");
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "test subject", "", greenMail.getSmtp().getServerSetup());
final IMAPStore store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
// Create some folders
Folder inboxFolder = store.getFolder("INBOX");
inboxFolder.open(Folder.READ_ONLY);
final Folder folderRequiringEscaping = inboxFolder.getFolder("requires escaping Ä");
assertTrue(folderRequiringEscaping.create(Folder.HOLDS_FOLDERS | Folder.HOLDS_MESSAGES));
folderRequiringEscaping.open(Folder.READ_WRITE);
assertEquals(0, folderRequiringEscaping.getMessageCount());
assertEquals(1, inboxFolder.getMessageCount());
inboxFolder.copyMessages(inboxFolder.getMessages(), folderRequiringEscaping);
folderRequiringEscaping.expunge(); // invalidates folder cache
assertEquals(1, folderRequiringEscaping.getMessageCount());
} finally {
store.close();
}
}
示例8: testUIDExpunge
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testUIDExpunge() throws MessagingException {
greenMail.setUser("[email protected]", "pwd");
// Create some test emails
int numberOfEmails = 10;
long[] uids = new long[numberOfEmails];
for (int i = 0; i < numberOfEmails; i++) {
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test UID expunge #" + i,
"Test message", greenMail.getSmtp().getServerSetup());
}
final IMAPStore store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
IMAPFolder folder = (IMAPFolder) store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
assertEquals(numberOfEmails, messages.length);
// Mark even as deleted ...
Message[] msgsForDeletion = new Message[uids.length / 2];
for (int i = 0; i < messages.length; i++) {
assertFalse(messages[i].getFlags().contains(Flags.Flag.DELETED));
uids[i] = folder.getUID(messages[i]);
if (i % 2 == 0) { // Deleted
messages[i].setFlag(Flags.Flag.DELETED, true);
msgsForDeletion[i / 2] = messages[i];
}
}
// ... and expunge (with UID)
folder.expunge(msgsForDeletion);
// Check
for (int i = 0; i < uids.length; i++) {
final Message message = folder.getMessageByUID(uids[i]);
if (i % 2 == 0) { // Deleted
assertNull(message);
} else {
assertTrue("" + i, !message.isExpunged());
assertTrue("" + i, !message.getFlags().contains(Flags.Flag.DELETED));
}
}
} finally {
store.close();
}
}
示例9: testAppend
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testAppend() throws MessagingException {
greenMail.setUser("[email protected]", "pwd");
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test Append",
"Test message", greenMail.getSmtp().getServerSetup());
final IMAPStore store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
IMAPFolder inboxFolder = (IMAPFolder) store.getFolder("INBOX");
inboxFolder.open(Folder.READ_WRITE);
Message[] messages = inboxFolder.getMessages();
assertEquals(1, messages.length);
Message message = messages[0];
Message[] toBeAppended = new Message[]{
new MimeMessage((MimeMessage) message) // Copy
};
toBeAppended[0].setSubject("testAppend#1");
inboxFolder.appendMessages(toBeAppended);
messages = inboxFolder.getMessages();
assertEquals(2, messages.length);
// UIDPLUS
toBeAppended[0] = new MimeMessage((MimeMessage) message);
toBeAppended[0].setSubject("testAppend#2");
final AppendUID[] appendUIDs = inboxFolder.appendUIDMessages(toBeAppended); // Copy again
long uid = appendUIDs[0].uid;
Message newMsg = inboxFolder.getMessageByUID(uid);
assertEquals(toBeAppended[0].getSubject(), newMsg.getSubject());
assertTrue(appendUIDs[0].uidvalidity == inboxFolder.getUIDValidity());
messages = inboxFolder.getMessages();
assertEquals(3, messages.length);
} finally {
store.close();
}
}
示例10: testExpunge
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testExpunge() throws MessagingException {
greenMail.setUser("[email protected]", "pwd");
for (int i = 0; i < 6; i++) {
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Test subject #" + i,
"Test message", ServerSetupTest.SMTP);
}
final IMAPStore store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
Folder inboxFolder = store.getFolder("INBOX");
inboxFolder.open(Folder.READ_WRITE);
Message[] messages = inboxFolder.getMessages();
assertEquals(6, messages.length);
inboxFolder.setFlags(new int[]{2, 3}, new Flags(DELETED), true); // 1 and 2, offset is not zero-based
assertEquals(false, inboxFolder.getMessage(1).isSet(DELETED));
assertEquals(true, inboxFolder.getMessage(2).isSet(DELETED));
assertEquals(true, inboxFolder.getMessage(3).isSet(DELETED));
assertEquals(false, inboxFolder.getMessage(4).isSet(DELETED));
assertEquals(false, inboxFolder.getMessage(5).isSet(DELETED));
assertEquals(false, inboxFolder.getMessage(6).isSet(DELETED));
assertEquals(2, inboxFolder.getDeletedMessageCount());
Message[] expunged = inboxFolder.expunge();
assertEquals(2, expunged.length);
messages = inboxFolder.getMessages();
assertEquals(4, messages.length);
assertEquals("Test subject #0", messages[0].getSubject());
assertEquals("Test subject #3", messages[1].getSubject());
assertEquals("Test subject #4", messages[2].getSubject());
assertEquals("Test subject #5", messages[3].getSubject());
} finally {
store.close();
}
}
示例11: testSendTextEmailTest
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testSendTextEmailTest() throws Exception {
GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
try {
greenMail.setUser("[email protected]", "pwd");
greenMail.start();
GreenMailUtil.sendTextEmail("\"Foo, Bar\" <[email protected]>", "\"Bar, Foo\" <[email protected]>",
"Test subject", "Test message", ServerSetupTest.SMTP);
greenMail.waitForIncomingEmail(1);
Store store = greenMail.getImap().createStore();
store.connect("[email protected]", "pwd");
try {
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message[] msgs = folder.getMessages();
assertTrue(null != msgs && msgs.length == 1);
Message m = msgs[0];
assertEquals("Test subject", m.getSubject());
Address a[] = m.getRecipients(Message.RecipientType.TO);
assertTrue(null != a && a.length == 1
&& a[0].toString().equals("\"Foo, Bar\" <[email protected]>"));
a = m.getFrom();
assertTrue(null != a && a.length == 1
&& a[0].toString().equals("\"Bar, Foo\" <[email protected]>"));
assertTrue(m.getContentType().toLowerCase()
.startsWith("text/plain"));
assertEquals("Test message", m.getContent());
} finally {
store.close();
}
} finally {
greenMail.stop();
}
}
示例12: testDoRun
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
@Test
public void testDoRun() throws MessagingException {
GreenMailStandaloneRunner runner = new GreenMailStandaloneRunner();
final Properties properties = new Properties();
properties.setProperty(PropertiesBasedServerSetupBuilder.GREENMAIL_VERBOSE, "");
properties.setProperty("greenmail.setup.test.smtp", "");
properties.setProperty("greenmail.setup.test.imap", "");
properties.setProperty(PropertiesBasedGreenMailConfigurationBuilder.GREENMAIL_USERS,
"test1:pwd1,test2:[email protected]");
runner.doRun(properties);
GreenMailUtil.sendTextEmail("[email protected]", "[email protected]", "Standalone test", "It worked",
ServerSetupTest.SMTP);
final Session session = runner.getGreenMail().getImap().createSession();
assertTrue(session.getDebug());
Store store = session.getStore("imap");
try {
store.connect("test2", "pwd2");
final Folder folder = store.getFolder("INBOX");
try {
folder.open(Folder.READ_ONLY);
Message msg = folder.getMessages()[0];
assertEquals("[email protected]", msg.getFrom()[0].toString());
assertEquals("Standalone test", msg.getSubject());
} finally {
folder.close(true);
}
} finally {
store.close();
}
}
示例13: sendEmail
import com.icegreen.greenmail.util.GreenMailUtil; //导入方法依赖的package包/类
/**
* Sends a mail message to the GreenMail server.
* <p/>
* Note: SMTP or SMTPS must be configured.
*
* @param theTo the <em>TO</em> field.
* @param theFrom the <em>FROM</em>field.
* @param theSubject the subject.
* @param theContent the message content.
*/
public void sendEmail(final String theTo, final String theFrom, final String theSubject,
final String theContent) {
if (null == smtpServerSetup) {
throw new IllegalStateException("Can not send mail, no SMTP or SMTPS setup found");
}
GreenMailUtil.sendTextEmail(theTo, theFrom, theSubject, theContent, smtpServerSetup);
}