List of usage examples for javax.mail Session getDefaultInstance
public static Session getDefaultInstance(Properties props)
From source file:uk.ac.cam.cl.dtg.util.Mailer.java
/** * @param recipient//from www . j a va 2s . c om * - string array of recipients that the message should be sent to * @param from * - the e-mail address that should be used as the sending address * @param replyTo * - the e-mail address that should be used as the reply-to address * @param subject * - The message subject * @return a newly created message with all of the headers populated. * @throws MessagingException - if there is an error in setting up the message */ private Message setupMessage(final String[] recipient, final String from, @Nullable final String replyTo, @Nullable final String replyToName, final String subject) throws MessagingException, UnsupportedEncodingException { Validate.notEmpty(recipient); Validate.notBlank(recipient[0]); Validate.notBlank(from); Properties p = new Properties(); p.put("mail.smtp.host", smtpAddress); if (null != smtpPort) { p.put("mail.smtp.port", smtpPort); } p.put("mail.smtp.starttls.enable", "true"); Session s = Session.getDefaultInstance(p); Message msg = new MimeMessage(s); InternetAddress sentBy = null; InternetAddress[] sender = new InternetAddress[1]; InternetAddress[] recievers = new InternetAddress[recipient.length]; sentBy = new InternetAddress(mailAddress, mailName); sender[0] = new InternetAddress(from); for (int i = 0; i < recipient.length; i++) { recievers[i] = new InternetAddress(recipient[i]); } if (sentBy != null && sender != null && recievers != null) { msg.setFrom(sentBy); msg.setRecipients(RecipientType.TO, recievers); msg.setSubject(subject); if (null != replyTo && null != replyToName) { msg.setReplyTo(new InternetAddress[] { new InternetAddress(replyTo, replyToName) }); } } return msg; }
From source file:org.syncope.core.notification.NotificationTest.java
private boolean verifyMail(final String sender, final String subject) { LOG.info("Waiting for notification to be sent..."); try {//from w w w .ja v a 2s .c o m Thread.sleep(10000); } catch (InterruptedException e) { } boolean found = false; try { Session session = Session.getDefaultInstance(System.getProperties()); Store store = session.getStore("pop3"); store.connect(pop3Host, mailAddress, mailPassword); Folder inbox = store.getFolder("INBOX"); assertNotNull(inbox); inbox.open(Folder.READ_WRITE); Message[] messages = inbox.getMessages(); for (int i = 0; i < messages.length; i++) { if (sender.equals(messages[i].getFrom()[0].toString()) && subject.equals(messages[i].getSubject())) { found = true; messages[i].setFlag(Flag.DELETED, true); } } inbox.close(true); store.close(); } catch (Throwable t) { LOG.error("Unexpected exception", t); fail("Unexpected exception while fetching e-mail"); } return found; }
From source file:com.quinsoft.zeidon.zeidonoperations.ZDRVROPR.java
public int CreateSeeMessage(int lConnection, String szSMTPServer, String szUserEmailAddress, String szRecipientEmailAddress, String szCCAddress, String szBCCAddress, String szSubjectText, int MimeType, String szMessageBody, String string4, String string5, int attachmentFlag, String szAttachmentFileName, String szUserEmailName, String szUserEmailPassword) { InternetAddress fromAddress = null;//from w w w .j av a2 s .com String host = szSMTPServer; //enc-exhub.enc-ad.enc.edu String from = szUserEmailAddress; String to[] = szRecipientEmailAddress.split("[\\s,;]+"); InternetAddress[] toAddress = new InternetAddress[to.length]; String cc[] = szCCAddress.split("[\\s,;]+"); InternetAddress[] ccAddress = new InternetAddress[cc.length]; String bcc[] = szBCCAddress.split("[\\s,;]+"); InternetAddress[] bccAddress = new InternetAddress[bcc.length]; //String host = "enc-exhub.enc-ad.enc.edu"; //String from = "kellysautter@comcast.net"; //String to = "kellysautter@comcast.net"; // Set properties Properties props = new Properties(); //mail.smtp.sendpartial props.put("mail.smtp.host", host); props.put("mail.debug", "true"); // Get session // Going to use getDefaultInstance // If I get java.lang.SecurityException: Access to default session denied // then it said to go use .getInstance(props). Session session = Session.getDefaultInstance(props); try { // Instantiate a message Message msg = new MimeMessage(session); try { if (from != null && !from.isEmpty()) fromAddress = new InternetAddress(from); if (szRecipientEmailAddress != null && !szRecipientEmailAddress.isEmpty()) { for (int iCnt = 0; iCnt < to.length; iCnt++) { toAddress[iCnt] = new InternetAddress(to[iCnt]); } } if (szCCAddress != null && !szCCAddress.isEmpty()) { for (int iCnt = 0; iCnt < cc.length; iCnt++) { ccAddress[iCnt] = new InternetAddress(cc[iCnt]); } } if (szBCCAddress != null && !szBCCAddress.isEmpty()) { for (int iCnt = 0; iCnt < bcc.length; iCnt++) { bccAddress[iCnt] = new InternetAddress(bcc[iCnt]); } } } catch (AddressException e) { task.log().error("*** CreateSeeMessage: setting addresses **** "); task.log().error(e); return -1; } // Set the FROM message msg.setFrom(fromAddress); if (szRecipientEmailAddress != null && !szRecipientEmailAddress.isEmpty()) msg.setRecipients(Message.RecipientType.TO, toAddress); if (szCCAddress != null && !szCCAddress.isEmpty()) msg.setRecipients(Message.RecipientType.CC, ccAddress); if (szBCCAddress != null && !szBCCAddress.isEmpty()) msg.setRecipients(Message.RecipientType.BCC, bccAddress); // Set the message subject and date we sent it. msg.setSubject(szSubjectText); msg.setSentDate(new Date()); // Set message content msg.setText(szMessageBody); // Send the message Transport.send(msg); } catch (MessagingException mex) { task.log().error("*** CreateSeeMessage: Transport.send error **** "); task.log().error(mex); // Email was bad? if (mex instanceof SendFailedException) return -1; // SMTP connection bad? return -2; } return 0; }
From source file:org.etudes.jforum.util.mail.Spammer.java
protected Spammer() throws EmailException { /*String host = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_HOST); /* ww w.ja va 2 s .c o m*/ if (host != null) { int colon = host.indexOf(':'); if (colon > 0) { mailProps.put("mail.smtp.host", host.substring(0, colon)); mailProps.put("mail.smtp.port", String.valueOf(host.substring(colon + 1))); } else { mailProps.put("mail.smtp.host", SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_HOST)); } String localhost = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_LOCALHOST); if (localhost != null && localhost.trim().length() > 0) { mailProps.put("mail.smtp.localhost", localhost); } }*/ // set the server host. sakai's email/email-impl/impl/src/java/org/sakaiproject/email/impl/BasicEmailService.java is setting this property String smtp = System.getProperty(SMTP_HOST); if (smtp == null || smtp.trim().length() == 0) { smtp = SakaiSystemGlobals.getValue(ConfigKeys.MAIL_SMTP_HOST); } mailProps.put(SMTP_HOST, smtp); if (logger.isDebugEnabled()) logger.debug("smtp is : " + smtp); // set the port, if specified String smtpPort = System.getProperty(SMTP_PORT); if (smtpPort != null) { mailProps.put(SMTP_PORT, smtpPort); } if (logger.isDebugEnabled()) logger.debug("smtpPort is : " + smtpPort); // set the mail envelope return address // String smtpFrom = System.getProperty(SMTP_FROM); String smtpFrom = "\"" + ServerConfigurationService.getString("ui.service", "Sakai") + "\"<no-reply@" + ServerConfigurationService.getServerName() + ">"; mailProps.put(SMTP_FROM, smtpFrom); if (logger.isDebugEnabled()) logger.debug("smtpFrom is : " + smtpFrom); mailProps.put("mail.mime.address.strict", "false"); mailProps.put("mail.mime.charset", SystemGlobals.getValue(ConfigKeys.MAIL_CHARSET)); // mailProps.put("mail.smtp.auth", SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_AUTH)); // username = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_USERNAME); // password = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_PASSWORD); messageFormat = SystemGlobals.getValue(ConfigKeys.MAIL_MESSSAGE_FORMAT).equals("html") ? MESSAGE_HTML : MESSAGE_TEXT; session = Session.getDefaultInstance(mailProps); this.testMode = ServerConfigurationService.getBoolean(EMAIL_TESTMODE, false); }
From source file:org.apache.syncope.core.logic.NotificationTest.java
private boolean verifyMail(final String sender, final String subject) throws Exception { LOG.info("Waiting for notification to be sent..."); try {//from ww w.java 2 s .c o m Thread.sleep(1000); } catch (InterruptedException e) { } boolean found = false; Session session = Session.getDefaultInstance(System.getProperties()); Store store = session.getStore("pop3"); store.connect(POP3_HOST, POP3_PORT, MAIL_ADDRESS, MAIL_PASSWORD); Folder inbox = store.getFolder("INBOX"); assertNotNull(inbox); inbox.open(Folder.READ_WRITE); Message[] messages = inbox.getMessages(); for (int i = 0; i < messages.length; i++) { if (sender.equals(messages[i].getFrom()[0].toString()) && subject.equals(messages[i].getSubject())) { found = true; messages[i].setFlag(Flag.DELETED, true); } } inbox.close(true); store.close(); return found; }
From source file:org.fogbowcloud.manager.core.plugins.util.CloudInitUserDataBuilder.java
private CloudInitUserDataBuilder(Charset charset) { super();//ww w . j av a 2 s . co m userDataMimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties())); userDataMultipart = new MimeMultipart(); try { userDataMimeMessage.setContent(userDataMultipart); } catch (MessagingException e) { throw Throwables.propagate(e); } this.charset = Preconditions.checkNotNull(charset, "'charset' can NOT be null"); }
From source file:fr.xebia.cloud.cloudinit.CloudInitUserDataBuilder.java
private CloudInitUserDataBuilder(@Nonnull Charset charset) { super();// ww w. j a va2 s.c o m userDataMimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties())); userDataMultipart = new MimeMultipart(); try { userDataMimeMessage.setContent(userDataMultipart); } catch (MessagingException e) { throw Throwables.propagate(e); } this.charset = Preconditions.checkNotNull(charset, "'charset' can NOT be null"); }
From source file:org.apache.james.mailrepository.file.MBoxMailRepository.java
/** * Parse a text block as an email and convert it into a mime message * /*from www . ja v a2 s. c o m*/ * @param emailBody * The headers and body of an email. This will be parsed into a * mime message and stored */ private MimeMessage convertTextToMimeMessage(String emailBody) { // this.emailBody = emailBody; MimeMessage mimeMessage = null; // Parse the mime message as we have the full message now (in string // format) ByteArrayInputStream mb = new ByteArrayInputStream(emailBody.getBytes()); Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props); try { mimeMessage = new MimeMessage(session, mb); } catch (MessagingException e) { getLogger().error("Unable to parse mime message!", e); } if (mimeMessage == null && getLogger().isDebugEnabled()) { String logBuffer = this.getClass().getName() + " Mime message is null"; getLogger().debug(logBuffer); } /* * String toAddr = null; try { // Attempt to read the TO field and see * if it errors toAddr = * mimeMessage.getRecipients(javax.mail.Message.RecipientType * .TO).toString(); } catch (Exception e) { // It has errored, so time * for plan B // use the from field I suppose try { * mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO, * mimeMessage.getFrom()); if (getLogger().isDebugEnabled()) { * StringBuffer logBuffer = new StringBuffer(128) * .append(this.getClass().getName()) * .append(" Patching To: field for message ") * .append(" with From: field"); * getLogger().debug(logBuffer.toString()); } } catch * (MessagingException e1) { * getLogger().error("Unable to set to: field to from: field", e); } } */ return mimeMessage; }
From source file:org.alfresco.email.server.EmailServiceImplTest.java
/** * Test the from name.//from w ww. j a v a2 s . c o m * * Step 1: * User admin will map to the "unknownUser" which out of the box is "anonymous" * Sending email From "admin" will fail. * * Step 2: * Send from the test user to the test' user's home folder. */ public void testFromName() throws Exception { folderEmailMessageHandler.setOverwriteDuplicates(true); logger.debug("Start testFromName"); String TEST_EMAIL = "buffy@sunnydale.high"; // TODO Investigate why setting PROP_EMAIL on createPerson does not work. NodeRef person = personService.getPerson(TEST_USER); if (person == null) { logger.debug("new person created"); Map<QName, Serializable> props = new HashMap<QName, Serializable>(); props.put(ContentModel.PROP_USERNAME, TEST_USER); props.put(ContentModel.PROP_EMAIL, TEST_EMAIL); person = personService.createPerson(props); } nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL); Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true); if (!auths.contains(TEST_USER)) { authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER); } String companyHomePathInStore = "/app:company_home"; String storePath = "workspace://SpacesStore"; StoreRef storeRef = new StoreRef(storePath); NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false); NodeRef companyHomeNodeRef = nodeRefs.get(0); assertNotNull("company home is null", companyHomeNodeRef); String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)) .toString() + "@Alfresco.com"; String testUserDBID = ((Long) nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com"; NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER); assertNotNull("testUserHomeFolder is null", testUserHomeFolder); String testUserHomeDBID = ((Long) nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)) .toString() + "@Alfresco.com"; /** * Step 1 * Negative test - send from "Bert" who does not exist. * User will be mapped to anonymous who is not an email contributor. */ try { String from = "admin"; String to = "bertie"; String content = "hello world"; Session sess = Session.getDefaultInstance(new Properties()); assertNotNull("sess is null", sess); SMTPMessage msg = new SMTPMessage(sess); InternetAddress[] toa = { new InternetAddress(to) }; msg.setFrom(new InternetAddress("Bert")); msg.setRecipients(Message.RecipientType.TO, toa); msg.setSubject("JavaMail APIs transport.java Test"); msg.setContent(content, "text/plain"); StringBuffer sb = new StringBuffer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); InputStream is = IOUtils.toInputStream(bos.toString()); assertNotNull("is is null", is); SubethaEmailMessage m = new SubethaEmailMessage(is); EmailDelivery delivery = new EmailDelivery(to, from, null); emailService.importMessage(delivery, m); fail("anonymous user not rejected"); } catch (EmailMessageException e) { // Check the exception is for the anonymous user. assertTrue("Message is not for anonymous", e.getMessage().contains("anonymous")); } /** * Step 2 * * Send From the test user TEST_EMAIL to the test user's home */ { logger.debug("Step 2"); String from = TEST_EMAIL; String to = testUserHomeDBID; String content = "hello world"; Session sess = Session.getDefaultInstance(new Properties()); assertNotNull("sess is null", sess); SMTPMessage msg = new SMTPMessage(sess); InternetAddress[] toa = { new InternetAddress(to) }; msg.setFrom(new InternetAddress(TEST_EMAIL)); msg.setRecipients(Message.RecipientType.TO, toa); msg.setSubject("JavaMail APIs transport.java Test"); msg.setContent(content, "text/plain"); StringBuffer sb = new StringBuffer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(bos); InputStream is = IOUtils.toInputStream(bos.toString()); assertNotNull("is is null", is); SubethaEmailMessage m = new SubethaEmailMessage(is); EmailDelivery delivery = new EmailDelivery(to, from, null); emailService.importMessage(delivery, m); } /** * Step 3 * * message.from From with "name" < name@ domain > format * SMTP.FROM="dummy" * * Send From the test user <TEST_EMAIL> to the test user's home */ { logger.debug("Step 3"); String from = " \"Joe Bloggs\" <" + TEST_EMAIL + ">"; String to = testUserHomeDBID; String content = "hello world"; Session sess = Session.getDefaultInstance(new Properties()); assertNotNull("sess is null", sess); SMTPMessage msg = new SMTPMessage(sess); InternetAddress[] toa = { new InternetAddress(to) }; msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO, toa); msg.setSubject("JavaMail APIs transport.java Test"); msg.setContent(content, "text/plain"); StringBuffer sb = new StringBuffer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(System.out); msg.writeTo(bos); InputStream is = IOUtils.toInputStream(bos.toString()); assertNotNull("is is null", is); SubethaEmailMessage m = new SubethaEmailMessage(is); EmailDelivery delivery = new EmailDelivery(to, "dummy", null); emailService.importMessage(delivery, m); } /** * Step 4 * * From with "name" < name@ domain > format * * Send From the test user <TEST_EMAIL> to the test user's home */ { logger.debug("Step 4"); String from = " \"Joe Bloggs\" <" + TEST_EMAIL + ">"; String to = testUserHomeDBID; String content = "hello world"; Session sess = Session.getDefaultInstance(new Properties()); assertNotNull("sess is null", sess); SMTPMessage msg = new SMTPMessage(sess); InternetAddress[] toa = { new InternetAddress(to) }; msg.setFrom(new InternetAddress(from)); msg.setRecipients(Message.RecipientType.TO, toa); msg.setSubject("JavaMail APIs transport.java Test"); msg.setContent(content, "text/plain"); StringBuffer sb = new StringBuffer(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); msg.writeTo(System.out); msg.writeTo(bos); InputStream is = IOUtils.toInputStream(bos.toString()); assertNotNull("is is null", is); SubethaEmailMessage m = new SubethaEmailMessage(is); InternetAddress a = new InternetAddress(from); String x = a.getAddress(); EmailDelivery delivery = new EmailDelivery(to, x, null); emailService.importMessage(delivery, m); } // /** // * Step 5 // * // * From with <e=name@domain> format // * // * RFC3696 // * // * Send From the test user <TEST_EMAIL> to the test user's home // */ // { // logger.debug("Step 4 <local tag=name@ domain > format"); // // String from = "\"Joe Bloggs\" <e=" + TEST_EMAIL + ">"; // String to = testUserHomeDBID; // String content = "hello world"; // // Session sess = Session.getDefaultInstance(new Properties()); // assertNotNull("sess is null", sess); // SMTPMessage msg = new SMTPMessage(sess); // InternetAddress[] toa = { new InternetAddress(to) }; // // msg.setFrom(new InternetAddress(from)); // msg.setRecipients(Message.RecipientType.TO, toa); // msg.setSubject("JavaMail APIs transport.java Test"); // msg.setContent(content, "text/plain"); // // StringBuffer sb = new StringBuffer(); // ByteArrayOutputStream bos = new ByteArrayOutputStream(); // msg.writeTo(System.out); // msg.writeTo(bos); // InputStream is = IOUtils.toInputStream(bos.toString()); // assertNotNull("is is null", is); // // SubethaEmailMessage m = new SubethaEmailMessage(is); // // emailService.importMessage(m); // } }
From source file:fsi_admin.JSmtpConn.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String ERROR = null, codErr = null; try {//w w w .jav a 2 s. com Properties parametros = new Properties(); Vector archivos = new Vector(); DiskFileUpload fu = new DiskFileUpload(); List items = fu.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) parametros.put(item.getFieldName(), item.getString()); else archivos.addElement(item); } if (parametros.getProperty("SERVER") == null || parametros.getProperty("DATABASE") == null || parametros.getProperty("USER") == null || parametros.getProperty("PASSWORD") == null || parametros.getProperty("BODY") == null || parametros.getProperty("MIMETYPE") == null || parametros.getProperty("SUBJECT") == null || parametros.getProperty("EMAIL") == null || parametros.getProperty("SOURCEMAIL") == null) { System.out.println("No recibi parametros de conexin antes del correo a enviar"); ERROR = "ERROR: El servidor no recibi todos los parametros de conexion (SERVER,DATABASE,USER,PASSWORD) antes del correo a enviar"; codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } //Hasta aqui se han enviado todos los parametros ninguno nulo if (ERROR == null) { StringBuffer msj = new StringBuffer(), SMTPHOST = new StringBuffer(), SMTPPORT = new StringBuffer(), SMTPUSR = new StringBuffer(), SMTPPASS = new StringBuffer(); MutableBoolean COBRAR = new MutableBoolean(false); MutableDouble COSTO = new MutableDouble(0.0), SALDO = new MutableDouble(0.0); // Primero obtiene info del SMTP if (!obtenInfoSMTP(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), SMTPHOST, SMTPPORT, SMTPUSR, SMTPPASS, msj, COSTO, SALDO, COBRAR)) { System.out.println("El usuario y contrasea de servicio estan mal"); ERROR = msj.toString(); codErr = "2"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 2); } else { if (COBRAR.booleanValue() && SALDO.doubleValue() < COSTO.doubleValue()) { System.out.println("El servicio tiene un costo que no alcanza en el saldo"); ERROR = "El servicio SMTP tiene un costo que no alcanza en el saldo"; codErr = "2"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 2); } else { Properties props; props = System.getProperties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.port", Integer.parseInt(SMTPPORT.toString())); // Set properties indicating that we want to use STARTTLS to encrypt the connection. // The SMTP session will begin on an unencrypted connection, and then the client // will issue a STARTTLS command to upgrade to an encrypted connection. props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.starttls.required", "true"); // Create a Session object to represent a mail session with the specified properties. Session session = Session.getDefaultInstance(props); MimeMessage mmsg = new MimeMessage(session); BodyPart messagebodypart = new MimeBodyPart(); MimeMultipart multipart = new MimeMultipart(); if (!prepareMsg(parametros.getProperty("SOURCEMAIL"), parametros.getProperty("EMAIL"), parametros.getProperty("SUBJECT"), parametros.getProperty("MIMETYPE"), parametros.getProperty("BODY"), msj, props, session, mmsg, messagebodypart, multipart)) { System.out.println("No se permiti preparar el mensaje"); ERROR = msj.toString(); codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } else { if (!adjuntarArchivo(msj, messagebodypart, multipart, archivos)) { System.out.println("No se permiti adjuntar archivos al mensaje"); ERROR = msj.toString(); codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } else { if (!sendMsg(SMTPHOST.toString(), SMTPUSR.toString(), SMTPPASS.toString(), msj, session, mmsg, multipart)) { System.out.println("No se permiti enviar el mensaje"); ERROR = msj.toString(); codErr = "3"; ingresarRegistroFallido(request.getRemoteAddr(), request.getRemoteHost(), parametros.getProperty("SERVER"), parametros.getProperty("USER"), parametros.getProperty("PASSWORD"), request, ERROR, 3); } else { ingresarRegistroExitoso(parametros.getProperty("SERVER"), parametros.getProperty("DATABASE"), parametros.getProperty("SUBJECT"), COSTO, SALDO, COBRAR); //Devuelve la respuesta al cliente Element Correo = new Element("Correo"); Correo.setAttribute("Subject", parametros.getProperty("SUBJECT")); Correo.setAttribute("MsjError", ""); Document Reporte = new Document(Correo); Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); ByteArrayOutputStream out = new ByteArrayOutputStream(); xmlOutputter.output(Reporte, out); byte[] data = out.toByteArray(); ByteArrayInputStream istream = new ByteArrayInputStream(data); String destino = "Correo.xml"; JBajarArchivo fd = new JBajarArchivo(); fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml", data.length, destino); } } } } } } } catch (Exception e) { e.printStackTrace(); ERROR = "ERROR DE EXCEPCION EN SERVIDOR PAC: " + e.getMessage(); } //Genera el archivo XML de error para ser devuelto al Servidor if (ERROR != null) { Element SIGN_ERROR = new Element("SIGN_ERROR"); SIGN_ERROR.setAttribute("CodError", codErr); SIGN_ERROR.setAttribute("MsjError", ERROR); Document Reporte = new Document(SIGN_ERROR); Format format = Format.getPrettyFormat(); format.setEncoding("utf-8"); format.setTextMode(TextMode.NORMALIZE); XMLOutputter xmlOutputter = new XMLOutputter(format); ByteArrayOutputStream out = new ByteArrayOutputStream(); xmlOutputter.output(Reporte, out); byte[] data = out.toByteArray(); ByteArrayInputStream istream = new ByteArrayInputStream(data); String destino = "SIGN_ERROR.xml"; JBajarArchivo fd = new JBajarArchivo(); fd.doDownload(response, getServletConfig().getServletContext(), istream, "text/xml", data.length, destino); } }