Search in sources :

Example 1 with SendmailMessage

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;
}
Also used : SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage)

Example 2 with SendmailMessage

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());
}
Also used : OrTerm(javax.mail.search.OrTerm) Message(javax.mail.Message) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) SearchTerm(javax.mail.search.SearchTerm) SubjectTerm(javax.mail.search.SubjectTerm) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SendmailMessage

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;
}
Also used : SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage)

Example 4 with SendmailMessage

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);
}
Also used : SendmailProtocol(org.opennms.netmgt.config.javamail.SendmailProtocol) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) SendmailConfig(org.opennms.netmgt.config.javamail.SendmailConfig) UserAuth(org.opennms.netmgt.config.javamail.UserAuth) SendmailHost(org.opennms.netmgt.config.javamail.SendmailHost)

Example 5 with SendmailMessage

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);
}
Also used : SendmailProtocol(org.opennms.netmgt.config.javamail.SendmailProtocol) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) JavaSendMailer(org.opennms.javamail.JavaSendMailer) SendmailConfig(org.opennms.netmgt.config.javamail.SendmailConfig) UserAuth(org.opennms.netmgt.config.javamail.UserAuth) SendmailHost(org.opennms.netmgt.config.javamail.SendmailHost)

Aggregations

SendmailMessage (org.opennms.netmgt.config.javamail.SendmailMessage)10 SendmailProtocol (org.opennms.netmgt.config.javamail.SendmailProtocol)4 MimeMessage (javax.mail.internet.MimeMessage)3 JavaSendMailer (org.opennms.javamail.JavaSendMailer)3 SendmailConfig (org.opennms.netmgt.config.javamail.SendmailConfig)3 SendmailHost (org.opennms.netmgt.config.javamail.SendmailHost)3 UserAuth (org.opennms.netmgt.config.javamail.UserAuth)3 Message (javax.mail.Message)2 MessagingException (javax.mail.MessagingException)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)2 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 OrTerm (javax.mail.search.OrTerm)1 SearchTerm (javax.mail.search.SearchTerm)1 SubjectTerm (javax.mail.search.SubjectTerm)1 JavaMailerException (org.opennms.javamail.JavaMailerException)1 ReadmailConfig (org.opennms.netmgt.config.javamail.ReadmailConfig)1