DATA: G_AUTOF TYPE CHAR4.
DATA SEND_REQUEST TYPE REF TO CL_BCS. "CL_BCS 发送邮件主要用到的功能类, 包括创建发送请求, 添加发送内容,添加发送地址, 到最终的发送指令发出.
DATA DOCUMENT TYPE REF TO CL_DOCUMENT_BCS." 用来放置发送的内容.
DATA G_TEXT TYPE SOLI_TAB.
DATA G_CONTENT TYPE STRING.
DATA MAILTO TYPE AD_SMTPADR.
DATA RECIPIENT TYPE REF TO CL_CAM_ADDRESS_BCS.
DATA L_BCS_EXCEPTION TYPE REF TO CX_DOCUMENT_BCS.
DATA L_SEND_EXCEPTION TYPE REF TO CX_SEND_REQ_BCS.
DATA L_ADDR_EXCEPTION TYPE REF TO CX_ADDRESS_BCS.
DATA: IT_HEX1 TYPE SOLIX_TAB .
DATA: LV_XML TYPE XSTRING.
DATA:T_MAILHEX TYPE SOLIX_TAB.
DATA:I_RECORD TYPE SOLIX_TAB.
DATA:FILELEN TYPE I.
DATA: G_OVERDAT LIKE SY-DATUM.
DATA: BEGIN OF WA_ATTACH,
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
BANFN LIKE EBAN-BANFN,
BNFPO LIKE EBAN-BNFPO,
TXZ01 LIKE ZMMT116-TXZ01,
LIFNR LIKE LFA1-LIFNR,
NAME1 LIKE LFA1-NAME1,
OVERDAT LIKE ZMMT116-OVERDAT,
CRNAM LIKE ZMMT116-CRNAM,
ERNAM LIKE EKKO-ERNAM,
END OF WA_ATTACH.
DATA: GT_ATTACH LIKE WA_ATTACH OCCURS 0 WITH HEADER LINE.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE GT_ATTACH
FROM ****
WHERE ************.
TRY.
" 邮件正文
G_CONTENT = ''.
APPEND G_CONTENT TO G_TEXT.
G_CONTENT = 'DEAR SIR:' .
APPEND G_CONTENT TO G_TEXT.
G_CONTENT = ''.
APPEND G_CONTENT TO G_TEXT.
G_CONTENT = '...........................'.
APPEND G_CONTENT TO G_TEXT.
G_CONTENT = ''.
APPEND G_CONTENT TO G_TEXT.
APPEND G_CONTENT TO G_TEXT.
G_CONTENT = 'THANKS.'.
APPEND G_CONTENT TO G_TEXT.
* 创建发送请求
SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = 'RAW'
I_TEXT = G_TEXT
I_IMPORTANCE = '1'
I_SUBJECT = '************' "郵件主題
).
*---------- 創建郵件的附件
*----內表作為郵件附件發送 BEGIN
DATA: TMPSTR TYPE STRING .
CLEAR: TMPSTR,I_RECORD,I_RECORD[].
DATA: TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
ENTER(2) TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,
N TYPE I.
DATA: BEGIN OF HEADTAB OCCURS 0 ,
LENGTH TYPE I ,
DECIMALS TYPE I,
TYPE_KIND TYPE C,
NAME(30) TYPE C,
END OF HEADTAB.
DATA DESCR_REF TYPE REF TO CL_ABAP_STRUCTDESCR.
FIELD-SYMBOLS: <COMP_WA> TYPE ABAP_COMPDESCR ,
<F_FIELD> ,
<F_T_ATTACH> TYPE ANY .
DATA:STR TYPE STRING,
STR2 TYPE STRING ,
TEXT1 TYPE C.
DESCR_REF ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( GT_ATTACH ). "導出表頭內容BANFN BNFPO MATNR TXZ01 MEINS EKGRP MENGE等等
LOOP AT DESCR_REF->COMPONENTS ASSIGNING <COMP_WA>.
MOVE-CORRESPONDING <COMP_WA> TO HEADTAB.
APPEND HEADTAB.
ENDLOOP.
DESCRIBE TABLE HEADTAB LINES N.
LOOP AT GT_ATTACH ASSIGNING <F_T_ATTACH>.
DO N TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F_T_ATTACH> TO <F_FIELD>.
STR = <F_FIELD>.
READ TABLE HEADTAB INDEX SY-INDEX.
IF HEADTAB-TYPE_KIND = 'I' OR HEADTAB-TYPE_KIND = 'P'
OR HEADTAB-TYPE_KIND = 'F'.
SEARCH STR FOR '-'.
IF SY-SUBRC = 0 AND SY-FDPOS <> 0.
SPLIT STR AT '-' INTO STR TEXT1.
CONDENSE STR.
CONCATENATE '-' STR INTO STR.
ELSE.
CONDENSE STR.
ENDIF.
ELSE.
* SHIFT STR LEFT DELETING LEADING '0' .
ENDIF.
CONCATENATE STR2 TAB STR INTO STR2.
ENDDO.
SHIFT STR2.
CONCATENATE TMPSTR STR2 ENTER INTO TMPSTR.
CLEAR STR2.
ENDLOOP.
CONCATENATE '採購單號' TAB
'採購單項目' TAB
'請購單號' TAB
'請購單項目' TAB
'物料說明' TAB
'供應商代碼' TAB
'供應商名稱' TAB
'完工日期' TAB
'開單人' TAB
'需求人' ENTER
TMPSTR INTO TMPSTR.
DATA:TMPBUFFER TYPE XSTRING.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = TMPSTR
MIMETYPE = '"TEXT/HTML; CHARSET=BIG5"'
* ENCODING = '8400'
IMPORTING
BUFFER = TMPBUFFER
EXCEPTIONS
FAILED = 1
OTHERS = 2.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = TMPBUFFER
APPEND_TO_TABLE = ''
IMPORTING
OUTPUT_LENGTH = FILELEN
TABLES
BINARY_TAB = I_RECORD.
APPEND LINES OF I_RECORD TO T_MAILHEX.
*----內表作為郵件附件發送 END
DOCUMENT->ADD_ATTACHMENT( "添加附件
I_ATTACHMENT_TYPE = 'XLS' " 附件格式
I_ATTACHMENT_SUBJECT = '*****************' " ATTACHMENT NAME
" I_ATTACHMENT_SIZE = SIZE "附件大小
I_ATT_CONTENT_HEX = T_MAILHEX ).
CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
* CALL METHOD L_SEND_REQUEST->SET_SENDER
* EXPORTING
* I_SENDER = L_SENDER.
"邮件地址
CLEAR :MAILTO.
MAILTO = '736998669@qq.com'.
RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( MAILTO ).
SEND_REQUEST->ADD_RECIPIENT( RECIPIENT ).
SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ).
CALL METHOD SEND_REQUEST->SEND( ).
COMMIT WORK.
CATCH CX_DOCUMENT_BCS INTO L_BCS_EXCEPTION.
CATCH CX_SEND_REQ_BCS INTO L_SEND_EXCEPTION.
CATCH CX_ADDRESS_BCS INTO L_ADDR_EXCEPTION.
ENDTRY.
ABAP 发送邮件
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一、邮件分享 1、iOS系统自带邮件设置邮箱(此处以QQ邮箱为例) a.打开电脑,登录邮箱(以QQ邮箱为例),进入...
- 之前写过用标准库使用Python Smtplib 和email发送邮件,感觉很繁琐,久了不用之后便忘记了。前几天看...
- 1.从http://glob.com.au/sendmail/下载sendmail.zip 2.解压到C:下,例如...
- 第一,是技术救助,接收的都是技术人员,那么一定要简洁明了,标题要简单,很容易使人明白,对于问题最好一句话就能说明问...