本文整理汇总了Java中org.apache.commons.mail.MultiPartEmail.attach方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPartEmail.attach方法的具体用法?Java MultiPartEmail.attach怎么用?Java MultiPartEmail.attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.MultiPartEmail
的用法示例。
在下文中一共展示了MultiPartEmail.attach方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmailAttachment
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public void sendEmailAttachment(String email_to, String assunto, String msg, String file_logs) {
File fileLogs = new File(file_logs);
EmailAttachment attachmentLogs = new EmailAttachment();
attachmentLogs.setPath(fileLogs.getPath());
attachmentLogs.setDisposition(EmailAttachment.ATTACHMENT);
attachmentLogs.setDescription("Logs");
attachmentLogs.setName(fileLogs.getName());
try {
MultiPartEmail email = new MultiPartEmail();
email.setDebug(debug);
email.setHostName(smtp);
email.addTo(email_to);
email.setFrom(email_from);
email.setAuthentication(email_from, email_password);
email.setSubject(assunto);
email.setMsg(msg);
email.setSSL(true);
email.attach(attachmentLogs);
email.send();
} catch (EmailException e) {
System.out.println(e.getMessage());
}
}
示例2: fillEmail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Fill email.
*
* @param email
* the email
* @throws EmailException
* the email exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void fillEmail(final MultiPartEmail email) throws EmailException, IOException {
email.setHostName(getHost());
email.setSmtpPort(getSmtpPort());
email.addTo(getTo());
email.setFrom(getFrom());
email.setSubject(getSubject());
email.setMsg(getMsg());
email.setSSLOnConnect(isSecured());
if (isRequiresAuthentication()) {
email.setAuthentication(getUsername(), getPassword());
}
for (int i = 0; i < this.attachements.size(); i++) {
final Attachment attachment = this.attachements.get(i);
final ByteArrayDataSource ds = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType());
email.attach(ds, attachment.getName(), attachment.getDescription());
}
}
示例3: prepareAndSend
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Prepare and send filejackets to the specified email address.
* <p>
* @param fileJackets files to be send
*/
private void prepareAndSend(List<FileJacket> fileJackets) {
SubMonitor m = monitorFactory.newSubMonitor("Transfer");
m.message("sending Mail");
m.start();
try {
ListingMailConfiguration config = listingService.get().listingMailConfiguration();
MultiPartEmail email = mandator.prepareDirectMail();
email.setFrom(config.getFromAddress());
email.addTo(config.getToAddress());
email.setSubject(config.getSubject());
email.setMsg(config.toMessage());
for (FileJacket fj : fileJackets) {
email.attach(
new javax.mail.util.ByteArrayDataSource(fj.getContent(), "application/xls"),
fj.getHead() + fj.getSuffix(), "Die Händlerliste für die Marke ");
}
email.send();
m.finish();
} catch (EmailException e) {
throw new RuntimeException(e);
}
}
示例4: send
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public void send (String to, String cc, String bcc, String subject,
String message, EmailAttachment attachment)
throws EmailException
{
MultiPartEmail email = new MultiPartEmail ();
// Server configuration
email.setMsg (message);
if (attachment != null) email.attach (attachment);
send (email, to, cc, bcc, subject);
}
示例5: attach
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
protected void attach(Email email, List<File> files, List<DataSource> dataSources) throws EmailException {
if (!(email instanceof MultiPartEmail && attachmentsExist(files, dataSources))) {
return;
}
MultiPartEmail mpEmail = (MultiPartEmail) email;
for (File file : files) {
mpEmail.attach(file);
}
for (DataSource ds : dataSources) {
if (ds != null) {
mpEmail.attach(ds, ds.getName(), null);
}
}
}
示例6: buildContent
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Builds email content to be sent using an email sender.
* @param content instance where content must be set.
* @throws com.irurueta.server.commons.email.EmailException if setting mail
* content fails.
*/
@Override
protected void buildContent(MultiPartEmail content)
throws com.irurueta.server.commons.email.EmailException {
try {
if (getText() != null) {
content.setMsg(getText());
}
//add attachments
List<EmailAttachment> attachments = getAttachments();
org.apache.commons.mail.EmailAttachment apacheAttachment;
if (attachments != null) {
for (EmailAttachment attachment : attachments) {
//only add attachments with files
if (attachment.getAttachment() == null) {
continue;
}
apacheAttachment = new org.apache.commons.mail.
EmailAttachment();
apacheAttachment.setPath(attachment.getAttachment().getAbsolutePath());
apacheAttachment.setDisposition(
org.apache.commons.mail.EmailAttachment.ATTACHMENT);
if (attachment.getName() != null) {
apacheAttachment.setName(attachment.getName());
}
content.attach(apacheAttachment);
}
}
} catch (EmailException e) {
throw new com.irurueta.server.commons.email.EmailException(e);
}
}
开发者ID:albertoirurueta,项目名称:irurueta-server-commons-email,代码行数:41,代码来源:ApacheMailTextEmailMessageWithAttachments.java
示例7: addAttachments
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
private void addAttachments(MultiPartEmail mail, Message msg) {
for (Attachment attachment : msg.getAttachments()) {
try {
mail.attach(new ByteArrayDataSource(attachment.getContent(), attachment.getMimeType()), attachment.getFileName(), "");
} catch (EmailException e) {
throw new RuntimeException(e);
}
}
}
示例8: addAttachment
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
private void addAttachment(final MultiPartEmail email, final File attachment) throws EmailException {
final EmailAttachment emailAttachment = new EmailAttachment();
emailAttachment.setPath(attachment.getPath());
emailAttachment.setDisposition(EmailAttachment.ATTACHMENT);
emailAttachment.setDescription(attachment.getName());
emailAttachment.setName(attachment.getName());
email.attach(emailAttachment);
}
示例9: setAttachments
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
private void setAttachments(List<IMendixObject> attachments, MultiPartEmail multipart) throws CoreException
{
if(this.context == null && attachments != null)
throw new MendixRuntimeException("Context should not be null when sending e-mails with attachments");
if(attachments != null && this.context != null) {
int i = 1;
for (IMendixObject attachment : attachments) {
if(attachment != null) {
if(!Core.isSubClassOf(FILE_DOCUMENT, attachment.getType())) {
throw new CoreException("Attachment is no fileDocument");
}
String mimeType = (new MimetypesFileTypeMap()).getContentType((String) attachment.getValue(this.context, FILE_DOCUMENT_NAME));
InputStream content = Core.getFileDocumentContent(this.context, attachment);
try {
if(content != null && content.available() > 0) {
DataSource source = new ByteArrayDataSource(content, mimeType);
String fileName = (String) attachment.getValue(this.context, FILE_DOCUMENT_NAME);
if("".equals(fileName)) fileName = "Attachment" + i;
multipart.attach(source, fileName, fileName);
}
} catch (Exception e)
{
throw new CoreException("Unable to attach attachment " + (String) attachment.getValue(this.context, FILE_DOCUMENT_NAME) + ".", e);
}
}
i++;
}
}
}
示例10: sendMultipartEmail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
private void sendMultipartEmail() throws MangooMailerException {
Config config = Application.getInstance(Config.class);
try {
MultiPartEmail multiPartEmail = new MultiPartEmail();
multiPartEmail.setCharset(Default.ENCODING.toString());
multiPartEmail.setHostName(config.getSmtpHost());
multiPartEmail.setSmtpPort(config.getSmtpPort());
multiPartEmail.setAuthenticator(getDefaultAuthenticator());
multiPartEmail.setSSLOnConnect(config.isSmtpSSL());
multiPartEmail.setFrom(this.from);
multiPartEmail.setSubject(this.subject);
multiPartEmail.setMsg(render());
for (String recipient : this.recipients) {
multiPartEmail.addTo(recipient);
}
for (String cc : this.ccRecipients) {
multiPartEmail.addCc(cc);
}
for (String bcc : this.bccRecipients) {
multiPartEmail.addBcc(bcc);
}
for (File file : this.files) {
multiPartEmail.attach(file);
}
multiPartEmail.send();
} catch (EmailException | MangooTemplateEngineException e) {
throw new MangooMailerException(e);
}
}
示例11: mail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* This method send document to the e-Mail address that is in the customer set.
* <p/>
* @param document This is the Document that will be send.
* @throws UserInfoException if the sending of the Mail is not successful.
* @throws RuntimeException if problems exist in the JasperExporter
*/
@Override
public void mail(Document document, DocumentViewType jtype) throws UserInfoException, RuntimeException {
UiCustomer customer = customerService.asUiCustomer(document.getDossier().getCustomerId());
String customerMailAddress = customerService.asCustomerMetaData(document.getDossier().getCustomerId()).getEmail();
if ( customerMailAddress == null ) {
throw new UserInfoException("Kunde hat keine E-Mail Hinterlegt! Senden einer E-Mail ist nicht Möglich!");
}
String doctype = (jtype == DocumentViewType.DEFAULT ? document.getType().getName() : jtype.getName());
try (InputStream is = mandator.getMailTemplateLocation().toURL().openStream();
InputStreamReader templateReader = new InputStreamReader(is)) {
String text = new MailDocumentParameter(customer.toTitleNameLine(), doctype).eval(IOUtils.toString(templateReader));
MultiPartEmail email = mandator.prepareDirectMail();
email.setCharset("UTF-8");
email.addTo(customerMailAddress);
email.setSubject(document.getType().getName() + " | " + document.getDossier().getIdentifier());
email.setMsg(text + mandator.getDefaultMailSignature());
email.attach(
new ByteArrayDataSource(JasperExportManager.exportReportToPdf(jasper(document, jtype)), "application/pdf"),
"Dokument.pdf", "Das ist das Dokument zu Ihrem Aufrag als PDF.");
for (MandatorMailAttachment mma : mandator.getDefaultMailAttachment()) {
email.attach(mma.getAttachmentData().toURL(), mma.getAttachmentName(), mma.getAttachmentDescription());
}
email.send();
} catch (EmailException ex) {
L.error("Error on Mail sending", ex);
throw new UserInfoException("Das senden der Mail war nicht erfolgreich!\n" + ex.getMessage());
} catch (IOException | JRException e) {
throw new RuntimeException(e);
}
}
示例12: share
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public void share()
{
MultiPartEmail email = new MultiPartEmail();
email.setHostName(GMAIL_SMTP_URL);
email.setSmtpPort(GMAIL_SMTP_PORT);
// needs gmail pass for from email
email.setAuthenticator(new DefaultAuthenticator(from, fromPassword));
email.setSSLOnConnect(true);
if(imagePath!=null && !imagePath.isEmpty()){
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(imagePath);
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription(ATTACHMENT_DESC);
attachment.setName(ATTACHMENT_IMG_TITLE);
try {
email.attach(attachment);
} catch (Exception e1) {
e1.printStackTrace();
}
}
try{
email.setFrom(from);
email.setSubject(EMAIL_SUBJECT);
email.setMsg(message);
email.addTo(to);
email.send();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
示例13: sendSupportRequest
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
public boolean sendSupportRequest() {
try {
String senderName = sender_name.getText();
String senderEmail = sender_email.getText();
String sendingTime = date_time.getText();
String systemUser = system_user.getText();
String message = messge_content.getText();
if (message.isEmpty()) {
JOptionPane.showMessageDialog(this, "You haven't entered your message. Please enter the message and try again.");
}
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("mail.mdcc.lk");
email.addTo("[email protected]", "Viraj @ MDCC");
email.addTo("[email protected]", "Isuru @ MDCC");
email.setFrom(senderEmail, senderName);
email.setAuthentication("[email protected]", "mdccmail123");
email.setSSLOnConnect(true);
email.setStartTLSEnabled(true);
email.setSmtpPort(465);
// email.setHostName("mail.mdcc.lk");
// email.addTo("[email protected]", "Isuru Ranawaka");
// email.setFrom("[email protected]", "Isuru Ranawaka from MDCC");
// email.setSubject("Test email with inline image");
// email.setAuthentication("[email protected]", "=-88isuru");
// email.setSSLOnConnect(false);
// email.setSmtpPort(25);
// email.setDebug(true);
email.setSubject("New Support Request from Application");
String textMessage = "Application - Support Request\n"
+ "---------------------------------------------------------------------\n"
+ "New Support Request from _P1_\n"
+ "Sent by _P2_ on _P3_\n"
+ "---------------------------------------------------------------------\n"
+ "\n"
+ "Message: \n_P4_\n"
+ "\n"
+ "---------------------------------------------------------------------\n"
+ "This email was sent from Application. \n"
+ "Please note that this is an automatically generated email and \n"
+ "your replies will go nowhere.\n"
+ "\n"
+ "© All Rights Reserved - Management Development Co-operative Co. Ltd.";
textMessage = textMessage.replace("_P1_", systemUser);
textMessage = textMessage.replace("_P2_", senderName + "(" + senderEmail + ")");
textMessage = textMessage.replace("_P3_", sendingTime);
textMessage = textMessage.replace("_P4_", message);
//attach file
if (!attachedFile.trim().isEmpty()) {
email.attach(new File(attachedFile));
}
// set the alternative message
email.setMsg(textMessage);
// send the email
email.send();
return true;
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Cannot send email.\nError:" + e.getLocalizedMessage(), "Sending failure", JOptionPane.ERROR_MESSAGE);
return false;
}
}
示例14: sendEmail
import org.apache.commons.mail.MultiPartEmail; //导入方法依赖的package包/类
/**
* Sends an email with a PDF attachment.
* @throws TransportConfigurationException
* @throws EmailException
* @throws MessagingException
*/
public void sendEmail(String receipient, byte[] pdf) throws TransportConfigurationException, EmailException, MessagingException {
if(!configuration.isEnabled()) {
throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
}
final MultiPartEmail email = new MultiPartEmail();
email.setCharset(EmailConstants.UTF_8);
if (Strings.isNullOrEmpty(configuration.getHostname())) {
throw new TransportConfigurationException("No hostname configured for email transport while trying to send alert email!");
} else {
email.setHostName(configuration.getHostname());
}
email.setSmtpPort(configuration.getPort());
if (configuration.isUseSsl()) {
email.setSslSmtpPort(Integer.toString(configuration.getPort()));
}
if(configuration.isUseAuth()) {
email.setAuthenticator(new DefaultAuthenticator(
Strings.nullToEmpty(configuration.getUsername()),
Strings.nullToEmpty(configuration.getPassword())
));
}
email.setSSLOnConnect(configuration.isUseSsl());
email.setStartTLSEnabled(configuration.isUseTls());
if (pluginConfig != null && !Strings.isNullOrEmpty(pluginConfig.getString("sender"))) {
email.setFrom(pluginConfig.getString("sender"));
} else {
email.setFrom(configuration.getFromEmail());
}
email.setSubject("Graylog Aggregates Report");
Calendar c = Calendar.getInstance();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
email.attach(new ByteArrayDataSource(pdf, "application/pdf"),
"aggregates_report_" + df.format(c.getTime()) +".pdf", "Graylog Aggregates Report",
EmailAttachment.ATTACHMENT);
email.setMsg("Please find the report attached.");
email.addTo(receipient);
LOG.debug("sending report to " + email.getToAddresses().toString());
email.send();
}