SAP邮件发送

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一、***************************************
在SAP中我们可以配置STMP邮件功能,可以通过SOST来查看邮件状态,在编码中可用FM SO_DOCUMENT_SEND_API1 、SO_NEW_DOCUMENT_ATT_SEND_API1通过编码的方式来发送邮件以及邮件附件。

在定义附件表时用solisti1,其长度为Char255,实际中我们导出的每一行记录都会超出这个长度。

对XLS格试的附件我们可以用Excel的分隔标签来解决这个问题,对于文字乱码我们可以在附件加charset=utf-16le解决此类问题。

同样,也适用于其他类似的乱码问题。

constants: c_tab type c value cl_abap_char_utilities=>horizontal_tab,
c_cret type c value cl_abap_char_utilities=>cr_lf,
c_mimetype type char64
value 'APPLICATION/MSEXCEL;charset=utf-16le'.
data: v_xattach type xstring,
it_binary_attach type solix_tab.
*---------------------------------------------------------------------------------
* Convert the internal data to XString
*----------------------------------------------------------------------------------
data: lc_descr_ref type ref to cl_abap_structdescr,
lv_value type char128,
lv_temp type string,
lv_mid type string,
lv_tabix type sy-tabix.
field-symbols: <fs_intable> type any.
field-symbols: <intable_wa> type abap_compdescr.
loop at it_table.
lv_tabix = sy-tabix.
clear lv_temp.
lc_descr_ref ?= cl_abap_typedescr=>describe_by_data( it_table ).
loop at lc_descr_ref->components assigning <intable_wa>.
assign component sy-tabix of structure in_table to <fs_table>.
lv_value = <fs_table>.
condense lv_value.
if sy-tabix = 1.
lv_temp = lv_value.
continue.
endif.
concatenate lv_temp lv_value
into lv_temp separated by c_tab.
endloop.
concatenate lv_mid lv_temp c_cret into lv_mid.
endloop.
* Convert string to xstring type
* 'APPLICATION/MSEXCEL;charset=utf-16le'
call function 'SCMS_STRING_TO_XSTRING'
exporting
text = lv_mid
mimetype = c_mimetype
importing
buffer = v_xattach
exceptions
failed = 1
others = 2.
* Add the file header for utf-16le. .
if sy-subrc = 0.
concatenate cl_abap_char_utilities=>byte_order_mark_little
v_xattach into v_xattach in byte mode.
endif.
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = v_xattach
tables
binary_tab = it_binary_attach.
*---------------------------------------------------------------------------------
*Send Email
*----------------------------------------------------------------------------------
data: lv_title type so_obj_des, " Email Title
lv_email type adsmtp-smtp_addr, " Receiver
lv_attitle type char50. " Attachment Title
data: send_request type ref to cl_bcs,
document type ref to cl_document_bcs,
conlengths type so_obj_len,
html type table of w3html,
sender_id type ref to if_sender_bcs,
recipient type ref to if_recipient_bcs,
cc_recipient type ref to if_recipient_bcs,
sent_to_all type os_boolean,
bcs_exception type ref to cx_bcs,
bcs_message type string.
clear: lv_email,
lv_title,
html. " Email Body Content with html format
try.
* request email function
clear send_request.
send_request = cl_bcs=>create_persistent( ).
* Create the content of email
clear document .
document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = html
i_length = conlengths
i_subject = lv_title ).
* Add Attachment
call method document->add_attachment
exporting
i_attachment_type = 'XLS'
i_attachment_subject = lv_attitle
i_att_content_hex = it_binary_attach.
* Add document to send request
call method send_request->set_document( document ).
clear recipient.
recipient =
cl_cam_address_bcs=>create_internet_address( lv_email ).
* Add recipient with its respective attributes to send request
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = 'X'.
* E-mail
call method send_request->set_status_attributes
exporting
i_requested_status = 'E'
i_status_mail = 'E'.
call method send_request->set_send_immediately( 'X' ).
* Send document
call method send_request->send(
exporting
i_with_error_screen = 'X'
receiving
result = sent_to_all ).
if sent_to_all = 'X' and sy-batch <> 'X'.
message 'Send Successfully' type 'I'.
endif.
commit work.
catch cx_bcs into bcs_exception.
bcs_message = bcs_exception->get_text( ).
if sy-batch <> 'X'.
message bcs_exception type 'E'.
else.
write: bcs_message.
endif.
exit.
endtry.
二、SAP OFFCIE功能发送邮件
SAP做为自成一体的系统,其开发环境有着丰富的资源,其中就包括发送邮件的SAP Office 组件。

