Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Can any one tell me how to send Body in Email

Hi,

I have a internal table which contain information

Dear Sir,

pls find attached file.

Thanks and Regards

chandra

I want to send that message with attached PDF file,

my PDF file is going as a attached format if email address is maintained in Customer master table.

Regards

Chandra.

Former Member
Former Member replied

Hi chandrashekar,

DATA:
 I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,
 I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,
 I_RECEIVERS TYPE  TABLE OF SOMLRECI1 WITH HEADER LINE,
 I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
 I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
 I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
 I_OBJBIN LIKE SOLISTI1  OCCURS 0 WITH HEADER LINE,
 I_RECLIST LIKE SOMLRECI1  OCCURS 0 WITH HEADER LINE.

DATA:
  W_OBJHEAD TYPE SOLI_TAB,
  W_CTRLOP TYPE SSFCTRLOP,
  W_COMPOP TYPE SSFCOMPOP,
  W_RETURN TYPE SSFCRESCL,
  W_DOC_CHNG TYPE SODOCCHGI1,
  W_DATA TYPE SODOCCHGI1,
  W_BUFFER TYPE STRING.

DATA:
 V_FORM_NAME TYPE RS38L_FNAM,
 V_LEN_IN LIKE SOOD-OBJLEN,
 V_LEN_OUT LIKE SOOD-OBJLEN,
 V_LEN_OUTN TYPE I,
 V_LINES_TXT TYPE I,
 V_LINES_BIN TYPE I.


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    FORMNAME           = '  '
  IMPORTING
    FM_NAME            = V_FORM_NAME
  EXCEPTIONS
    NO_FORM            = 1
    NO_FUNCTION_MODULE = 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.

W_CTRLOP-GETOTF = 'X'.
W_CTRLOP-NO_DIALOG = 'X'.
W_COMPOP-TDNOPREV = 'X'.


CALL FUNCTION '/1BCDWB/SF00000482'
  EXPORTING
    CONTROL_PARAMETERS = W_CTRLOP
    OUTPUT_OPTIONS     = W_COMPOP
    USER_SETTINGS      = 'X'
  IMPORTING
    JOB_OUTPUT_INFO    = W_RETURN
  EXCEPTIONS
    FORMATTING_ERROR   = 1
    INTERNAL_ERROR     = 2
    SEND_ERROR         = 3
    USER_CANCELED      = 4.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

I_OTF[] = W_RETURN-OTFDATA[].



CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    FORMAT                = 'PDF'
    MAX_LINEWIDTH         = 132
  IMPORTING
    BIN_FILESIZE          = V_LEN_IN
  TABLES
    OTF                   = I_OTF
    LINES                 = I_TLINE
  EXCEPTIONS
    ERR_MAX_LINEWIDTH     = 1
    ERR_FORMAT            = 2
    ERR_CONV_NOT_POSSIBLE = 3
    ERR_BAD_OTF           = 4.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


LOOP AT I_TLINE.

  TRANSLATE I_TLINE USING '~'.
  CONCATENATE W_BUFFER I_TLINE INTO W_BUFFER.

ENDLOOP.

TRANSLATE W_BUFFER USING '~'.


DO.
  I_RECORD = W_BUFFER.
  APPEND I_RECORD.
  SHIFT W_BUFFER LEFT BY 255 PLACES.
  IF W_BUFFER IS INITIAL.
    EXIT.
  ENDIF.
ENDDO.

REFRESH :
  I_RECLIST,
  I_OBJTXT,
  I_OBJBIN,
  I_OBJPACK.

CLEAR W_OBJHEAD.

I_OBJBIN[] = I_RECORD[].
DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.


I_OBJTXT = 'Find attached the output of the smartform.'.
APPEND I_OBJTXT.
I_OBJTXT = 'Regards,'.
APPEND I_OBJTXT.
I_OBJTXT = 'Sravanthi'.
APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.


W_DOC_CHNG-OBJ_NAME = 'Smartform'.
W_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10 .
W_DOC_CHNG-OBJ_DESCR  = 'Smart form output'.
W_DOC_CHNG-SENSITIVTY = 'F'.
W_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 0.
I_OBJPACK-BODY_START = 1.
I_OBJPACK-BODY_NUM = V_LINES_TXT.
I_OBJPACK-DOC_TYPE = 'RAW'.
APPEND I_OBJPACK.

I_OBJPACK-TRANSF_BIN = 'X'.
I_OBJPACK-HEAD_START = 1.
I_OBJPACK-HEAD_NUM = 1.
I_OBJPACK-BODY_START = 1.
I_OBJPACK-BODY_NUM = V_LINES_BIN.
I_OBJPACK-DOC_TYPE  = 'PDF'.
I_OBJPACK-OBJ_NAME = 'Smartform'.
CONCATENATE 'smartform output' 'pdf'
INTO I_OBJPACK-OBJ_DESCR.
I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255.
APPEND I_OBJPACK.

CLEAR I_RECLIST.


I_RECLIST-RECEIVER = ' '.---------------> email id
I_RECLIST-EXPRESS  = 'X'.
I_RECLIST-REC_TYPE  = 'U'.
APPEND I_RECLIST.


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    DOCUMENT_DATA              = W_DOC_CHNG
    PUT_IN_OUTBOX              = 'X'
    commit_work                = 'X'
  TABLES
    PACKING_LIST               = I_OBJPACK
   CONTENTS_BIN                = I_OBJBIN
    OBJECT_HEADER              = W_OBJHEAD
    CONTENTS_TXT               = I_OBJTXT
    RECEIVERS                  = I_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 NE 0.
      WRITE:/ 'Error When Sending the File', sy-subrc.
    ELSE.
      WRITE:/ 'Mail sent'.
    ENDIF.

After exceuting this program check status of the mail in the SOST transaction.

Regards,

Sravanthi

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question