Search in sources :

Example 1 with HudsonMimeMessage

use of hudson.tasks.HudsonMimeMessage in project hudson-2.x by hudson.

the class MailCommand method run.

protected int run() throws Exception {
    Hudson.getInstance().checkPermission(Item.CONFIGURE);
    Mailer.DescriptorImpl descriptor = Mailer.descriptor();
    descriptor.send(new HudsonMimeMessage(descriptor.createSession(), stdin));
    return 0;
}
Also used : Mailer(hudson.tasks.Mailer) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage)

Example 2 with HudsonMimeMessage

use of hudson.tasks.HudsonMimeMessage in project hudson-2.x by hudson.

the class BaseMailSender method getMail.

/**
     * Returns prepared email.
     *
     * @return prepared email.
     * @throws MessagingException exception if any.
     */
protected MimeMessage getMail() throws MessagingException {
    MimeMessage msg = new HudsonMimeMessage(Mailer.descriptor().createSession());
    msg.setContent("", "text/plain");
    msg.setFrom(new InternetAddress(Mailer.descriptor().getAdminAddress()));
    msg.setSentDate(new Date());
    Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>();
    StringTokenizer tokens = new StringTokenizer(recipients);
    while (tokens.hasMoreTokens()) {
        String address = tokens.nextToken();
        try {
            rcp.add(new InternetAddress(address));
        } catch (AddressException ignore) {
        // ignore bad address, but try to send to other addresses
        }
    }
    msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
    msg.setSubject(new StringBuilder().append(getSubjectPrefix()).append(" ").append(getSubject()).toString(), charset);
    msg.setText(new StringBuilder().append(getText()).append(getTextFooter()).toString(), charset);
    return msg;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternetAddress(javax.mail.internet.InternetAddress) StringTokenizer(java.util.StringTokenizer) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) Date(java.util.Date)

Example 3 with HudsonMimeMessage

use of hudson.tasks.HudsonMimeMessage in project hudson-2.x by hudson.

the class BaseBuildResultMail method createEmptyMail.

/**
     * Creates empty mail.
     *
     * @param build build.
     * @param listener listener.
     * @return empty mail.
     * @throws MessagingException exception if any.
     */
protected MimeMessage createEmptyMail(AbstractBuild<?, ?> build, BuildListener listener) throws MessagingException {
    MimeMessage msg = new HudsonMimeMessage(Mailer.descriptor().createSession());
    // TODO: I'd like to put the URL to the page in here,
    // but how do I obtain that?
    msg.setContent("", "text/plain");
    msg.setFrom(new InternetAddress(Mailer.descriptor().getAdminAddress()));
    msg.setSentDate(new Date());
    Set<InternetAddress> rcp = new LinkedHashSet<InternetAddress>();
    StringTokenizer tokens = new StringTokenizer(getRecipients());
    while (tokens.hasMoreTokens()) {
        String address = tokens.nextToken();
        if (address.startsWith("upstream-individuals:")) {
            // people who made a change in the upstream
            String projectName = address.substring("upstream-individuals:".length());
            AbstractProject up = Hudson.getInstance().getItemByFullName(projectName, AbstractProject.class);
            if (up == null) {
                listener.getLogger().println("No such project exist: " + projectName);
                continue;
            }
            includeCulpritsOf(up, build, listener, rcp);
        } else {
            // ordinary address
            try {
                rcp.add(new InternetAddress(address));
            } catch (AddressException e) {
                // report bad address, but try to send to other addresses
                e.printStackTrace(listener.error(e.getMessage()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(upstreamProjects)) {
        for (AbstractProject project : upstreamProjects) {
            includeCulpritsOf(project, build, listener, rcp);
        }
    }
    if (sendToIndividuals) {
        Set<User> culprits = build.getCulprits();
        if (debug)
            listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)==" + culprits.size());
        rcp.addAll(buildCulpritList(listener, culprits));
    }
    msg.setRecipients(Message.RecipientType.TO, rcp.toArray(new InternetAddress[rcp.size()]));
    AbstractBuild<?, ?> pb = build.getPreviousBuild();
    if (pb != null) {
        MailMessageIdAction b = pb.getAction(MailMessageIdAction.class);
        if (b != null) {
            msg.setHeader("In-Reply-To", b.messageId);
            msg.setHeader("References", b.messageId);
        }
    }
    return msg;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternetAddress(javax.mail.internet.InternetAddress) User(hudson.model.User) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) Date(java.util.Date) MailMessageIdAction(hudson.tasks.MailMessageIdAction) StringTokenizer(java.util.StringTokenizer) MimeMessage(javax.mail.internet.MimeMessage) HudsonMimeMessage(hudson.tasks.HudsonMimeMessage) AddressException(javax.mail.internet.AddressException) AbstractProject(hudson.model.AbstractProject)

Aggregations

HudsonMimeMessage (hudson.tasks.HudsonMimeMessage)3 Date (java.util.Date)2 LinkedHashSet (java.util.LinkedHashSet)2 StringTokenizer (java.util.StringTokenizer)2 AddressException (javax.mail.internet.AddressException)2 InternetAddress (javax.mail.internet.InternetAddress)2 MimeMessage (javax.mail.internet.MimeMessage)2 AbstractProject (hudson.model.AbstractProject)1 User (hudson.model.User)1 MailMessageIdAction (hudson.tasks.MailMessageIdAction)1 Mailer (hudson.tasks.Mailer)1