Search in sources :

Example 11 with MultiPartEmail

use of org.apache.commons.mail.MultiPartEmail in project nifi by apache.

the class GenerateAttachment method WithAttachments.

public byte[] WithAttachments(int amount) {
    MultiPartEmail email = new MultiPartEmail();
    try {
        email.setFrom(from);
        email.addTo(to);
        email.setSubject(subject);
        email.setMsg(message);
        email.setHostName(hostName);
        int x = 1;
        while (x <= amount) {
            // Create an attachment with the pom.xml being used to compile (yay!!!)
            EmailAttachment attachment = new EmailAttachment();
            attachment.setPath("pom.xml");
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            attachment.setDescription("pom.xml");
            attachment.setName("pom.xml" + String.valueOf(x));
            // attach
            email.attach(attachment);
            x++;
        }
        email.buildMimeMessage();
    } catch (EmailException e) {
        e.printStackTrace();
    }
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    MimeMessage mimeMessage = email.getMimeMessage();
    try {
        mimeMessage.writeTo(output);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
    return output.toByteArray();
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) EmailAttachment(org.apache.commons.mail.EmailAttachment) EmailException(org.apache.commons.mail.EmailException) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 12 with MultiPartEmail

use of org.apache.commons.mail.MultiPartEmail in project ANNIS by korpling.

the class ReportBugWindow method sendBugReport.

private boolean sendBugReport(String bugEMailAddress, byte[] screenImage, String imageMimeType) {
    MultiPartEmail mail = new MultiPartEmail();
    try {
        // server setup
        mail.setHostName("localhost");
        // content of the mail
        mail.addReplyTo(form.getField("email").getValue().toString(), form.getField("name").getValue().toString());
        mail.setFrom(bugEMailAddress);
        mail.addTo(bugEMailAddress);
        mail.setSubject("[ANNIS BUG] " + form.getField("summary").getValue().toString());
        // TODO: add info about version etc.
        StringBuilder sbMsg = new StringBuilder();
        sbMsg.append("Reporter: ").append(form.getField("name").getValue().toString()).append(" (").append(form.getField("email").getValue().toString()).append(")\n");
        sbMsg.append("Version: ").append(VersionInfo.getVersion()).append("\n");
        sbMsg.append("Vaadin Version: ").append(Version.getFullVersion()).append("\n");
        sbMsg.append("Browser: ").append(Page.getCurrent().getWebBrowser().getBrowserApplication()).append("\n");
        sbMsg.append("URL: ").append(UI.getCurrent().getPage().getLocation().toASCIIString()).append("\n");
        sbMsg.append("\n");
        sbMsg.append(form.getField("description").getValue().toString());
        mail.setMsg(sbMsg.toString());
        if (screenImage != null) {
            mail.attach(new ByteArrayDataSource(screenImage, imageMimeType), "screendump.png", "Screenshot of the browser content at time of problem report");
        }
        File logfile = new File(VaadinService.getCurrent().getBaseDirectory(), "/WEB-INF/log/annis-gui.log");
        if (logfile.exists() && logfile.isFile() && logfile.canRead()) {
            mail.attach(new FileDataSource(logfile), "annis-gui.log", "Logfile of the GUI (shared by all users)");
        }
        if (cause != null) {
            try {
                mail.attach(new ByteArrayDataSource(Helper.convertExceptionToMessage(cause), "text/plain"), "exception.txt", "Exception that caused the user to report the problem");
            } catch (IOException ex) {
                log.error(null, ex);
            }
        }
        mail.send();
        return true;
    } catch (EmailException ex) {
        Notification.show("E-Mail not configured on server", "If this is no Kickstarter version please ask the administrator (" + bugEMailAddress + ") of this ANNIS-instance for assistance. " + "Problem reports are not available for ANNIS Kickstarter", Notification.Type.ERROR_MESSAGE);
        log.error(null, ex);
        return false;
    }
}
Also used : MultiPartEmail(org.apache.commons.mail.MultiPartEmail) FileDataSource(javax.activation.FileDataSource) EmailException(org.apache.commons.mail.EmailException) IOException(java.io.IOException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) File(java.io.File)

Example 13 with MultiPartEmail

use of org.apache.commons.mail.MultiPartEmail in project Java-Tutorial by gpcodervn.

the class SendAttachment method main.

public static void main(String[] args) throws EmailException, MalformedURLException {
    // Tạo một đối tượng đính kèm
    String filename = "data/myfile.txt";
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(filename);
    attachment.setURL(new URL("https://gpcoder.com"));
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription("Gp coder");
    attachment.setName("gpcoder");
    // Tạo đối tượng Email
    MultiPartEmail email = new MultiPartEmail();
    // Cấu hình thông tin Email Server
    email.setHostName(MailConfig.MAILCATCHER_HOST_NAME);
    email.setSmtpPort(MailConfig.MAILCATCHER_SSL_PORT);
    // Người gửi
    email.setFrom(MailConfig.APP_EMAIL);
    // Người nhận
    email.addTo(MailConfig.RECEIVE_EMAIL);
    // Tiêu đề
    email.setSubject("Testing Subject");
    // Nội dung email
    email.setMsg("Welcome to gpcoder.com");
    // Thêm đính kèm
    email.attach(attachment);
    // Gửi email
    email.send();
    System.out.println("Sent!");
}
Also used : EmailAttachment(org.apache.commons.mail.EmailAttachment) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) URL(java.net.URL)

