项目中,经常会有需求,向客户,供应商发送邮件,但是会有一些格式上的要求。
我们一般使用长文本来处理此类需求
举例,客户需要发送一个如下邮件主体内容(带格式)
Dear Customer,
Attached is your most recent Account Statement. Currently, you are able to see all the Opening Invoices and Credit Memos in your account. Please make the payment at your earliest convenience. If you have any questions, please feel free to contact us! We appreciate your business!
Best wish
XXXX
首先,我们需要将客户给的模板去转换成HTML格式
我这个需求比较简单,所以我用的在线网站转换
转换文本为HTML (99cankao.com)
如果复杂的,可以自己去敲、
我们可以通过SO10 去创建长文本,将你转换出来的内容复制进去
结果如图
然后再发送邮件的时候,用read text 函数读取
DATA: CT_MAIL_BODY TYPE BCSY_TEXT.
DATA: LS_MAIL_BODY TYPE SOLI.
DATA: LT_TLINE TYPE STANDARD TABLE OF TLINE.
DATA: LS_TLINE TYPE TLINE.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
ID = 'ST'
LANGUAGE = SY-LANGU
NAME = 'ZINVOICE_EMAIL_BODY'
OBJECT = 'TEXT'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = LT_TLINE
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT LT_TLINE INTO LS_TLINE.
CLEAR:LS_MAIL_BODY.
LS_MAIL_BODY-LINE = LS_TLINE-TDLINE.
APPEND LS_MAIL_BODY TO CT_MAIL_BODY.
ENDLOOP.
TRY.
LCL_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = 'HTM'
I_TEXT = LT_MAIL_BODY
I_SUBJECT = LV_SUBJECT ).
CATCH CX_DOCUMENT_BCS .
ENDTRY.