使用SO_DOCUMENT_SEND_API1发送邮件
程序员文章站
2022-03-18 20:39:46
...
DATA: L_ATTLEN TYPE I,
L_MAILEN TYPE I,
L_BINLEN TYPE I,
"将附件内容拼接成一个字符串存储到该变量
L_ATTACHMENT TYPE STRING.
DATA: GT_BINARY LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
"储存附件内容的内表
DATA: BEGIN OF GT_ATTACHMENT OCCURS 0,
ID TYPE I,
NAME(10),
PRICE TYPE P,
END OF GT_ATTACHMENT.
"储存邮件内容的内表
DATA: LT_MAILBODY TYPE TABLE OF SOLISTI1,
LS_MAILBODY LIKE LINE OF LT_MAILBODY.
"邮件属性结构
DATA: LS_SODOCCHGI1 TYPE SODOCCHGI1,
"邮件组件(附件、邮件内文等)属性内表
LT_SOPCKLSTI1 TYPE TABLE OF SOPCKLSTI1,
LS_SOPCKLSTI1 LIKE LINE OF LT_SOPCKLSTI1,
"收件人内表
LT_SOMLRECI1 TYPE TABLE OF SOMLRECI1,
LS_SOMLRECI1 LIKE LINE OF LT_SOMLRECI1.
"添加收件人
LS_SOMLRECI1-RECEIVER = '[email protected]'.
LS_SOMLRECI1-REC_TYPE = 'U'.
LS_SOMLRECI1-COPY = 'X'.
APPEND LS_SOMLRECI1 TO LT_SOMLRECI1.
LS_SOMLRECI1-RECEIVER = '[email protected]'.
LS_SOMLRECI1-REC_TYPE = 'U'.
LS_SOMLRECI1-BLIND_COPY = 'X'.
APPEND LS_SOMLRECI1 TO LT_SOMLRECI1.
"添加附件内容
GT_ATTACHMENT-ID = 1.
GT_ATTACHMENT-NAME = 'NAME1'.
GT_ATTACHMENT-PRICE = 11.
APPEND GT_ATTACHMENT.
GT_ATTACHMENT-ID = 2.
GT_ATTACHMENT-NAME = 'NAME2'.
GT_ATTACHMENT-PRICE = 12.
APPEND GT_ATTACHMENT.
DESCRIBE TABLE GT_ATTACHMENT LINES L_ATTLEN.
"添加邮件内容内容
LS_MAILBODY = '<HTML><BODY>'.
APPEND LS_MAILBODY TO LT_MAILBODY.
CONCATENATE '<P><FONT SIZE = 2 >' SY-DATUM '</FONT></P>' INTO LS_MAILBODY.
APPEND LS_MAILBODY TO LT_MAILBODY.
LS_MAILBODY = '<TABLE WIDTH=100% BORDER=1 CELLSPACING=0><TR BGCOLOR=#00CCFF>'.
APPEND LS_MAILBODY TO LT_MAILBODY.
READ TABLE GT_ATTACHMENT INDEX 1.
CONCATENATE '<TD>' GT_ATTACHMENT-ID '</TD></TR></TABLE>' INTO LS_MAILBODY.
APPEND LS_MAILBODY TO LT_MAILBODY.
CONCATENATE '<p><span style=''font-size:10.0pt;color:#999999''>'
'Client-' SY-MANDT
'</span></p></body></html>' INTO LS_MAILBODY.
APPEND LS_MAILBODY TO LT_MAILBODY.
DESCRIBE TABLE LT_MAILBODY LINES L_MAILEN.
"将附件内表转换为一STRING
PERFORM ITABTOSTR TABLES GT_ATTACHMENT USING L_ATTACHMENT.
"将储存附件内容的STRING转换为BIN
PERFROM STRTOBIN TABLES GT_BINARY USING L_ATTACHMENT L_BINLEN.
"设置邮件属性
LS_SODOCCHGI1-OBJ_DESCR = 'SUBJECT'.
LS_SODOCCHGI1-OBJ_LANGU = SY-LANGU.
LS_SODOCCHGI1-SENSITIVTY = 'F'.
LS_SODOCCHGI1-DOC_SIZE = L_MAILEN.
"设置邮件附件属性
LS_SOPCKLSTI1-TRANSF_BIN = 'X'.
LS_SOPCKLSTI1-HEAD_START = 1.
LS_SOPCKLSTI1-HEAD_NUM = 0.
LS_SOPCKLSTI1-BODY_START = 1.
LS_SOPCKLSTI1-BODY_NUM = L_ATTLEN.
LS_SOPCKLSTI1-DOC_TYPE = 'XLS'.
LS_SOPCKLSTI1-OBJ_DESCR = 'SUBJECT'.
LS_SOPCKLSTI1-DOC_SIZE = LS_SOPCKLSTI1-BODY_NUM * 255.
APPEND LS_SOPCKLSTI1 TO LT_SOPCKLSTI1.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = LS_SODOCCHGI1
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = LT_SOPCKLSTI1
CONTENTS_BIN = GT_BINARY
CONTENTS_TXT = LT_MAILBODY
RECEIVERS = LT_SOMLRECI1
EXCEPTIONGS
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.
上一篇: CDR怎么制作线框透镜效果?