cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in sending email with the smartform output as PDF attachment.

Former Member
0 Kudos

Hi,

I have written a code to send a email with the smartform output as attachment. But the problem is, though the code runs successfully (all sy-subrc checks are 0), still the email is not being sent to the recipient.

I am posting the code below :

"Calling the smartform function module.

DATA: l_formname TYPE tdsfname,
        l_fm_name TYPE rs38l_fnam,
        l_control_param TYPE ssfctrlop,
        l_output_options TYPE ssfcompop,
        l_device LIKE itcpp-tddest VALUE 'LP01',
        l_job_info TYPE ssfcrescl .

  l_formname = text-008.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = l_formname
    IMPORTING
      fm_name            = l_fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  l_control_param-no_dialog = 'X'.
  l_control_param-preview = 'X'.
  l_control_param-getotf = c_email.
  l_output_options-tddest = l_device.

  CALL FUNCTION l_fm_name
    EXPORTING
      wa_output_header   = wa_output_header
      control_parameters = l_control_param
      output_options     = l_output_options
      user_settings      = ''
    IMPORTING
      job_output_info    = l_job_info
    TABLES
      it_po              = it_po
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  IF c_email = 'X'. "If this checkbox is selected, then send email.    
    PERFORM prepare_and_send_mail USING l_job_info.
  ENDIF.
ENDFORM.                    " DISPLAY_SMARTFORM

Continued in the next post.......................

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Continued......


*&---------------------------------------------------------------------*
*&      Form  SEND_MAIL
*&---------------------------------------------------------------------*
*       Description - Sends the mail to the destination addresses.
*----------------------------------------------------------------------*
FORM send_mail.
  DATA: it_objheader TYPE STANDARD TABLE OF solisti1,
        it_email_body TYPE STANDARD TABLE OF solisti1,
        wa_email_body TYPE solisti1,
        l_com_type TYPE  somlreci1-com_type VALUE 'INT',
        l_doc_data TYPE sodocchgi1,
        it_reclist TYPE STANDARD TABLE OF somlreci1,
        wa_reclist LIKE LINE OF it_reclist,
        it_packing_list TYPE STANDARD TABLE OF sopcklsti1,
        wa_packing_list TYPE sopcklsti1.

  IF NOT it_packing_list IS INITIAL.
    CLEAR it_packing_list[].
  ENDIF.

  CLEAR wa_packing_list.
  wa_packing_list-head_start = 1.
  wa_packing_list-head_num = 0.
  DESCRIBE TABLE it_pdf LINES wa_packing_list-body_num.
  wa_packing_list-doc_type = 'RAW'.
  APPEND wa_packing_list TO it_packing_list.

  CLEAR wa_packing_list.
  wa_packing_list-transf_bin = 'X'.
  wa_packing_list-head_start = 1.
  wa_packing_list-head_num = 1.
  wa_packing_list-body_start = 1.
  DESCRIBE TABLE it_pdf LINES wa_packing_list-body_num.
  wa_packing_list-doc_type = 'PDF'.
  wa_packing_list-obj_name = 'PO_DATA.PDF'.
  wa_packing_list-obj_descr = 'PO Data'.
  wa_packing_list-doc_size = wa_packing_list-body_num * 255.
  APPEND wa_packing_list TO it_packing_list.

  CLEAR l_doc_data.
  l_doc_data-sensitivty = 'F'.
  l_doc_data-obj_name = 'PO_DATA.PDF'.
  l_doc_data-obj_descr = 'PO Data'.

  IF it_email_body[] IS INITIAL.
    CLEAR wa_email_body.
    wa_email_body-line = 'Please download the attachment.'.
    APPEND wa_email_body TO it_email_body.

* Convert the contents of email_body1 to a format rtf.
    CALL FUNCTION 'SO_RAW_TO_RTF'
      TABLES
        objcont_old = it_email_body
        objcont_new = it_email_body
      EXCEPTIONS
        OTHERS      = 0.
  ENDIF.

Continued in the next post.....

Former Member
0 Kudos

+*Form SENDMAIL continued.....*+_

CLEAR g_str_emails.
  g_str_emails = p_emaddr.
  IF NOT it_mailaddrs[] IS INITIAL.
    REFRESH it_mailaddrs[].
  ENDIF.

  IF NOT it_reclist[] IS INITIAL.
    REFRESH it_reclist[].
  ENDIF.

  SPLIT g_str_emails AT ';' INTO TABLE it_mailaddrs.
  LOOP AT it_mailaddrs INTO wa_mailaddr.
    CONDENSE wa_mailaddr-email NO-GAPS.
    CLEAR wa_reclist.
    wa_reclist-receiver = wa_mailaddr-email.
    wa_reclist-rec_type = 'U'.        "Internet address
    wa_reclist-com_type = l_com_type. "Transmission Medium = Internet.
    APPEND wa_reclist TO it_reclist.
  ENDLOOP.