Example 14 with MultiPartEmail

use of org.apache.commons.mail.MultiPartEmail in project Java-Tutorial by gpcodervn.

the class SendAttachment method main.

public static void main(String[] args) throws EmailException, MalformedURLException {
    // Tạo một đối tượng đính kèm
    String filename = "data/myfile.txt";
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(filename);
    attachment.setURL(new URL("https://gpcoder.com"));
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription("Gp coder");
    attachment.setName("gpcoder");
    // Tạo đối tượng Email
    MultiPartEmail email = new MultiPartEmail();
    // Cấu hình
    email.setHostName(MailConfig.HOST_NAME);
    email.setSmtpPort(MailConfig.SSL_PORT);
    email.setAuthenticator(new DefaultAuthenticator(MailConfig.APP_EMAIL, MailConfig.APP_PASSWORD));
    email.setSSLOnConnect(true);
    // Người gửi
    email.setFrom(MailConfig.APP_EMAIL);
    // Người nhận
    email.addTo(MailConfig.RECEIVE_EMAIL);
    // Tiêu đề
    email.setSubject("Testing Subject");
    // Nội dung email
    email.setMsg("Welcome to gpcoder.com");
    // Thêm đính kèm
    email.attach(attachment);
    // Gửi email
    email.send();
    System.out.println("Sent!");
}
Also used : EmailAttachment(org.apache.commons.mail.EmailAttachment) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) DefaultAuthenticator(org.apache.commons.mail.DefaultAuthenticator) URL(java.net.URL)

Example 15 with MultiPartEmail

use of org.apache.commons.mail.MultiPartEmail in project dwoss by gg-net.

the class Mandator method prepareDirectMail.

/**
 * Prepares a eMail to be send direct over the mandator smtp configuration.
 * The email is missing: to, subject, message and optional attachments.
 *
 * @return the email
 * @throws EmailException if something is wrong in the subsystem.
 */
public MultiPartEmail prepareDirectMail() throws EmailException {
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName(smtpConfiguration.getHostname());
    email.addBcc(company.getEmail());
    email.setFrom(company.getEmail(), company.getEmailName());
    email.setAuthentication(smtpConfiguration.getSmtpAuthenticationUser(), smtpConfiguration.getSmtpAuthenticationPass());
    email.setStartTLSEnabled(false);
    email.setSSLCheckServerIdentity(false);
    email.setSSLOnConnect(false);
    email.setCharset(smtpConfiguration.getCharset());
    return email;
}
Also used : MultiPartEmail(org.apache.commons.mail.MultiPartEmail)

Aggregations

MultiPartEmail (org.apache.commons.mail.MultiPartEmail)22 EmailException (org.apache.commons.mail.EmailException)11 EmailAttachment (org.apache.commons.mail.EmailAttachment)9 HtmlEmail (org.apache.commons.mail.HtmlEmail)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 InternetAddress (javax.mail.internet.InternetAddress)4 Email (org.apache.commons.mail.Email)4 RenderResult (cn.bran.japid.template.RenderResult)3 IOException (java.io.IOException)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)3 Mail (ninja.postoffice.Mail)3 Test (org.junit.Test)3 MessagingException (javax.mail.MessagingException)2 MimeMessage (javax.mail.internet.MimeMessage)2 MailException (cn.bran.play.exceptions.MailException)1