Search in sources :

Example 1 with Mailing

use of com.gitblit.models.Mailing in project gitblit by gitblit.

the class NotificationManager method sendHtmlMail.

/**
	 * Notify users by email of something.
	 *
	 * @param subject
	 * @param message
	 * @param toAddresses
	 */
@Override
public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {
    Mailing mail = Mailing.newHtml();
    mail.subject = subject;
    mail.content = message;
    mail.setRecipients(toAddresses);
    send(mail);
}
Also used : Mailing(com.gitblit.models.Mailing)

Example 2 with Mailing

use of com.gitblit.models.Mailing in project gitblit by gitblit.

the class NotificationManager method sendMailToAdministrators.

/**
	 * Notify the administrators by email.
	 *
	 * @param subject
	 * @param message
	 */
@Override
public void sendMailToAdministrators(String subject, String message) {
    Mailing mail = Mailing.newPlain();
    mail.subject = subject;
    mail.content = message;
    mail.setRecipients(settings.getStrings(Keys.mail.adminAddresses));
    send(mail);
}
Also used : Mailing(com.gitblit.models.Mailing)

Example 3 with Mailing

use of com.gitblit.models.Mailing in project gitblit by gitblit.

the class GitblitAuthority method sendEmail.

private boolean sendEmail(UserModel user, X509Metadata metadata, File zip) {
    // send email
    try {
        if (mail.isReady()) {
            Mailing mailing = Mailing.newPlain();
            if (user.getPreferences().getLocale() != null)
                mailing.subject = MessageFormat.format(ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", user.getPreferences().getLocale()).getString("gb.emailClientCertificateSubject"), metadata.serverHostname);
            else
                mailing.subject = MessageFormat.format(ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", Locale.ENGLISH).getString("gb.emailClientCertificateSubject"), metadata.serverHostname);
            mailing.setRecipients(user.emailAddress);
            File fileMailTmp = null;
            String body = null;
            if ((fileMailTmp = new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl" + "_" + user.getPreferences().getLocale())).exists())
                body = X509Utils.processTemplate(fileMailTmp, metadata);
            else {
                fileMailTmp = new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl");
                body = X509Utils.processTemplate(fileMailTmp, metadata);
            }
            if (StringUtils.isEmpty(body)) {
                body = MessageFormat.format("Hi {0}\n\nHere is your client certificate bundle.\nInside the zip file are installation instructions.", user.getDisplayName());
            }
            mailing.content = body;
            mailing.addAttachment(zip);
            Message message = mail.createMessage(mailing);
            mail.sendNow(message);
            return true;
        } else {
            JOptionPane.showMessageDialog(GitblitAuthority.this, "Sorry, the mail server settings are not configured properly.\nCan not send email.", Translation.get("gb.error"), JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception e) {
        Utils.showException(GitblitAuthority.this, e);
    }
    return false;
}
Also used : Message(javax.mail.Message) Mailing(com.gitblit.models.Mailing) File(java.io.File) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException)

Example 4 with Mailing

use of com.gitblit.models.Mailing in project gitblit by gitblit.

the class TicketNotifier method queueMailing.

/**
	 * Queues an update notification.
	 *
	 * @param ticket
	 * @return a notification object used for testing
	 */
public Mailing queueMailing(TicketModel ticket) {
    try {
        // format notification message
        String markdown = formatLastChange(ticket);
        StringBuilder html = new StringBuilder();
        html.append("<head>");
        html.append(readStyle());
        html.append(readViewTicketAction(ticket));
        html.append("</head>");
        html.append("<body>");
        html.append(MarkdownUtils.transformGFM(settings, markdown, ticket.repository));
        html.append("</body>");
        Mailing mailing = Mailing.newHtml();
        mailing.from = getUserModel(ticket.updatedBy == null ? ticket.createdBy : ticket.updatedBy).getDisplayName();
        mailing.subject = getSubject(ticket);
        mailing.content = html.toString();
        mailing.id = "ticket." + ticket.number + "." + StringUtils.getSHA1(ticket.repository + ticket.number);
        setRecipients(ticket, mailing);
        queue.put(ticket.number, mailing);
        return mailing;
    } catch (Exception e) {
        Logger.getLogger(getClass()).error("failed to queue mailing for #" + ticket.number, e);
    }
    return null;
}
Also used : Mailing(com.gitblit.models.Mailing) IOException(java.io.IOException)

Example 5 with Mailing

use of com.gitblit.models.Mailing in project gitblit by gitblit.

the class NotificationManager method sendMail.

/**
	 * Notify users by email of something.
	 *
	 * @param subject
	 * @param message
	 * @param toAddresses
	 */
@Override
public void sendMail(String subject, String message, Collection<String> toAddresses) {
    Mailing mail = Mailing.newPlain();
    mail.subject = subject;
    mail.content = message;
    mail.setRecipients(toAddresses);
    send(mail);
}
Also used : Mailing(com.gitblit.models.Mailing)

Aggregations

Mailing (com.gitblit.models.Mailing)7 IOException (java.io.IOException)2 Message (javax.mail.Message)2 Test (org.junit.Test)2 FileSettings (com.gitblit.FileSettings)1 TicketModel (com.gitblit.models.TicketModel)1 Change (com.gitblit.models.TicketModel.Change)1 Patchset (com.gitblit.models.TicketModel.Patchset)1 MailService (com.gitblit.service.MailService)1 TicketNotifier (com.gitblit.tickets.TicketNotifier)1 File (java.io.File)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1