* Now send the mail to the spool.
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = l_doc_data
    TABLES
      packing_list               = it_packing_list
      contents_bin               = it_pdf
      contents_txt               = it_email_body
      receivers                  = it_reclist
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
* Now send the mail to the world.
    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = l_com_type
        WITH output = ' ' AND RETURN.
    MESSAGE text-033 TYPE 'I'.
  ENDIF.
ENDFORM.                    " SEND_MAIL

former_member205763
Active Contributor
0 Kudos

in the fm 'SO_NEW_DOCUMENT_ATT_SEND_API1' u hv an exporting parameter commit_work just set it to 'X' it will work.

Former Member
0 Kudos

Thanks Kartik. It is solved now.

Answers (3)

Answers (3)

Former Member
0 Kudos

Though the email is being sent to the recipient successfully, but the pdf attachment becomes corrupted. I have searched in sdn and lots of other sites and have tried the ways mentioned there but in vain. Please give any hint or clue.

Former Member
0 Kudos

Hi,

Set the parameters as below before calling the smartforms FM.


l_control_param-GETOTF = 'X'.
l_control_param-NO_DIALOG = 'X'.
l_output_options-tdnoprev = 'X'.

CALL FUNCTION l_fm_name
    EXPORTING
      wa_output_header   = wa_output_header
      control_parameters = l_control_param
      output_options     = l_output_options
      user_settings      = 'X'             
    IMPORTING
      job_output_info    = l_job_info
    TABLES
      it_po              = it_po
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
  IF sy-subrc  0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
CALL FUNCTION 'CONVERT_OTF'
 EXPORTING
   FORMAT                      = 'PDF'
   MAX_LINEWIDTH               = 132
*   ARCHIVE_INDEX               = ' '
*   COPYNUMBER                  = 0
*   ASCII_BIDI_VIS2LOG          = ' '
*   PDF_DELETE_OTFTAB           = ' '
 IMPORTING
   BIN_FILESIZE                = v_len_in
*   BIN_FILE                    =
  TABLES
    otf                         = i_otf
    lines                       = i_tline
 EXCEPTIONS
   ERR_MAX_LINEWIDTH           = 1
   ERR_FORMAT                  = 2
   ERR_CONV_NOT_POSSIBLE       = 3
   ERR_BAD_OTF                 = 4.

Regards,

Raju.

Former Member
0 Kudos

Hi Raju,

Thanks for your reply, but whatever you have mentioned, I have done just that in my program. If you can check out the "long" code that I have posted here, everything seems to be very ok to me. But still the email is not being sent to the recipient's email address.

I have checked with the transaction transaction SO01 (SAP Inbox).. Whatever mails I am sending from there, the mails are being forwarded successfully to the recipient's addresses. What could possibly be the problem with my code? Is there any problem with the configuration in SAP?

Former Member
0 Kudos

Hi Anirban,

Did you find the attachement SAP Inbox?

If yes then the mail server ( domain ) should be configure to SAP. Take help from basis guys.

Regards,

Raju.

Former Member
0 Kudos

...Continued


*&---------------------------------------------------------------------*
*&      Form  PREPARE_AND_SEND_MAIL
*&---------------------------------------------------------------------*
*       Description - Prepare data for smartform to be sent as email.
*----------------------------------------------------------------------*
FORM prepare_and_send_mail USING p_job_info TYPE ssfcrescl.
  DATA:
        it_pdfdata TYPE TABLE OF tline,
        it_otfdata TYPE TABLE OF itcoo,
        l_bin_filesize TYPE i.


  it_otfdata[] = p_job_info-otfdata[].
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = l_bin_filesize
*     bin_file              =
    TABLES
      otf                   = it_otfdata[]
      lines                 = it_pdfdata[]
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4
      OTHERS                = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    REFRESH it_pdf[].

* To send data as email attachment, we need to have a table of SOLISTI1.
* This table contains line size of 255 characters. Below function module
* does the trick of changing the table from X character sized lines into
* any given Y character sized lines.
    CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
      EXPORTING
        line_width_dst              = '255'
      TABLES
        content_in                  = it_pdfdata[]
        content_out                 = it_pdf[]
      EXCEPTIONS
        err_line_width_src_too_long = 1
        err_line_width_dst_too_long = 2
        err_conv_failed             = 3
        OTHERS                      = 4.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
      PERFORM send_mail.
    ENDIF.
  ENDIF.
ENDFORM.                    " PREPARE_AND_SEND_MAIL

Continued in the next post...