通过SAP组件,可以实现向Internet发送邮件。

通过CALL FUNCTION'SO_OBJ ECT_SEND' ,就可以实现邮件的发送,下面的代码片断,就举例说明了参数的作用。

必须说明的是,下面的代码,只是在发送的邮件中提供一个文本类型的附件。

大家在使用
SAP的Office发送邮件的时候,可以带上上传的文件做为邮件附件,还可以使用ALV的内容做为附件(在标准ALV,工具上有发送邮件)。

这些理论上都是可行的,只是小弟还不知道,所以这里只是抛个砖,有玉的请尽管砸过来~~~~~
data:object_hd_change LIKE sood1 OCCURS 10 WITH HEADER LINE," 邮件正文的头信息
receivers LIKE soos1 OCCURS 10 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 10 WITH HEADER LINE," 邮件附件的头信息
objcont LIKE soli OCCURS 10 WITH HEADER LINE," 邮件正文
att_cont LIKE soli OCCURS 10 WITH HEADER LINobject_hd_changeE," 邮件附件
att_head LIKE soli OCCURS 10 WITH HEADER LINE." 头行
data:count TYPE i,length TYPE i.
data:lc_item1(24)type c.
data:lc_item2(24)type c.
data:lc_line_sub(29)type c.
data:lc_line_sub2(52)type c.
data:ls_data type string.
data:li_len type i.
data:ls_title type string.
refresh:objcont,receivers,packing_list,
objcont,att_cont,att_head.
CLEAR:ATT_CONT-LINE.
att_cont-line = '附件文本的标题'.
ls_title =att_cont-line.
append att_cont.
* 放入附件内表
CLEAR:ATT_CONT-LINE.
ATT_CONT-LINE = '附件文本内容.
append att_cont. "如果有行内容,可以append多次
move'邮件内容标题'to objcont-line.
APPEND objcont.
move'file'to att_head-line.
append att_head.
DESCRIBE TABLE objcont LINES count.
DESCRIBE FIELD objcont-line LENGTH length IN BYTE MODE .
object_hd_change-objla ='E'."创建文档使用的语言
object_hd_change-objnam ='LIST'."文档,文件夹或分配清单的名称object_hd_change-objdes =gs_string."内容的简短描述CHAR50 object_hd_change-objsns ='O'."对象:灵敏度P机密F功能O标准object_hd_change-objlen =count * length. "文档内容的大小
append object_hd_change.
* 接收者
receivers-recextnam ='seewood@'.
receivers-recesc ='U'." 地址类型,U: 互联网地址
APPEND receivers." 收件人地址
DESCRIBE TABLE att_cont LINES count." 邮件附件总行数
DESCRIBE FIELD att_cont-line LENGTH length" 邮件每行的长度
IN BYTE MODE .
packing_list-head_start ='1'."传输包中的对象表头开始行packing_list-body_start ='1'."对象包中的对象内容开始行packing_list-head_num ='0'."在对象包内的对象表头行号packing_list-body_num =count * length. "在对象包内的对象内容行号packing_list-objtp ='RAW'."文档类别代码
packing_list-OBJDES =gs_string.
packing_list-OBJNAM =gs_string.
* OBJDES OBJNAM
APPEND packing_list.
* 调用函数发送邮件
CALL FUNCTION'SO_OBJECT_SEND'
EXPORTING
* New object: General header data
object_hd_change =object_hd_change
object_type ='RAW'" RAW SAP编辑程序文件
SENDER =sy-uname " 发送者用户名
TABLES
objcont =objcont " Content
* Recipient table with send attributes
receivers =receivers " 接收人地址
packing_list =packing_list " 邮件内容
att_cont =att_cont " 附件
ATT_HEAD =att_head " 标题
EXCEPTIONS
active_user_not_exist =1
communication_failure =2
component_not_available =3
folder_not_exist =4
folder_no_authorization =5
forwarder_not_exist =6
note_not_exist =7
object_not_exist =8
object_not_sent =9
object_no_authorization =10
object_type_not_exist =11
operation_no_authorization =12 owner_not_exist =13
parameter_error =14
substitute_not_active =15
substitute_not_defined =16
system_failure =17
too_much_receivers =18
user_not_exist =19
originator_not_exist =20
x_error =21
OTHERS=22.
PR_SUBRC =SY-SUBRC.
IF SY-SUBRC =0.
COMMIT WORK.
ENDIF.。

相关文档
最新文档