use of org.opennms.netmgt.config.javamail.SendmailMessage in project opennms by OpenNMS.
the class JavaMailAckReaderIT method createAckMessage.
private SendmailMessage createAckMessage(String gmailAccount, String noticeId, String body) {
SendmailMessage sendMsg = new SendmailMessage();
sendMsg.setTo(gmailAccount + "@gmail.com");
sendMsg.setFrom(gmailAccount + "@gmail.com");
sendMsg.setSubject("Re: Notice #" + noticeId + ":");
sendMsg.setBody(body);
return sendMsg;
}
use of org.opennms.netmgt.config.javamail.SendmailMessage in project opennms by OpenNMS.
the class JavaReadMailerTest method testReadMessagesWithSearchTerm.
/**
* Un-ignore this test with a proper gmail account
* @throws JavaMailerException
* @throws MessagingException
* @throws InterruptedException
*/
@Test
@Ignore
public void testReadMessagesWithSearchTerm() throws JavaMailerException, MessagingException, InterruptedException {
String gmailAccount = getUser();
String gmailPassword = getPassword();
JavaSendMailer sendMailer = createSendMailer(gmailAccount, gmailPassword);
String term1 = String.valueOf(Calendar.getInstance().getTimeInMillis());
Thread.sleep(2);
String term2 = String.valueOf(Calendar.getInstance().getTimeInMillis());
Thread.sleep(2);
String term3 = String.valueOf(Calendar.getInstance().getTimeInMillis());
Thread.sleep(2);
SendmailMessage sendMsg = createAckMessage(gmailAccount, "1", term1, "ack");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
sendMsg = createAckMessage(gmailAccount, "2", term2, "ack");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
sendMsg = createAckMessage(gmailAccount, "3", term3, "ack");
sendMailer.setMessage(sendMailer.buildMimeMessage(sendMsg));
sendMailer.send();
JavaReadMailer readMailer = createGoogleReadMailer(gmailAccount, gmailPassword);
// See if search finds all 3 messages
SearchTerm st = new OrTerm(new SubjectTerm(".*" + term1 + " #.*"), new SubjectTerm(".*" + term2 + " #.*"));
st = new OrTerm(st, new SubjectTerm("*." + term3 + " #.*"));
List<Message> msgs = null;
try {
msgs = readMailer.retrieveMessages(st);
} catch (JavaMailerException e) {
e.printStackTrace();
}
Assert.assertEquals(3, msgs.size());
st = new OrTerm(new SubjectTerm(".*" + term1 + " #.*"), new SubjectTerm(".*" + term2 + " #.*"));
try {
msgs = readMailer.retrieveMessages(st);
} catch (JavaMailerException e) {
e.printStackTrace();
}
// Should find only term1 and term2 messages
Assert.assertNotNull(msgs);
Assert.assertEquals(2, msgs.size());
// Delete the term1 and term2 messages
for (Message msg : msgs) {
msg.setFlag(Flag.DELETED, true);
}
// Find and delete the term3 messages
st = new SubjectTerm("*." + term3 + " #.*");
try {
msgs = readMailer.retrieveMessages(st);
} catch (JavaMailerException e) {
e.printStackTrace();
}
Assert.assertNotNull(msgs);
Assert.assertTrue(msgs.size() >= 1);
for (Message eventMsg : msgs) {
eventMsg.setFlag(Flag.DELETED, true);
}
// Make sure they're all gone
st = new OrTerm(new SubjectTerm(".*" + term1 + " #.*"), new SubjectTerm(".*" + term2 + " #.*"));
st = new OrTerm(st, new SubjectTerm("*." + term3 + " #.*"));
try {
msgs = readMailer.retrieveMessages(st);
} catch (JavaMailerException e) {
e.printStackTrace();
}
Assert.assertTrue(msgs.isEmpty());
}
use of org.opennms.netmgt.config.javamail.SendmailMessage in project opennms by OpenNMS.
the class JavaReadMailerTest method createAckMessage.
private SendmailMessage createAckMessage(String gmailAccount, String noticeId, String regards, String body) {
SendmailMessage sendMsg = new SendmailMessage();
sendMsg.setTo(gmailAccount + "@gmail.com");
sendMsg.setFrom(gmailAccount + "@gmail.com");
sendMsg.setSubject("re:" + regards + " #" + noticeId + ":");
sendMsg.setBody(body);
return sendMsg;
}
use of org.opennms.netmgt.config.javamail.SendmailMessage in project opennms by OpenNMS.
the class JavaReadMailerTest method createSendMailer.
private JavaSendMailer createSendMailer(String gmailAccount, String gmailPassword) throws JavaMailerException {
SendmailConfig config = new SendmailConfig();
config.setAttemptInterval(1000l);
config.setDebug(true);
config.setName("test");
SendmailMessage sendmailMessage = new SendmailMessage();
sendmailMessage.setBody("service is down");
sendmailMessage.setFrom("bamboo.opennms@gmail.com");
sendmailMessage.setSubject("Notice #1234: service down");
sendmailMessage.setTo("bamboo.opennms@gmail.com");
config.setSendmailMessage(sendmailMessage);
SendmailHost host = new SendmailHost();
host.setHost("smtp.gmail.com");
host.setPort(465);
config.setSendmailHost(host);
SendmailProtocol protocol = new SendmailProtocol();
protocol.setSslEnable(true);
protocol.setTransport("smtps");
config.setSendmailProtocol(protocol);
config.setUseAuthentication(true);
config.setUseJmta(false);
UserAuth auth = new UserAuth();
auth.setUserName(gmailAccount);
auth.setPassword(gmailPassword);
config.setUserAuth(auth);
return new JavaSendMailer(config);
}
use of org.opennms.netmgt.config.javamail.SendmailMessage in project opennms by OpenNMS.
the class JavaMailAckReaderIT method createSendMailer.
private JavaSendMailer createSendMailer(String gmailAccount, String gmailPassword) throws JavaMailerException {
SendmailConfig config = new SendmailConfig();
config.setAttemptInterval(1000l);
config.setDebug(true);
config.setName("test");
SendmailMessage sendmailMessage = new SendmailMessage();
sendmailMessage.setBody("service is down");
sendmailMessage.setFrom("bamboo.opennms@gmail.com");
sendmailMessage.setSubject("Notice #1234: service down");
sendmailMessage.setTo("bamboo.opennms@gmail.com");
config.setSendmailMessage(sendmailMessage);
SendmailHost host = new SendmailHost();
host.setHost("smtp.gmail.com");
host.setPort(465);
config.setSendmailHost(host);
SendmailProtocol protocol = new SendmailProtocol();
protocol.setSslEnable(true);
protocol.setTransport("smtps");
config.setSendmailProtocol(protocol);
config.setUseAuthentication(true);
config.setUseJmta(false);
UserAuth auth = new UserAuth();
auth.setUserName(gmailAccount);
auth.setPassword(gmailPassword);
config.setUserAuth(auth);
return new JavaSendMailer(config);
}
Aggregations