Search in sources :

Example 1 with MailService

use of com.gitblit.service.MailService in project gitblit by gitblit.

the class GitblitAuthority method loadUsers.

private IUserService loadUsers(File folder) {
    File file = new File(folder, "gitblit.properties");
    if (!file.exists()) {
        return null;
    }
    gitblitSettings = new FileSettings(file.getAbsolutePath());
    mail = new MailService(gitblitSettings);
    String us = gitblitSettings.getString(Keys.realm.userService, "${baseFolder}/users.conf");
    String ext = us.substring(us.lastIndexOf(".") + 1).toLowerCase();
    IUserService service = null;
    if (!ext.equals("conf") && !ext.equals("properties") && ext.contains("userservice")) {
        String realm = ext.substring(0, ext.indexOf("userservice"));
        us = gitblitSettings.getString(MessageFormat.format("realm.{0}.backingUserService", realm), "${baseFolder}/users.conf");
    }
    if (us.endsWith(".conf")) {
        service = new ConfigUserService(FileUtils.resolveParameter(Constants.baseFolder$, folder, us));
    } else {
        throw new RuntimeException("Unsupported user service: " + us);
    }
    service = new ConfigUserService(FileUtils.resolveParameter(Constants.baseFolder$, folder, us));
    return service;
}
Also used : MailService(com.gitblit.service.MailService) FileSettings(com.gitblit.FileSettings) IUserService(com.gitblit.IUserService) ConfigUserService(com.gitblit.ConfigUserService) File(java.io.File)

Example 2 with MailService

use of com.gitblit.service.MailService in project gitblit by gitblit.

the class MailTest method testSendMail.

@Test
public void testSendMail() throws Exception {
    FileSettings settings = new FileSettings("mailtest.properties");
    MailService mail = new MailService(settings);
    Mailing mailing = Mailing.newPlain();
    mailing.setRecipients(settings.getStrings(Keys.mail.adminAddresses));
    Message message = mail.createMessage(mailing);
    message.setSubject("Test");
    message.setText("Lägger till andra stycket i ny fil. UTF-8 encoded");
    mail.queue(message);
    mail.run();
    assertTrue("mail queue is not empty!", mail.hasEmptyQueue());
}
Also used : MailService(com.gitblit.service.MailService) Message(javax.mail.Message) FileSettings(com.gitblit.FileSettings) Mailing(com.gitblit.models.Mailing) Test(org.junit.Test)

Aggregations

FileSettings (com.gitblit.FileSettings)2 MailService (com.gitblit.service.MailService)2 ConfigUserService (com.gitblit.ConfigUserService)1 IUserService (com.gitblit.IUserService)1 Mailing (com.gitblit.models.Mailing)1 File (java.io.File)1 Message (javax.mail.Message)1 Test (org.junit.Test)1