Função para receber e-mails com anexo



  • Boa tarde!

    Eu estou precisando criar uma função para receber e-mails com anexo, pois no maker não existe esta função nativa hoje. Tentei juntar partes dos códigos de duas funções para tentar criar isto: Email - corpo da mensagem e Email - enviar email com SSL/TLS - Anexo. O resultado segue abaixo:
    [code]protected final Variant receiveMailWithAttachment(Variant messageVar, Variant bodyVar, Variant attachmentVar) throws Exception { // Verifica se a mensagem passada como parâmetro é um objeto Message Object messageObj = messageVar.getObject(); if (!(messageObj instanceof javax.mail.Message)) { return Variant.VARIANT_NULL; } // Obtém o corpo da mensagem javax.mail.Message message = (javax.mail.Message) messageObj; String messageBody = null; if (message.isMimeType("text/plain")) { messageBody = message.getContent().toString(); } else if (message.isMimeType("text/html")) { StringBuffer buffer = new StringBuffer(); String newMessage = message.getContent().toString(); for (int index = 0; index < newMessage.length(); index++) { char c = newMessage.charAt(index); if (c == '\n') { buffer.append("<br>"); } else { buffer.append(c); } } messageBody = buffer.toString(); } else { javax.mail.Multipart multipart = (javax.mail.Multipart) message.getContent(); for (int index = 0; index < multipart.getCount(); index++) { javax.mail.Part part = multipart.getBodyPart(index); String disposition = part.getDisposition(); if (disposition != null && disposition.equals(javax.mail.Part.INLINE)) { if (part.isMimeType("text/plain")) { messageBody = part.getContentType().toString(); break; } } else if (disposition == null) { if (part.getContent() instanceof javax.mail.internet.MimeMultipart) { javax.mail.internet.MimeMultipart mm = (javax.mail.internet.MimeMultipart) part.getContent(); if (mm.getBodyPart(1).getContent() instanceof String) { messageBody = mm.getBodyPart(1).getContent().toString(); break; } } else { if (part.getContent() instanceof String) { messageBody = part.getContent().toString(); break; } } } } } return VariantPool.get(messageBody); //Obter anexos da mensagem - trecho retirado da função email - enviar email com SSL/TLS - Anexo; Object a = bodyVar.getObject(); javax.mail.Multipart messageBody; javax.activation.FileDataSource fds; if (a instanceof javax.mail.Multipart) { messageBody = (javax.mail.Multipart) a; } else { messageBody = new javax.mail.internet.MimeMultipart(); javax.mail.internet.MimeBodyPart bodyPart = null; String bodyContent = bodyVar.getTrimString(); if ((bodyContent != null) && (bodyContent != "")) { bodyPart = new javax.mail.internet.MimeBodyPart(); bodyPart.setContent(bodyVar.getString(), (html.getBoolean())? "text/html" : "text/plain"); messageBody.addBodyPart(bodyPart); } } Object attachmentObj = attachmentVar.getObject(); String currentAttachment; javax.mail.internet.MimeBodyPart bodyPart = null; if (attachmentObj instanceof List) { java.util.List<String> attachment = (List) attachmentObj; for (int index = 0; index < attachment.size(); index++) { currentAttachment = attachment.get(index).toString(); if ((currentAttachment != null) && (currentAttachment != "")) { fds = new javax.activation.FileDataSource(currentAttachment); bodyPart = new javax.mail.internet.MimeBodyPart(); bodyPart.setDataHandler(new javax.activation.DataHandler(fds)); bodyPart.setFileName(fds.getName()); messageBody.addBodyPart(bodyPart); } } } else if (attachmentObj instanceof String) { currentAttachment = attachmentObj.toString(); if ((currentAttachment != null) && (currentAttachment != "")) { fds = new javax.activation.FileDataSource(currentAttachment); bodyPart = new javax.mail.internet.MimeBodyPart(); bodyPart.setDataHandler(new javax.activation.DataHandler(fds)); bodyPart.setFileName(fds.getName()); messageBody.addBodyPart(bodyPart); } } msg.setContent(messageBody); }[/code] Porém, estou tendo um erro de compilação, que é este:

    Exceção Gerada:
    wfr.exceptions.WFRCompileException: java.lang.Exception: C:\Arquivos de programas\Softwell Solutions\Maker 2.7\Webrun 2\tomcat\webapps\webrun/src/wfr/com/systems/system_lpo/rules/LpoObterMensagemsModificado.java:158: cannot find symbol symbol : method receiveMailWithAttachment(wfr.rules.Variant) location: class wfr.com.systems.system_lpo.rules.LpoObterMensagemsModificado ebfSetElementAtList(VARIABLE[2], ebfListParamsCreate(ebfEmailGetMessageFrom(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), VARIABLE[9], ebfEmailGetMessageSubject(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), receiveMailWithAttachment(ebfGetElementFromList(VARIABLE[0], VARIABLE[1]))), Variant.VARIANT_NULL); ^ 1 error at wfr.util.Functions.compileFile(Functions.java:3601) at wfr.util.Functions.compileFile(Functions.java:3557) at wfr.util.Functions.compileFile(Functions.java:3534) at wfr.rules.RulesClassLoader.compile(RulesClassLoader.java:140) at wfr.rules.WFRRuleManager.create(WFRRuleManager.java:377) at wfr.rules.WFRRuleManager.getRuleClass(WFRRuleManager.java:110) at wfr.web.actions.ExecuteRuleAction.execute(ExecuteRuleAction.java:160) at wfr.web.Action.doAction(Action.java:126) at wfr.web.Controller.process(Controller.java:100) at wfr.web.Controller.doPost(Controller.java:67) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at wfr.web.ContextFilter.doFilter(ContextFilter.java:86) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.Exception: C:\Arquivos de programas\Softwell Solutions\Maker 2.7\Webrun 2\tomcat\webapps\webrun/src/wfr/com/systems/system_lpo/rules/LpoObterMensagemsModificado.java:158: cannot find symbol symbol : method receiveMailWithAttachment(wfr.rules.Variant) location: class wfr.com.systems.system_lpo.rules.LpoObterMensagemsModificado ebfSetElementAtList(VARIABLE[2], ebfListParamsCreate(ebfEmailGetMessageFrom(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), VARIABLE[9], ebfEmailGetMessageSubject(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), receiveMailWithAttachment(ebfGetElementFromList(VARIABLE[0], VARIABLE[1]))), Variant.VARIANT_NULL); ^ 1 error at wfr.util.Functions.compileFile(Functions.java:3593) ... 27 more

    Causa:
    java.lang.Exception: C:\Arquivos de programas\Softwell Solutions\Maker 2.7\Webrun 2\tomcat\webapps\webrun/src/wfr/com/systems/system_lpo/rules/LpoObterMensagemsModificado.java:158: cannot find symbol symbol : method receiveMailWithAttachment(wfr.rules.Variant) location: class wfr.com.systems.system_lpo.rules.LpoObterMensagemsModificado ebfSetElementAtList(VARIABLE[2], ebfListParamsCreate(ebfEmailGetMessageFrom(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), VARIABLE[9], ebfEmailGetMessageSubject(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), receiveMailWithAttachment(ebfGetElementFromList(VARIABLE[0], VARIABLE[1]))), Variant.VARIANT_NULL); ^ 1 error at wfr.util.Functions.compileFile(Functions.java:3593) at wfr.util.Functions.compileFile(Functions.java:3557) at wfr.util.Functions.compileFile(Functions.java:3534) at wfr.rules.RulesClassLoader.compile(RulesClassLoader.java:140) at wfr.rules.WFRRuleManager.create(WFRRuleManager.java:377) at wfr.rules.WFRRuleManager.getRuleClass(WFRRuleManager.java:110) at wfr.web.actions.ExecuteRuleAction.execute(ExecuteRuleAction.java:160) at wfr.web.Action.doAction(Action.java:126) at wfr.web.Controller.process(Controller.java:100) at wfr.web.Controller.doPost(Controller.java:67) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at wfr.web.ContextFilter.doFilter(ContextFilter.java:86) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:595) Exceção Gerada

    Tentei testar com o trecho de código referente ao anexo comentado, porque ai ficaria idêntico a função email - corpo da mensagem. Porém o erro persistiu. Alguém pode me ajudar a entender o que está acontecendo?

    Obrigado


  • Causa:
    java.lang.Exception: C:\Arquivos de programas\Softwell Solutions\Maker 2.7\Webrun 2\tomcat\webapps\webrun/src/wfr/com/systems/system_lpo/rules/[b]LpoObterMensagemsModificado[/b].java:158: cannot find symbol symbol : [b]method receiveMailWithAttachment[/b](wfr.rules.Variant) location: class wfr.com.systems.system_lpo.rules.LpoObterMensagemsModificado [b]ebfSetElementAtList(VARIABLE[2], ebfListParamsCreate(ebfEmailGetMessageFrom(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), VARIABLE[9], ebfEmailGetMessageSubject(ebfGetElementFromList(VARIABLE[0], VARIABLE[1])), receiveMailWithAttachment(ebfGetElementFromList(VARIABLE[0], VARIABLE[1]))), [/b]Variant.VARIANT_NULL); ^ 1 error at wfr.util.Functions.compileFile(Functions.java:3593) at wfr.util.Functions.compileFile(Functions.java:3557) at



    O Erro ta dizendo tudo ai... so prestar atenção.. erro na regra LpoObterMensagemsModificado no metodo receiveMailWithAttachment

Log in to reply