DATA: GI_RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE,
GI_OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE, "
GI_OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE, "
GI_OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE, "
GI_OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE, "
GW_DOCDATA LIKE SODOCCHGI1,
GV_LINES TYPE SY-INDEX.
*********************************************
* SEND MAIL TO THE PERSON IN CHANGE
*********************************************
FORM SENDMAIL.
DATA: ADR6_WA TYPE T_ADR6 ,
DOMAIN TYPE C LENGTH 10 VALUE '@163.com',
MAILAD TYPE C LENGTH 30 .
CONCATENATE P_BNAME DOMAIN INTO MAILAD.
TRANSLATE MAILAD TO LOWER CASE.
GI_RECLIST-RECEIVER = MAILAD.
GI_RECLIST-REC_TYPE = 'U'. " U:Email
GI_RECLIST-EXPRESS = 'X'. " set popup
APPEND GI_RECLIST.
* mack mail body
PERFORM MAKE_MAIL_BODY.
* set mail title
MOVE TEXT-M01 TO GW_DOCDATA-OBJ_DESCR . "mail title
GW_DOCDATA-OBJ_NAME = 'SENDFILE'.
DESCRIBE TABLE GI_OBJTXT LINES GV_LINES.
* READ TABLE GI_OBJTXT INDEX GV2_LINES.
GW_DOCDATA-DOC_SIZE = ( GV_LINES - 1 ) * 255 + STRLEN( GI_OBJTXT ).
* Create the entry for the compressed document
REFRESH: GI_OBJPACK.
GI_OBJPACK-HEAD_START = 1.
GI_OBJPACK-HEAD_NUM = 0.
GI_OBJPACK-BODY_START = 1.
GI_OBJPACK-BODY_NUM = GV_LINES.
GI_OBJPACK-DOC_TYPE = 'HTM'. "
APPEND GI_OBJPACK.
*-- Send Email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = GW_DOCDATA
TABLES
PACKING_LIST = GI_OBJPACK
OBJECT_HEADER = GI_OBJHEAD
CONTENTS_BIN = GI_OBJBIN
CONTENTS_TXT = GI_OBJTXT
RECEIVERS = GI_RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
IF SY-SUBRC <> 0.
MESSAGE 'Outlook mail send error' TYPE 'I'.
ELSE.
COMMIT WORK.
ENDIF.
CLEAR GI_RECLIST.
ENDFORM.