Problema enviando email

Colapsar
X
 
  • Tiempo
  • Mostrar
Limpiar Todo
nuevos mensajes
  • marianoboni
    Member
    • abr
    • 75

    #1

    Problema enviando email

    Buenos días

    Problema:
    Aplicación no envía email; tampoco acusa ningún tipo de error.
    El codigo que utilizo para enviar el email esta tomado de los ejemplos de SAP ( BCS_EXAMPLE_7 u BCS_EXAMPLE_8). Si corro estos ejemplos SAP envía el email correctamente; Funciona también si copio estos programas y los corro con la trz SE38.

    La diferencia entre éstos radica en que mi programa no es un Report, si no que invoco el procedimiento desde un DYNPRO.

    Otros datos:
    -para el envío uso SAPConnect ( funciona correctamente ).
    -verifico los emails con SOST

    Todo parece indicar que hay alguna propiedad de mi aplicación que esta imposibilitando el envío y al no haber exepción alguna se dificulta ver el problema.
    Desde ya agradezco cualquier tipo de orientación.

    Mariano
    Editado por última vez por marianoboni; 16/09/2011, 18:17:19.
  • SAPING
    Senior Member
    • may
    • 199

    #2
    Fijate si el mail destinatario esta cargado en la trx SCOT.
    Proba agregando uno a mano.
    Tambien proba haciendo un COMMIT al final de la funcion. Yo tuve un inconveniente similar, donde me dejaba encolados los mails y no los enviaba. Luego de poner el COMMIT se soluciono el problema.

    El codigo que use yo es el siguiente:

    FORM f_enviar_mail TABLES pt_notificadores
    pt_log.

    DATA: w_notificadores TYPE pa0105-usrid_long.

    *** Estructuras para mails
    DATA: BEGIN OF i_text OCCURS 0.
    INCLUDE STRUCTURE soli.
    DATA: END OF i_text.

    DATA: wspoolnumber LIKE sy-spono ,
    wmailname LIKE sood1-objnam,
    wsubject LIKE sood1-objdes ,
    wrecepient(40) TYPE c ,
    wdli LIKE soos1-dlinam.

    DATA: object_hd_change LIKE sood1 OCCURS 0 WITH HEADER LINE,
    objpara LIKE selc OCCURS 0 WITH HEADER LINE,
    receivers LIKE soos1 OCCURS 0 WITH HEADER LINE.

    DATA: BEGIN OF i_receivers OCCURS 0.
    INCLUDE STRUCTURE receivers.
    DATA: END OF i_receivers.

    CONSTANTS: lc_docu(12) TYPE c VALUE 'Documentos:',
    lc_det(8) TYPE c VALUE 'Detalle:'.

    ************************************************** *********************

    * seteo el ASUNTO
    READ TABLE pt_log INDEX 1.
    IF sy-subrc IS INITIAL.
    * Si son registros OK
    IF pt_log-error IS INITIAL.

    wsubject = 'registros ok'.

    ELSE."son registros erroneos

    wsubject = 'registros no ok'.

    ENDIF.

    ENDIF.
    * Seteo datos de cabecera de mensaje
    object_hd_change-objla = sy-langu.
    object_hd_change-objdes = wsubject.
    object_hd_change-objsns = 'F'.
    object_hd_change-vmtyp = 'T'.
    object_hd_change-skips = 'X'.
    object_hd_change-acnam = 'SP01'.
    object_hd_change-objcp = 'X'.

    * Coloco en el cuerpo del mens los docs
    i_text-line = lc_docu.
    APPEND i_text.
    CLEAR i_text.
    LOOP AT pt_log. "mi tabla de registros procesados

    i_text-line = 'mensaje'.
    APPEND i_text.
    CLEAR i_text.

    ENDLOOP.

    * Ingreso las cuentas de mails obtenidas en un form anterior
    REFRESH i_receivers.
    CLEAR i_receivers.
    i_receivers-rcdat = sy-datum.
    i_receivers-rctim = sy-uzeit.
    i_receivers-recesc = 'U'.
    i_receivers-sndex = 'X'. " Express-Mail

    LOOP AT pt_notificadores INTO w_notificadores.

    MOVE w_notificadores TO i_receivers-recextnam.
    APPEND i_receivers.
    CLEAR i_receivers-recextnam.

    ENDLOOP.


    * envio los mails
    CALL FUNCTION 'SO_OBJECT_SEND'
    EXPORTING
    object_hd_change = object_hd_change
    object_type = 'RAW'
    owner = sy-uname
    TABLES
    objcont = i_text
    receivers = i_receivers
    EXCEPTIONS
    active_user_not_exist = 1
    communication_failure = 2
    component_not_available = 3
    folder_not_exist = 4
    folder_no_authorization = 5
    forwarder_not_exist = 6
    note_not_exist = 7
    object_not_exist = 8
    object_not_sent = 9
    object_no_authorization = 10
    object_type_not_exist = 11
    operation_no_authorization = 12
    owner_not_exist = 13
    parameter_error = 14
    substitute_not_active = 15
    substitute_not_defined = 16
    system_failure = 17
    too_much_receivers = 18
    user_not_exist = 19
    originator_not_exist = 20
    x_error = 21
    OTHERS = 22.

    IF sy-subrc IS NOT INITIAL.
    MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    COMMIT WORK.
    ENDFORM. " f_enviar_mail

    Desde la SCOT vas a Utilidades/Resumenes de ordenes de envio y te tira el listado y status de los mails.

    Saludos.

    Comentario

    • marianoboni
      Member
      • abr
      • 75

      #3
      Originalmente publicado por SAPING
      Fijate si el mail destinatario esta cargado en la trx SCOT.
      Proba agregando uno a mano.
      Tambien proba haciendo un COMMIT al final de la funcion. Yo tuve un inconveniente similar, donde me dejaba encolados los mails y no los enviaba. Luego de poner el COMMIT se soluciono el problema.

      El codigo que use yo es el siguiente:

      FORM f_enviar_mail TABLES pt_notificadores
      pt_log.

      DATA: w_notificadores TYPE pa0105-usrid_long.

      *** Estructuras para mails
      DATA: BEGIN OF i_text OCCURS 0.
      INCLUDE STRUCTURE soli.
      DATA: END OF i_text.

      DATA: wspoolnumber LIKE sy-spono ,
      wmailname LIKE sood1-objnam,
      wsubject LIKE sood1-objdes ,
      wrecepient(40) TYPE c ,
      wdli LIKE soos1-dlinam.

      DATA: object_hd_change LIKE sood1 OCCURS 0 WITH HEADER LINE,
      objpara LIKE selc OCCURS 0 WITH HEADER LINE,
      receivers LIKE soos1 OCCURS 0 WITH HEADER LINE.

      DATA: BEGIN OF i_receivers OCCURS 0.
      INCLUDE STRUCTURE receivers.
      DATA: END OF i_receivers.

      CONSTANTS: lc_docu(12) TYPE c VALUE 'Documentos:',
      lc_det(8) TYPE c VALUE 'Detalle:'.

      ************************************************** *********************

      * seteo el ASUNTO
      READ TABLE pt_log INDEX 1.
      IF sy-subrc IS INITIAL.
      * Si son registros OK
      IF pt_log-error IS INITIAL.

      wsubject = 'registros ok'.

      ELSE."son registros erroneos

      wsubject = 'registros no ok'.

      ENDIF.

      ENDIF.
      * Seteo datos de cabecera de mensaje
      object_hd_change-objla = sy-langu.
      object_hd_change-objdes = wsubject.
      object_hd_change-objsns = 'F'.
      object_hd_change-vmtyp = 'T'.
      object_hd_change-skips = 'X'.
      object_hd_change-acnam = 'SP01'.
      object_hd_change-objcp = 'X'.

      * Coloco en el cuerpo del mens los docs
      i_text-line = lc_docu.
      APPEND i_text.
      CLEAR i_text.
      LOOP AT pt_log. "mi tabla de registros procesados

      i_text-line = 'mensaje'.
      APPEND i_text.
      CLEAR i_text.

      ENDLOOP.

      * Ingreso las cuentas de mails obtenidas en un form anterior
      REFRESH i_receivers.
      CLEAR i_receivers.
      i_receivers-rcdat = sy-datum.
      i_receivers-rctim = sy-uzeit.
      i_receivers-recesc = 'U'.
      i_receivers-sndex = 'X'. " Express-Mail

      LOOP AT pt_notificadores INTO w_notificadores.

      MOVE w_notificadores TO i_receivers-recextnam.
      APPEND i_receivers.
      CLEAR i_receivers-recextnam.

      ENDLOOP.


      * envio los mails
      CALL FUNCTION 'SO_OBJECT_SEND'
      EXPORTING
      object_hd_change = object_hd_change
      object_type = 'RAW'
      owner = sy-uname
      TABLES
      objcont = i_text
      receivers = i_receivers
      EXCEPTIONS
      active_user_not_exist = 1
      communication_failure = 2
      component_not_available = 3
      folder_not_exist = 4
      folder_no_authorization = 5
      forwarder_not_exist = 6
      note_not_exist = 7
      object_not_exist = 8
      object_not_sent = 9
      object_no_authorization = 10
      object_type_not_exist = 11
      operation_no_authorization = 12
      owner_not_exist = 13
      parameter_error = 14
      substitute_not_active = 15
      substitute_not_defined = 16
      system_failure = 17
      too_much_receivers = 18
      user_not_exist = 19
      originator_not_exist = 20
      x_error = 21
      OTHERS = 22.

      IF sy-subrc IS NOT INITIAL.
      MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.

      COMMIT WORK.
      ENDFORM. " f_enviar_mail

      Desde la SCOT vas a Utilidades/Resumenes de ordenes de envio y te tira el listado y status de los mails.

      Saludos.
      Hola,
      mirá ese no es el problema, ya que utilizando la misma cuenta y codigo en un report funciona, puedo ver el email ( en vez de acceder por la SCOT uso la transaccion SOST ) en la cola de salida; en cambio cuando "copio y pego" el codigo con los mismos datos en el mismso entorno no funciona; ni siquiera aparece en la cola de salida.
      Gracias po la ayuda, voy a seguir renegando

      Comentario

      • SAPING
        Senior Member
        • may
        • 199

        #4
        oks... igualmente podrias probar de esta manera, como para descartar posibilidades..je..

        Si lo solucionas, compartilo !!

        Saludos y suerte.
        (perdon por no poder ayudarte mas)

        Comentario

        • jossnet
          Member
          • oct
          • 61

          #5
          Haz hecho un debug de tu aplicación?,postea tu código,no deberia haber problema si lo lanzas desde un dynpro.

          Comentario

          • marianoboni
            Member
            • abr
            • 75

            #6
            Codigo de mi aplicacion

            Este framgmento de codigo lo saque de un report: BCS_EXAMPLE_7


            form send.
            data send_request type ref to cl_bcs.
            data document type ref to cl_document_bcs.
            data recipient type ref to if_recipient_bcs.
            data bcs_exception type ref to cx_bcs.

            data main_text type bcsy_text.
            data binary_content type solix_tab.
            data size type so_obj_len.
            data sent_to_all type os_boolean.
            data mailto type ad_smtpadr.

            mailto = 'mariano.boni@aguasdesantafe.com.ar'.
            try.

            * -------- create persistent send request ------------------------
            send_request = cl_bcs=>create_persistent( ).

            * -------- create and set document with attachment ---------------
            * create document object from internal table with text
            append 'Hello world!' to main_text. "#EC NOTEXT
            document = cl_document_bcs=>create_document(
            i_type = 'RAW'
            i_text = main_text
            i_subject = 'Test Created By BCS_EXAMPLE_7' ). "#EC NOTEXT

            * add the spread sheet as attachment to document object
            document->add_attachment(
            i_attachment_type = 'xls' "#EC NOTEXT
            i_attachment_subject = 'ExampleSpreadSheet' "#EC NOTEXT
            i_attachment_size = size
            i_att_content_hex = binary_content ).

            * add document object to send request
            send_request->set_document( document ).

            * --------- add recipient (e-mail address) -----------------------
            * create recipient object
            recipient = cl_cam_address_bcs=>create_internet_address( mailto ).

            * add recipient object to send request
            send_request->add_recipient( recipient ).

            * ---------- send document ---------------------------------------
            sent_to_all = send_request->send( i_with_error_screen = 'X' ).

            commit work.

            if sent_to_all is initial.
            message i500(sbcoms) with mailto.
            else.
            message s022(so).
            endif.

            * ------------ exception handling ----------------------------------
            * replace this rudimentary exception handling with your own one !!!
            catch cx_bcs into bcs_exception.
            message i865(so) with bcs_exception->error_type.
            endtry.
            endform. "send

            Comentario

            • jossnet
              Member
              • oct
              • 61

              #7
              En document->add_attachment... estas intentando adjuntar algo pero las variables que pasas estan vacias, comenta esa parte si solo vas a enviar el mensaje.

              Comentario

              • marianoboni
                Member
                • abr
                • 75

                #8
                Originalmente publicado por jossnet
                En document->add_attachment... estas intentando adjuntar algo pero las variables que pasas estan vacias, comenta esa parte si solo vas a enviar el mensaje.
                Tenés razón. Motivado por esa falta hice lo siguiente:

                1) reemplace el form por el form del ejemplo BCS_EXAMPLE_1
                que es un envío simple.

                2) invoque desde mi programa via sentencia y funciono.

                FORM send .

                SUBMIT ZBCS_EXAMPLE_1
                AND RETURN.

                ENDFORM.

                3 ) reemplace la llamada del mencionado reporte y ¡no funciono!

                FORM send.

                DATA: send_request TYPE REF TO cl_bcs.
                DATA: text TYPE bcsy_text.
                DATA: document TYPE REF TO cl_document_bcs.
                DATA: sender TYPE REF TO cl_sapuser_bcs.
                DATA: recipient TYPE REF TO if_recipient_bcs.
                DATA: bcs_exception TYPE REF TO cx_bcs.
                DATA: sent_to_all TYPE os_boolean.
                TRY.
                * -------- create persistent send request ------------------------
                send_request = cl_bcs=>create_persistent( ).

                * -------- create and set document -------------------------------
                * create document from internal table with text
                APPEND 'Hello world!' TO text.
                document = cl_document_bcs=>create_document(
                i_type = 'RAW'
                i_text = text
                i_length = '12'
                i_subject = 'test created by BCS_EXAMPLE_1' ).

                * add document to send request
                CALL METHOD send_request->set_document( document ).

                * --------- set sender -------------------------------------------
                * note: this is necessary only if you want to set the sender
                * different from actual user (SY-UNAME). Otherwise sender is
                * set automatically with actual user.

                sender = cl_sapuser_bcs=>create( sy-uname ).
                CALL METHOD send_request->set_sender
                EXPORTING
                i_sender = sender.

                * --------- add recipient (e-mail address) -----------------------
                * create recipient - please replace e-mail address !!!
                recipient = cl_cam_address_bcs=>create_internet_address(
                'mariano.boni@aguasdesantafe.com.ar' ).

                * add recipient with its respective attributes to send request
                CALL METHOD send_request->add_recipient
                EXPORTING
                i_recipient = recipient
                i_express = 'X'.

                * ---------- send document ---------------------------------------
                CALL METHOD send_request->send(
                EXPORTING
                i_with_error_screen = 'X'
                RECEIVING
                result = sent_to_all ).
                IF sent_to_all = 'X'.
                WRITE text-003.
                ENDIF.

                COMMIT WORK.

                * -----------------------------------------------------------
                * * exception handling
                * -----------------------------------------------------------
                * * replace this very rudimentary exception handling
                * * with your own one !!!
                * -----------------------------------------------------------
                CATCH cx_bcs INTO bcs_exception.
                WRITE: text-001.
                WRITE: text-002, bcs_exception->error_type.
                EXIT.

                ENDTRY.

                ENDFORM.

                Comentario

                • marianoboni
                  Member
                  • abr
                  • 75

                  #9
                  Logica del programa

                  Mi programa es invocado por una trx la cual llama a un metodo de una clase.
                  Dicho metodo llama al DYNPRO.
                  Luego hay un boton que ejecuta un procedimiento dentro del dynpro.
                  Este es el contexto donde se ejecuta el codigo copiado del Standar.
                  Lo unico que se me ocurre es que puede haber algun tipo de control, que por algun motivo no esta saltando como excepcion.

                  Adjunte el log al cual accedo a través de la SOST.
                  En el mismo archivo va la primer corrida que pertenece al programa estructurado como indico arrriba.
                  La segunda corrida es la copia del ejemplo de sao, ejecutada desde la SE38.
                  Archivos Adjuntos

                  Comentario

                  • marianoboni
                    Member
                    • abr
                    • 75

                    #10
                    Problema Solucionado

                    Luego de renegar durante 4 días ayer encontré un nota ( 717265 ) que reconoce este error en la versión 6 de SAP.
                    Aconseja como primera aproximación que se cree una función RFC y se encapsule el código en ella.
                    Cuando hice pruebas invocando a los programas usando SUBMIT funcionaban, evidentemente se ejecutan en un espacio deferente de la misma manera que la RFC.
                    Saludos.

                    Comentario

                    • ing_Gmaurisio
                      Junior Member
                      • may
                      • 15

                      #11
                      Sendmail

                      Maria, podras ayudarme,, no he logrado configurar el correo en sap. ???????

                      Comentario

                      • marianoboni
                        Member
                        • abr
                        • 75

                        #12
                        Originalmente publicado por ing_Gmaurisio
                        Maria, podras ayudarme,, no he logrado configurar el correo en sap. ???????
                        Ok, ¿que es lo que estuviste haciendo?

                        Comentario

                        Trabajando...