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();
}
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;
}
}
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!");
}
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!");
}
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;
}
Aggregations