mm = new MultiPartEmail(); if(!StringUtils.isEmpty(bodyText)){ mm.setMsg(bodyText); mm.setHostName("NiFi-EWS"); mm.setFrom(ewsMessage.getFrom().getAddress()); mm.addTo(x.getAddress()); } catch (EmailException e) { throw new ProcessException("Failed to add TO recipient.", e); mm.addCc(x.getAddress()); } catch (EmailException e) { throw new ProcessException("Failed to add CC recipient.", e); mm.setSubject(ewsMessage.getSubject()); mm.setSentDate(ewsMessage.getDateTimeSent()); .forEach(x-> mm.addHeader(x.getName(), x.getValue())); mm.attach(bds,file.getName(), "", EmailAttachment.ATTACHMENT); } catch (MessagingException e) { e.printStackTrace(); mm.buildMimeMessage(); return mm.getMimeMessage();
@Override public void send(Mail mail) throws EmailException, AddressException { // create a correct multipart email based on html / txt content: MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail); // fill the from, to, bcc, css and all other fields: commonsmailHelper.doPopulateMultipartMailWithContent(multiPartEmail, mail); // set server parameters so we can send the MultiPartEmail: commonsmailHelper.doSetServerParameter(multiPartEmail, smtpHost, smtpPort, smtpSsl, smtpStartTLS, smtpStartTLSRequired, smtpUser, smtpPassword, smtpDebug); // And send it: multiPartEmail.send(); }
@Override public void doSetServerParameter(MultiPartEmail multiPartEmail, String smtpHost, Integer smtpPort, Boolean smtpSsl, Boolean smtpStartTLS, Boolean smtpStartTLSRequired, String smtpUser, String smtpPassword, Boolean smtpDebug) { // /set config params: multiPartEmail.setHostName(smtpHost); multiPartEmail.setSmtpPort(smtpPort); multiPartEmail.setSSLOnConnect(smtpSsl); multiPartEmail.setStartTLSEnabled(smtpStartTLS); multiPartEmail.setStartTLSRequired(smtpStartTLSRequired); if (smtpUser != null) { multiPartEmail.setAuthentication(smtpUser, smtpPassword); } multiPartEmail.setDebug(smtpDebug); }
protected MultiPartEmail createMultiPartEmail(String text) { MultiPartEmail email = new MultiPartEmail(); try { email.setMsg(text); return email; } catch (EmailException e) { throw new ActivitiException("Could not create text-only email", e); } }
/** * @param subject 主题 * @param body 内容 * @param attachment 附件 * @param recipients 收件人 */ public static MultiPartEmail getMultiPartEmail(String subject, String body, EmailAttachment attachment, String... recipients) { try { MultiPartEmail multiPartEmail = new MultiPartEmail(); configEmail(subject, multiPartEmail, recipients); multiPartEmail.setMsg(body); // add the attachment if (attachment != null) multiPartEmail.attach(attachment); return multiPartEmail; } catch (EmailException e) { throw new MailException("Unabled to send email", e); } }
public static boolean sendEmail(String [] mailTo, String mailFrom, String msgSubject, String msgContent,List<File> annexs) { MultiPartEmail multMail = new MultiPartEmail(); // SMTP multMail.setHostName(mailHost); multMail.setSmtpPort(smtpPort); // 需要提供公用的邮件用户名和密码 multMail.setAuthentication( mailUser, mailPassword); try { //multMail.setFrom(CodeRepositoryUtil.getValue("SysMail", "admin_email")); multMail.setFrom(mailFrom); multMail.addTo(mailTo); multMail.setSubject(msgSubject); multMail.setMsg(msgContent); for(File attachment: annexs){ multMail.attach(attachment); } multMail.send(); return true; } catch (EmailException e) { logger.error(e.getMessage(),e);//e.printStackTrace(); } return false; }
MultiPartEmail email = new MultiPartEmail(); email.setSmtpPort(getPortNumber()); email.setAuthenticator(new DefaultAuthenticator(getSenderID(), getSenderPassword())); email.setSSL(true); email.setHostName(getHostName()); email.addTo(receiverId); email.addCc(getCc()); email.addBcc(getBcc()); email.setFrom(getSenderID()); email.setSubject(getSubject()); email.setMsg(getBody()); attachment.setPath(getAttachmentPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); email.attach(attachment); email.send();
MultiPartEmail email = new MultiPartEmail(); email.setCharset("utf-8"); email.setHostName(SandraSchedulerConfigHelper.getSandraEmailHost(config)); email.setSmtpPort(SandraSchedulerConfigHelper.getSandraEmailPort(config)); email.setSubject(subject); try { email.setFrom(SandraSchedulerConfigHelper.getSandraEmailForm(config)); for (String recipient : to) { email.addTo(recipient); email.addPart(msg, MultiPartEmail.TEXT_PLAIN + ";charset=UTF-8"); email.attach(attachment); email.send();
String senderId = "xyz@yahoo.com"; try { MultiPartEmail email = new MultiPartEmail(); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword)); email.setDebug(true); email.setHostName("smtp.gmail.com"); email.setFrom(myEmailId); email.setSubject("Hi"); email.setMsg("This is a test mail ... :-)\n\nPlease check attachements that I have sent.\n\nThanks,\nFahim"); email.addTo(senderId); email.setTLS(true); attachment.setDescription("Excel"); attachment.setName("tables.xlsx"); email.attach(attachment); email.send(); System.out.println("Mail sent!"); } catch (Exception e) {
public void sendWebAttachEmail(String toEmail, String toName, String subject, String msg, List attachments) throws Exception { try { MultiPartEmail email = new MultiPartEmail(); this.setEmail(email, toEmail, toName, subject, msg, null, null); for (int i = 0; i < attachments.size(); i++) { String attachPath = (String) attachments.get(i); String attachName = attachPath.substring(attachPath .lastIndexOf("/"), attachPath.length()); EmailAttachment attachment = new EmailAttachment(); attachment.setURL(new URL(attachPath)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName); email.attach(attachment); } email.send(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
MultiPartEmail email = new MultiPartEmail(); email.setHostName(smtpServer); email.addTo(to); email.setFrom(from); email.setSubject(subject); email.setMsg(msg); email.setSocketTimeout(20000); email.setSocketConnectionTimeout(20000); // SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); // soapMessage.createAttachmentPart(); // enough for empty body new AttachmentPartImpl(); // enough for empty body // new MimeHeaders(); not enough for empty body email.send();
/** * 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()); } }
@Override public void reportError(ErrorInfo errorInfo) throws NullPointerException { MultiPartEmail email = new MultiPartEmail(); try { String emailTo = "support@codelutin.com"; email.setHostName("smtp"); email.addTo(emailTo, "Support"); email.setFrom("no-reply@isis-fish.org", "Isis-Fish"); email.setSubject("Project error notification : Isis-Fish"); email.addReplyTo("no-reply@isis-fish.org"); email.setContent(message, "text/plain; charset=ISO-8859-9"); email.send();
/** * 发送多媒体邮件,可以携带附件信息 * @param urls 附件的URL,key为附件的名称 */ public void sendMultipartEmail(String targetAddress,String title,String content,Map<String,URL> urls) throws Exception { MultiPartEmail email = new MultiPartEmail(); for(Map.Entry<String,URL> entry : urls.entrySet()) { email.attach(entry.getValue(),entry.getKey(),EmailAttachment.ATTACHMENT); } email.setSubject(title); email.addTo(targetAddress); email.setMsg(content); sendEmail(email); }
// Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(zipFile); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Zip File"); attachment.setName("myfiles.zip"); MultiPartEmail email = new MultiPartEmail(); email.attach(attachment);
/** * A sanity check that a simple email also works in reality. * * @throws Exception the test failed */ @Test public void testMultiPartEmail() throws Exception { final MultiPartEmail email = (MultiPartEmail) create(MultiPartEmail.class); email.setSubject("TestMultiPartMail"); email.setMsg("This is a test mail ... :-)"); email.attach(new File("./src/test/resources/attachments/logo.pdf")); EmailUtils.writeMimeMessage( new File("./target/test-emails/multipart.eml"), send(email).getMimeMessage()); }
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); } } }
MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.yourhosthere.com"); email.setSmtpPort(25); // authentication not always needed depending on your environment email.setAuthenticator(new DefaultAuthenticator("username", "password")); email.setTo("to@yourhosthere.com"); email.setFrom("from@yourhosthere.com");
@Signature public void __construct() { helper = new MultiPartEmail(); }
multiPartEmail.setCharset(charset); multiPartEmail.setSubject(subject); multiPartEmail.setFrom(from.x, from.y); } else { multiPartEmail.setFrom(from.x); multiPartEmail.addTo(email.x, email.y); } else { multiPartEmail.addTo(email.x); List<Tuple<String, String>> emails = createListOfAddresses(mail.getReplyTo()); for (Tuple<String, String> email : emails) { multiPartEmail.addReplyTo(email.x, email.y); List<Tuple<String, String>> emails = createListOfAddresses(mail.getCcs()); for (Tuple<String, String> email : emails) { multiPartEmail.addCc(email.x, email.y); List<Tuple<String, String>> emails = createListOfAddresses(mail.getBccs()); for (Tuple<String, String> email : emails) { multiPartEmail.addBcc(email.x, email.y); multiPartEmail.setHeaders(mail.getHeaders());