1,获取操作员姓名
SELECT SINGLE ADRP~NAME_TEXT INTO GS_OUTPUT-UNAMT FROM ADRP INNER JOIN USR21 ON ADRP~PERSNUMBER = USR21~PERSNUMBER WHERE USR21~BNAME = GS_OUTPUT-UNAME.
2,获取操作员邮箱地址
SELECT SINGLE ADR6~SMTP_ADDR INTO GS_OUTPUT-EMAIL FROM ADR6 INNER JOIN USR21 ON ADR6~PERSNUMBER = USR21~PERSNUMBER WHERE USR21~BNAME = GS_OUTPUT-UNAME.
3,创建邮件FORM
FORM FRM_MAIL_BUILD . DATA: LV_EMAIL TYPE AD_SMTPADR, LV_UNAMT TYPE AD_NAMTEXT, LV_SUBJECT TYPE SO_OBJ_DES, LV_BODY_LIN TYPE W3HTML, LV_BODY_TEXT TYPE TABLE OF W3HTML. LV_SUBJECT = '邮件主题'. LOOP AT GT_OUTPUT INTO GS_OUTPUT. CLEAR: LV_EMAIL, LV_UNAMT. LV_EMAIL = GS_OUTPUT-EMAIL. LV_UNAMT = GS_OUTPUT-UNAMT. AT NEW UNAME. CLEAR LV_BODY_LIN. REFRESH LV_BODY_TEXT. CONCATENATE LV_BODY_LIN '<html><body><table width=100% border=1 cellpadding=0 cellspacing=0>' INTO LV_BODY_LIN. APPEND LV_BODY_LIN TO LV_BODY_TEXT. CLEAR LV_BODY_LIN. CONCATENATE LV_BODY_LIN '<tr>DEAR:' LV_UNAMT '</tr><br>' INTO LV_BODY_LIN. APPEND LV_BODY_LIN TO LV_BODY_TEXT. CLEAR LV_BODY_LIN. CONCATENATE LV_BODY_LIN '<tr>请注意如下人员:' '</tr>' INTO LV_BODY_LIN. APPEND LV_BODY_LIN TO LV_BODY_TEXT. CLEAR LV_BODY_LIN. CONCATENATE '<tr><td align=center height=10>' '人员编号' '</td><td align=center height=10>' '姓名' '</td><td align=center height=10>' '合同号' '</td><td align=center height=10>' '单位名称' '</td><td align=center height=10>' '操作人' '</td></tr>' INTO LV_BODY_LIN. APPEND LV_BODY_LIN TO LV_BODY_TEXT. ENDAT. CLEAR LV_BODY_LIN. CONCATENATE '<tr><td align=center height=10>' GS_OUTPUT-PERNR '</td><td align=center height=10>' GS_OUTPUT-ZNAME '</td><td align=center height=10>' GS_OUTPUT-ZOBJID '</td><td align=center height=10>' GS_OUTPUT-ZSTEXT '</td><td align=center height=10>' GS_OUTPUT-UNAMT '</td></tr>' INTO LV_BODY_LIN. APPEND LV_BODY_LIN TO LV_BODY_TEXT. AT END OF UNAME. CLEAR LV_BODY_LIN. CONCATENATE LV_BODY_LIN '</table></body></html>' INTO LV_BODY_LIN. APPEND LV_BODY_LIN TO LV_BODY_TEXT. * 调用发送邮件FORM PERFORM FRM_MAIL_SENT USING LV_EMAIL LV_SUBJECT LV_BODY_TEXT. ENDAT. ENDLOOP. ENDFORM.
4,发送邮件FORM
FORM FRM_MAIL_SENT USING P_EMAIL P_SUBJECT P_BODY_TEXT. DATA: LV_EMAIL TYPE AD_SMTPADR, LV_DOCUMENT TYPE REF TO CL_DOCUMENT_BCS, LV_SEND_REQUEST TYPE REF TO CL_BCS, LV_CL_REQ_BCS TYPE REF TO CL_SEND_REQUEST_BCS, LV_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS, BCS_EXCEPTION TYPE REF TO CX_BCS. TRY. *创建发送请求 LV_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ). *创建发送内容 LV_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT( I_TYPE = 'HTM' I_TEXT = P_BODY_TEXT I_SUBJECT = P_SUBJECT ). *添加发送内容到发送请求 LV_SEND_REQUEST->SET_DOCUMENT( LV_DOCUMENT ). *邮件地址 *1、清空 CALL METHOD CL_SEND_REQUEST_BCS=>CREATE RECEIVING RESULT = LV_CL_REQ_BCS. CALL METHOD LV_CL_REQ_BCS->REMOVE_RECIPIENTS. *2、转换 TRANSLATE P_EMAIL TO LOWER CASE. LV_EMAIL = P_EMAIL. LV_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( LV_EMAIL ). *3、添加 CALL METHOD LV_SEND_REQUEST->ADD_RECIPIENT EXPORTING I_RECIPIENT = LV_RECIPIENT I_EXPRESS = 'X'. * 设置立即发送标志 CALL METHOD LV_SEND_REQUEST->SET_STATUS_ATTRIBUTES EXPORTING I_REQUESTED_STATUS = 'E' I_STATUS_MAIL = 'E'. LV_SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ). * 发送 CALL METHOD LV_SEND_REQUEST->SEND. COMMIT WORK AND WAIT . SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN. * CATCH CX_SEND_REQ_BCS . CATCH CX_BCS INTO BCS_EXCEPTION. MESSAGE S865(SO) DISPLAY LIKE 'E' WITH BCS_EXCEPTION->ERROR_TYPE . ENDTRY. ENDFORM.