public void getEmail() throws MessagingException, IOException { Session session = Session.getDefaultInstance(System.getProperties(),null); Store store = null; store = session.getStore("imaps"); // store.connect(this.host, this.userName, this.password); // Get default folder Folder folder = store.getDefaultFolder(); folder.getMessages(); folder.getNewMessageCount(); Message m = folder.getMessage(0); m.getMessageNumber(); m.getAllRecipients(); m.getReceivedDate(); m.getFrom(); m.getSubject(); m.getReplyTo(); m.getContent(); m.getSize(); // Get any folder by name Folder[] folderList = folder.list(); }
public boolean sendMsg(String recipient, String subject, String content) throws MessagingException { // Create a mail object Session session = Session.getInstance(props, new Authenticator() { // Set the account information session,transport will send mail @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(Constants.MAIL_USERNAME, Constants.MAIL_PASSWORD); } }); session.setDebug(true); Message msg = new MimeMessage(session); try { msg.setSubject(subject); //Set the mail subject msg.setContent(content,"text/html;charset=utf-8"); msg.setFrom(new InternetAddress(Constants.MAIL_USERNAME)); //Set the sender msg.setRecipient(RecipientType.TO, new InternetAddress(recipient)); //Set the recipient Transport.send(msg); return true; } catch (Exception ex) { ex.printStackTrace(); System.out.println(ex.getMessage()); return false; } }
@Override public void sendEmail(String address, String subject, String content, Map<String, String> headers) throws Exception { Session session = MailUtilities.makeSession(); if (session == null) { // LogService.getRoot().warning("Unable to create mail session. Not sending mail to "+address+"."); LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.MailSenderSMTP.creating_mail_session_error", address); } MimeMessage msg = new MimeMessage(session); msg.setRecipients(Message.RecipientType.TO, address); msg.setFrom(); msg.setSubject(subject, "UTF-8"); msg.setSentDate(new Date()); msg.setText(content, "UTF-8"); if (headers != null) { for (Entry<String, String> header : headers.entrySet()) { msg.setHeader(header.getKey(), header.getValue()); } } Transport.send(msg); }
public String sendMail() { mail.setPassword(Mailer.PA); mail.setHost(Mailer.HOST); mail.setSender(Mailer.SENDER); Properties properties = System.getProperties(); properties.put("mail.smtp.host", mail.getHost()); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.socketFactory.port", "465"); properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); properties.put("mail.smtp.port", "465"); Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAurhentication() { return new PasswordAuthentication(mail.getSender(), mail.getPassword()); } }); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(mail.getSender())); message.addRecipient(Message.RecipientType.TO, new InternetAddress(mail.getEmailId())); message.setSubject(mail.getSubject()); message.setText(mail.getMessage()); Transport.send(message, mail.getSender(),mail.getPassword()); System.out.println("Mail Sent"); return StatusCode.SUCCESS; } catch(Exception ex) { throw new RuntimeException("Error while sending mail" + ex); } }
public static Session authorizeWebShopEmail() throws MessagingException { Session session = null; final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; Properties props = System.getProperties(); props.setProperty("mail.smtp.host", "smtp.gmail.com"); props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY); props.setProperty("mail.smtp.socketFactory.fallback", "false"); props.setProperty("mail.smtp.port", "465"); props.setProperty("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.auth", "true"); props.put("mail.debug", "true"); props.put("mail.store.protocol", "pop3"); props.put("mail.transport.protocol", "smtp"); final String username = ApplicationProperties.SHOP_EMAIL; final String password = ApplicationProperties.SHOP_EMAIL_PASSWORD; session = Session.getDefaultInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); return session; }
private Session getMailSession(){ if(session==null){ Properties properties = new Properties(); properties.put("mail.smtp.host",smtpHost); if(StringUtils.isNotEmpty(smtpPort)){ properties.put("mail.smtp.port",Integer.parseInt(smtpPort)); } if(smtpIsAuth) { properties.put("mail.smtp.auth","true"); session = Session.getDefaultInstance(properties, new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUser,smtpPassword); } }); } else { session = Session.getDefaultInstance(properties); } } return session; }
/** * Test attachment extraction with a TNEF message * @throws Exception */ public void testAttachmentExtraction() throws Exception { AuthenticationUtil.setRunAsUserSystem(); /** * Load a TNEF message */ ClassPathResource fileResource = new ClassPathResource("imap/test-tnef-message.eml"); assertNotNull("unable to find test resource test-tnef-message.eml", fileResource); InputStream is = new FileInputStream(fileResource.getFile()); MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), is); NodeRef companyHomeNodeRef = findCompanyHomeNodeRef(); FileInfo f1 = fileFolderService.create(companyHomeNodeRef, "ImapServiceImplTest", ContentModel.TYPE_FOLDER); FileInfo f2 = fileFolderService.create(f1.getNodeRef(), "test-tnef-message.eml", ContentModel.TYPE_CONTENT); ContentWriter writer = fileFolderService.getWriter(f2.getNodeRef()); writer.putContent(new FileInputStream(fileResource.getFile())); imapService.extractAttachments(f2.getNodeRef(), message); List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(f2.getNodeRef(), ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER); assertTrue("attachment folder is found", targetAssocs.size() == 1); NodeRef attachmentFolderRef = targetAssocs.get(0).getTargetRef(); assertNotNull(attachmentFolderRef); List<FileInfo> files = fileFolderService.listFiles(attachmentFolderRef); assertTrue("three files not found", files.size() == 3); }
/** * 获取用户与邮件服务器的连接 * * @param host 邮件主机名 * @param username 发件人的用户名 * @param password 发件人的用户名密码 * @return 返回指定用户与指定邮件服务器绑定的一个连接(会话) */ public static Session getSession(String host, final String username, final String password) { // 设置配置文件,邮件主机和是否认证 Properties property = new Properties(); property.put("mail.host", host); property.put("mail.smtp.auth", "true"); // 设置用户名和密码 Authenticator auth = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { // TODO Auto-generated method stub return new PasswordAuthentication(username, password); } }; // 获取与邮件主机的连接 Session session = Session.getInstance(property, auth); return session; }
public static void sendTextEmail(String to, String from, String subject, String msg, final ServerSetup setup) { try { Session session = getSession(setup); Address[] tos = new javax.mail.Address[0]; tos = new InternetAddress[]{new InternetAddress(to)}; Address[] froms = new InternetAddress[]{new InternetAddress(from)}; MimeMessage mimeMessage = new MimeMessage(session); mimeMessage.setSubject(subject); mimeMessage.setFrom(froms[0]); mimeMessage.setText(msg); Transport.send(mimeMessage, tos); } catch (Throwable e) { throw new RuntimeException(e); } }
public void processMessage() { System.out.println("Process message"); try { Session session = Session.getDefaultInstance(new Properties()); InputStream inputStream = new ByteArrayInputStream(message.getBytes()); MimeMessage mimeMessage = new MimeMessage(session,inputStream); if(mimeMessage.isMimeType(InboxVariables.plainMime)) { plainMessage = mimeMessage.getContent().toString(); } else if(mimeMessage.isMimeType(InboxVariables.multipartMime)) { MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent(); processMimeMultipart(mimeMultipart); } subject = mimeMessage.getSubject(); System.out.println("Message processed"); } catch(Exception ex) { ex.printStackTrace(System.err); } }
public Email convert(RawData rawData) throws IOException { try { Session s = Session.getDefaultInstance(new Properties()); MimeMessage mimeMessage = new MimeMessage(s, rawData.getContentAsStream()); String subject = Objects.toString(mimeMessage.getSubject(), UNDEFINED); ContentType contentType = ContentType.fromString(mimeMessage.getContentType()); Object messageContent = mimeMessage.getContent(); switch (contentType) { case HTML: case PLAIN: return buildPlainOrHtmlEmail(rawData, subject, contentType, messageContent); case MULTIPART_ALTERNATIVE: return buildMultipartAlternativeMail(rawData, subject, (Multipart) messageContent); default: throw new IllegalStateException("Unsupported e-mail content type " + contentType.name()); } } catch (MessagingException e) { return buildFallbackEmail(rawData); } }
private static Message createMessage(Session session) throws MessagingException, IOException { Message msg = new MimeMessage(session); InternetAddress fromAddress = new InternetAddress( getVal("from.mail"), getVal("username")); msg.setFrom(fromAddress); Optional.ofNullable(getVal("to.mail")).ifPresent((String tos) -> { for (String to : tos.split(";")) { try { msg.addRecipient(Message.RecipientType.TO, new InternetAddress( to, to)); } catch (Exception ex) { Logger.getLogger(Mailer.class.getName()).log(Level.SEVERE, null, ex); } } }); msg.setSubject(parseSubject(getVal("msg.subject"))); msg.setContent(getMessagePart()); return msg; }
private Session lookupSessionInJNDI() { addInfo("Looking up javax.mail.Session at JNDI location [" + jndiLocation + "]"); try { Context initialContext = new InitialContext(); Object obj = initialContext.lookup(jndiLocation); return (Session) obj; } catch (Exception e) { addError("Failed to obtain javax.mail.Session from JNDI location [" + jndiLocation + "]"); return null; } }
/** * * This method will create a new Mail Session * * @param smtpServer * Mail server IP/FQDN * @param port * SMTP port * @param sendFrom * Sender's Email ID * @param password * Email account Password * @param sendTo * Receiver's Email address * @return * Mail Session Object with Properties configured */ private static Session getSession(String smtpServer, String port, final String sendFrom, final String password) { Properties props = new Properties(); props.put("mail.smtp.host", smtpServer); props.put("java.net.preferIPv4Stack", "true"); props.put("mail.smtp.port", port); Session session = Session.getInstance(props, null); if (!StringUtils.isBlank(password)) { props.put("mail.smtp.socketFactory.port", port); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); session = Session.getInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(sendFrom, password); } }); } return session; }
/** * Creates a mail session with authentication if it is required, ie if it has been set up with SMTP authentication * in the config page * * @param properties * @return */ public static Session getMailSession() { String smtpServer = Configuration.get(ConfigurationKeys.SMTP_SERVER); Properties properties = new Properties(); properties.put("mail.smtp.host", smtpServer); String smtpAuthUser = Configuration.get(ConfigurationKeys.SMTP_AUTH_USER); String smtpAuthPass = Configuration.get(ConfigurationKeys.SMTP_AUTH_PASSWORD); Session session = null; if (StringUtils.isBlank(smtpAuthUser)) { session = Session.getInstance(properties); } else { properties.setProperty("mail.smtp.submitter", smtpAuthUser); properties.setProperty("mail.smtp.auth", "true"); SMTPAuthenticator auth = new SMTPAuthenticator(smtpAuthUser, smtpAuthPass); session = Session.getInstance(properties, auth); } return session; }
public static boolean createMimeMessage() { try { // 用props对象来创建并初始化session对象 session = Session.getDefaultInstance(props, null); // 用session对象来创建并初始化邮件对象 message = new MimeMessage(session); // 生成附件组件的实例 mp = new MimeMultipart(); } catch (Exception e) { return false; } return true; }
/** * Bereitet den Mailinhalt zum Senden vor. * * @throws MessagingException - * @throws UnsupportedEncodingException - */ public void createEmailMessage() throws MessagingException, UnsupportedEncodingException { mailSession = Session.getDefaultInstance(emailProperties, null); emailMessage = new MimeMessage(mailSession); emailMessage.setFrom(new InternetAddress(fromEmail, fromEmail)); for (String toEmail : toEmailList) { emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail)); } emailMessage.setSubject(emailSubject); emailMessage.setContent(emailBody, "text/html"); }
private void initSession() { session = Session.getDefaultInstance( emailConfig, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } } ); }
public void sendMail(){ Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username,password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject("Website Status Notification."); message.setText("website is down ."); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { System.out.println("Error sending email."); e.printStackTrace(); } }
private MimeMessage buildMailMessage(Session session, NotificationEvent notifyEvent, String title, String mailTemplatePath) throws MessagingException { MimeMessage message = new MimeMessage(session); // 邮件标题 message.setSubject(title); String html = IOHelper.readTxtFile(mailTemplatePath, "utf-8"); html = buildMailBody(html, notifyEvent); // 正文 message.setContent(html, "text/html;charset=utf-8"); // 发件人 message.setFrom(username); String addressStr = notifyEvent.getArg(cName); String[] toAddr = addressStr.split(","); Address[] receiver = new Address[toAddr.length]; int i = 0; for (String addr : toAddr) { if (!StringHelper.isEmpty(addr)) { receiver[i] = new InternetAddress(addr); i++; } } // 收件人 message.setRecipients(MimeMessage.RecipientType.TO, receiver); message.saveChanges(); return message; }
/** * 发送邮件 * * @param name String * @param pass String */ public boolean sendout() { try { mimeMsg.setContent(mp); mimeMsg.saveChanges(); logger.info(Resources.getMessage("EMAIL.SENDING")); Session mailSession = Session.getInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { if (userkey == null || "".equals(userkey.trim())) { return null; } return new PasswordAuthentication(username, userkey); } }); Transport transport = mailSession.getTransport("smtp"); transport.connect((String) props.get("mail.smtp.host"), username, password); // 设置发送日期 mimeMsg.setSentDate(new Date()); // 发送 transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.TO)); if (mimeMsg.getRecipients(Message.RecipientType.CC) != null) { transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.CC)); } logger.info(Resources.getMessage("EMAIL.SEND_SUCC")); transport.close(); return true; } catch (Exception e) { logger.error(Resources.getMessage("EMAIL.SEND_ERR"), e); return false; } }
public void report(UserSetting userSetting, SearchResult searchResult, int resultState) { if(! (boolean)config.get("enableMailReport")) return; final Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", "smtp.163.com"); props.put("mail.user", config.get("fromEmailUser")); props.put("mail.password", config.get("fromEmailPassword")); // 构建授权信息,用于进行SMTP进行身份验证 Authenticator authenticator = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(props.getProperty("mail.user"), props.getProperty("mail.password")); } }; Session mailSession = Session.getInstance(props, authenticator); try { MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(props.getProperty("mail.user"))); message.setRecipient(RecipientType.TO, new InternetAddress(config.get("toEmailUser").toString())); message.setSubject("PTE助手通知"); String content = String.format("账号 %s 已搜索到可用约会: 时间=%s, 地点=%s", userSetting.user.username, CalendarUtils.chinese(searchResult.apptTime), searchResult.testCenter); if(resultState > -1) { content += "<br>"; content += resultState == 1 ? "并报名成功" : "但报名失败"; } message.setContent(content, "text/html;charset=UTF-8"); Transport.send(message); } catch (MessagingException e) { e.printStackTrace(); } }
/** * 发送邮件 */ public boolean sendout() { try { mimeMsg.setContent(mp); mimeMsg.saveChanges(); logger.info(Resources.getMessage("EMAIL.SENDING")); Session mailSession = Session.getInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { if (userkey == null || "".equals(userkey.trim())) { return null; } return new PasswordAuthentication(username, userkey); } }); Transport transport = mailSession.getTransport("smtp"); transport.connect((String) props.get("mail.smtp.host"), username, password); // 设置发送日期 mimeMsg.setSentDate(new Date()); // 发送 transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.TO)); if (mimeMsg.getRecipients(Message.RecipientType.CC) != null) { transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.CC)); } logger.info(Resources.getMessage("EMAIL.SEND_SUCC")); transport.close(); return true; } catch (Exception e) { logger.error(Resources.getMessage("EMAIL.SEND_ERR"), e); return false; } }
public void send(String email, String token) throws EmailException { Properties properties = System.getProperties(); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); properties.put("mail.smtp.host", emailProperties.getSmtpHost()); properties.put("mail.smtp.port", emailProperties.getSmtpPort()); Session session = Session.getInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(emailProperties.getUsername(), emailProperties.getPassword()); } }); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(emailProperties.getUsername())); message.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); message.setSubject(messages.getMessageBy("label.pathological.reports").concat(" - ").concat(messages.getMessageBy("label.recover.password"))); message.setText(createBody(emailProperties.getApplicationCtxPath(), token)); Transport.send(message); } catch (MessagingException mex) { mex.printStackTrace(); throw new EmailException(messages.getMessageBy("message.email.exception")); } }
public void receiverConnect() throws NoSuchProviderException, MessagingException { receiverSession = Session.getInstance(pManager.getReceiverProps()); //receiverSession.setDebugOut(pManager.get_Log_Stream()); store = receiverSession.getStore(pManager.get_RECEIVER_Protocol()); store.connect(pManager.get_RECEIVER_User(), pManager.get_RECEIVER_Pass()); }
public static void enviarMailCumpleaños(Cliente cliente) { if (cliente.getPersonaMail() != null) { Mail mail = obtenerMailEmisor(); Properties props = conectarse(mail); Session session = autentificar(mail, props); String asunto = "Feliz Cumpleaños " + cliente.getClienteNombre() + "!!!"; String mensaje = "Queremos saludarlo en el mes de su cumpleaños, " + "espero que tenga una gran celebración y un día maravilloso.\r\n\r\nFeliz cumpleaños " + cliente.getClienteNombre() + ".\r\nDe parte del equipo de Pacinetes S.R.L."; try { BodyPart texto = new MimeBodyPart(); // Texto del mensaje texto.setText(mensaje); MimeMultipart multiParte = new MimeMultipart(); multiParte.addBodyPart(texto); MimeMessage message = new MimeMessage(session); // Se rellena el From InternetAddress emisor = new InternetAddress(mail.getNombre() + " <" + mail.getMail() + ">"); message.setFrom(emisor); // Se rellenan los destinatarios InternetAddress receptor = new InternetAddress(); receptor.setAddress(cliente.getPersonaMail()); message.addRecipient(Message.RecipientType.TO, receptor); // Se rellena el subject message.setSubject(asunto); // Se mete el texto y la foto adjunta. message.setContent(multiParte); Transport.send(message); } catch (MessagingException e) { messageService.informUser("Poliza creada, falló envío de mail"); } } }
@RequestMapping(value = "sendCode", method = RequestMethod.POST) public String sendCode(@RequestParam("login") String login, @RequestParam("email") String email, Model model, HttpServletResponse response, HttpServletRequest request) { if ((usersService.findByEmail(email) == null)) { model.addAttribute("msg", "Wrong e-mail"); return "loginAndRegistration/reset/forgotPassword"; } else if (usersService.findByLogin(login) == null) { model.addAttribute("msg", "Wrong login"); return "loginAndRegistration/reset/forgotPassword"; } try { Session session = EmailActions.authorizeWebShopEmail(); String code = Long.toHexString(Double.doubleToLongBits(Math.random())); request.getSession().setAttribute("code", code); request.getSession().setAttribute("email", email); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(ApplicationProperties.SHOP_EMAIL)); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false)); msg.setSubject("Reset password"); msg.setText("After 5 min code will be delete\n" + code); msg.setSentDate(new Date()); Transport.send(msg); } catch (MessagingException e) { System.out.println("Error : " + e); } return "loginAndRegistration/reset/codePassword"; }
@Override protected void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception { InputStream contentInputStream = null; try{ contentInputStream = reader.getContentInputStream(); MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()), contentInputStream); final StringBuilder sb = new StringBuilder(); Object content = mimeMessage.getContent(); if (content instanceof Multipart) { processMultiPart((Multipart) content,sb); } else { sb.append(content.toString()); } writer.putContent(sb.toString()); } finally { if (contentInputStream != null) { try { contentInputStream.close(); } catch ( IOException e) { //stop exception propagation } } } }
public void testUnmodifiedMessage() throws Exception { // Get test message UID final Long uid = getMessageUid(folder, 1); // Get Message size final int count = getMessageSize(folder, uid); // Make multiple message reading for (int i = 0; i < 100; i++) { // Get random offset int n = (int) ((int) 100 * Math.random()); // Get first part BODY body = getMessageBodyPart(folder, uid, 0, count - n); // Read second message part BODY bodyRest = getMessageBodyPart(folder, uid, count - n, n); // Creating and parsing message from 2 parts MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), new SequenceInputStream(new BufferedInputStream(body.getByteArrayInputStream()), new BufferedInputStream(bodyRest.getByteArrayInputStream()))); MimeMultipart content = (MimeMultipart) message.getContent(); // Reading first part - should be successful assertNotNull(content.getBodyPart(0).getContent()); // Reading second part - should be successful assertNotNull(content.getBodyPart(1).getContent()); } }
/** * Load a MIME package from an existing source * * @param packageStream * the stream with the package content * * @throws PackageException */ @PublicAtsApi public MimePackage( InputStream packageStream ) throws PackageException { try { this.message = new MimeMessage(Session.getInstance(new Properties()), packageStream); partOfImapFolder = message.getFolder(); // initial best effort. Null for nested or newly created MimeMessages } catch (MessagingException me) { throw new PackageException(me); } decompose(); }
/** * Initialize the SMTP session * * @throws ActionException */ private void initSession() throws ActionException { // initialize the mail session with the current properties session = Session.getInstance(mailProperties); // user can get more debug info with the session's debug mode session.setDebug(configurator.getMailSessionDebugMode()); // initialize the SMPT transport try { transport = session.getTransport("smtp"); } catch (NoSuchProviderException e) { throw new ActionException(e); } }
@Test public void constructFromMimeMessage() throws Exception { MimePackage message = new MimePackage(new MimeMessage(Session.getDefaultInstance(new Properties()), new FileInputStream(mailMessagePath))); assertEquals(4, message.getRegularPartCount()); assertEquals(2, message.getAttachmentPartCount()); }