cancel
Showing results for 
Search instead for 
Did you mean: 

Send mail with PDF File

Former Member
0 Kudos

Hi All,

I want to send mail along with PDF file. My program is working well upto PDF Conversion.But Sending mail is bot working properly. Can anyone give me coding to send mail with PDF file..

<b>

CALL FUNCTION 'CONVERT_OTF_2_PDF'

  • EXPORTING

  • USE_OTF_MC_CMD = 'X'

  • ARCHIVE_INDEX =

IMPORTING

BIN_FILESIZE = GV_DOC_SIZE

TABLES

OTF = IT_OTF

DOCTAB_ARCHIVE = IT_DOCTAB

LINES = IT_PDF_OUTPUT</b>

<b>

After this PDF conversion i want the coding for Send mail..Pls help me.</b>

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Resolved

Former Member
0 Kudos


DATA: mailid   TYPE STANDARD TABLE OF t_mailid,
          wa_mailid  TYPE t_mailid,
g_mail_rec_obj TYPE swotobjid,
g_mail_sen_obj TYPE swotobjid.

    LOOP AT s_smtp.
      mailid-mailid = s_smtp-low.
      APPEND wa_mailid TO itab_mailid.
    ENDLOOP.

        PERFORM prepare_mail TABLES itab
                              USING wa_mailid
                                    l_fmname
                                    p_sub.

*&---------------------------------------------------------------------*
*&      Form  prepare_mail
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM prepare_mail TABLES itab
                           USING u_mailid
                         u_formname
                         u_subject.


  MOVE u_mailid TO l_mail.
  PERFORM mail_recipient_object.
  PERFORM mail_sender_object.
  PERFORM mail_appl_object TABLES  itab
                           USING u_formname
                                  u_subject .


ENDFORM.                    " prepare_mail
*&---------------------------------------------------------------------*
*&      Form  mail_recipient_object
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM mail_recipient_object .

  l_rectype = 'U'.

  CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
    EXPORTING
      ip_mailaddr       = l_mail
      ip_type_id        =  l_rectype
    IMPORTING
      ep_recipient_id   = g_mail_rec_obj
    EXCEPTIONS
      invalid_recipient = 1
      OTHERS            = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDFORM.                    " mail_recipient_object
*&---------------------------------------------------------------------*
*&      Form  mail_sender_object
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM mail_sender_object .

  CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
    EXPORTING
      ip_sender      = sy-uname
    IMPORTING
      ep_sender_id   = g_mail_sen_obj
    EXCEPTIONS
      invalid_sender = 1
      OTHERS         = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDFORM.                    " mail_sender_object
*&---------------------------------------------------------------------*
*&      Form  mail_appl_object
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
FORM mail_appl_object TABLES itab
                       USING u_formname
                             u_subject .


  SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
  ENDSELECT.
  IF sy-subrc NE 0.

    CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT'
      EXPORTING
        sapname        = sy-uname
      EXCEPTIONS
        no_insert      = 1
        sap_name_exist = 2
        x_error        = 3
        OTHERS         = 4.
    IF sy-subrc NE 0.
      CLEAR soud.
    ELSE.
      SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
      ENDSELECT.
    ENDIF.
  ENDIF.

  CLEAR sofmfol_key.
  sofmfol_key-type = 'FOL'.
  sofmfol_key-year = soud-inbyr.
  sofmfol_key-number = soud-inbno.
  bor_key = sofmfol_key.
  IF NOT bor_key IS INITIAL.

  ELSE.
    CLEAR g_mail_app_obj.
  ENDIF.

  g_cont_par-device = 'MAIL'.
  g_output-tdtitle = u_subject.

  CALL FUNCTION u_formname
    EXPORTING
      control_parameters = g_cont_par
      mail_recipient     = g_mail_rec_obj
      mail_sender        = g_mail_sen_obj
      output_options     = g_output
    TABLES
      data                    = itab
    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.
  ELSE.
    COMMIT WORK.

    WAIT UP TO 2 SECONDS.
    SUBMIT rsconn01 WITH mode = 'INT'
                  WITH output = ' '
                  AND RETURN.
  ENDIF.

ENDFORM.                    " mail_appl_object

*reward for helpful answers.

thx

murthy

Former Member
0 Kudos

<b>CLOSE DUPLICATE THREADS AWARDING POINTS</b>

REPORT ZEXAMPLE.

DATA: ITCPO LIKE ITCPO,

TAB_LINES LIKE SY-TABIX.

  • Variables for EMAIL functionality

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

PERFORM SEND_FORM_VIA_EMAIL.

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

  • FORM SEND_FORM_VIA_EMAIL *

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

FORM SEND_FORM_VIA_EMAIL.

CLEAR: MAILDATA, MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

REFRESH: MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

  • Mail Contents

MAILTXT-LINE = 'Here is your file'.

APPEND MAILTXT.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

  • Set recipient - email address here!!!

MAILREC-RECEIVER = 'itsme@whatever.com'.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = ' '

TABLES

PACKING_LIST = MAILPACK

OBJECT_HEADER = MAILHEAD

CONTENTS_BIN = MAILBIN

CONTENTS_TXT = MAILTXT

RECEIVERS = MAILREC

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM.

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

  • Form PREPARE_PACKING_LIST

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

FORM PREPARE_PACKING_LIST.

CLEAR: MAILPACK, MAILBIN, MAILHEAD.

REFRESH: MAILPACK, MAILBIN, MAILHEAD.

DESCRIBE TABLE MAILTXT LINES TAB_LINES.

READ TABLE MAILTXT INDEX TAB_LINES.

MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).

  • Creation of the entry for the compressed document

CLEAR MAILPACK-TRANSF_BIN.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 0.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'RAW'.

APPEND MAILPACK.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM GET_OTF_CODE.

LOOP AT SOLISTI1.

MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.

APPEND MAILBIN.

ENDLOOP.

DESCRIBE TABLE MAILBIN LINES TAB_LINES.

MAILHEAD = 'TEST.OTF'.

APPEND MAILHEAD.

    • Creation of the entry for the compressed attachment

MAILPACK-TRANSF_BIN = 'X'.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 1.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'OTF'.

MAILPACK-OBJ_NAME = 'TEST'.

MAILPACK-OBJ_DESCR = 'Subject'.

MAILPACK-DOC_SIZE = TAB_LINES * 255.

APPEND MAILPACK.

ENDFORM.

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

  • Form GET_OTF_CODE

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

FORM GET_OTF_CODE.

DATA: BEGIN OF OTF OCCURS 0.

INCLUDE STRUCTURE ITCOO .

DATA: END OF OTF.

DATA: ITCPO LIKE ITCPO.

DATA: ITCPP LIKE ITCPP.

CLEAR ITCPO.

ITCPO-TDGETOTF = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'ZTEST_FORM'

LANGUAGE = SY-LANGU

OPTIONS = ITCPO

DIALOG = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

MOVE-CORRESPONDING ITCPO TO ITCPP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = ITCPP

TABLES

OTFDATA = OTF

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR SOLISTI1. REFRESH SOLISTI1.

LOOP AT OTF.

SOLISTI1-LINE = OTF.

APPEND SOLISTI1.

ENDLOOP.

ENDFORM.