form frm_send_mail .
data: objpack like sopcklsti1 occurs 2 with header line.
data: objhead like solisti1 occurs 1 with header line.
* DATA: OBJBIN LIKE SOLIX OCCURS 10 WITH HEADER LINE.
data objbin like solisti1 occurs 0 with header line.
data: objtxt like solisti1 occurs 10 with header line.
data: reclist like somlreci1 occurs 5 with header line.
data: objhex like solix occurs 10 with header line.
data: doc_chng like sodocchgi1.
data: tab_lines like sy-tabix.
data:sender_address like soextreci1-receiver value 'account@teamwisepower.com.cn'.
data: tmpstr type string .
data:i_record like solix occurs 0 with header line, "solisti1
filelen type i.
data: v_lines_bin_all type i ,
v_lines_bin type i .
data:lv_str type string.
data:lv_recname type ad_smtpadr .
data:lt_mail like standard table of zcfg_mail with header line .
data :begin of lt_address occurs 0 ,
smtp_addr type ad_smtpadr ,
end of lt_address .
data :begin of lt_ccaddress occurs 0 ,
smtp_addr type ad_smtpadr ,
end of lt_ccaddress .
*** Mail Object
concatenate lv_str '贸易料检验批监控' into doc_chng-obj_descr separated by space.
*** 邮件正文
clear objtxt.
objtxt = '你好,:'.
append objtxt.
clear objtxt.
append objtxt.
clear objtxt.
objtxt = '附件是贸易料检验批
,请查收,谢谢 '.
append objtxt.
describe table objtxt lines tab_lines.
read table objtxt index tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
* Packing List For the E-mail Body
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
append objpack.
**内表作为邮件附件
clear: tmpstr,i_record,i_record[].
perform itabtostr tables gt_xml using tmpstr.
perform strtorecord tables i_record using tmpstr filelen.
append lines of i_record to objhex."objbin.
describe table i_record lines v_lines_bin.
describe table objhex lines v_lines_bin_all."objbin
objhead = '贸易料检验批清单 '.
append objhead.
* Packing List For the E-mail Attachment
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = v_lines_bin.
objpack-obj_descr = '贸易料检验批清单'.
objpack-obj_name = '贸易料检验批清单.xls' .
objpack-doc_type = 'XLS'.
objpack-doc_size = v_lines_bin_all * 255.
append objpack.
**** 取发件人和收件人以及抄送人,
select *
into corresponding fields of table lt_mail
from zcfg_mail
where progname = 'ZMMR074'.
if sy-subrc = 0 .
read table lt_mail index 1 .
split lt_mail-recname at '/' into table lt_address .
split lt_mail-ccname at '/' into table lt_ccaddress .
endif.
loop at lt_address.
clear reclist .
reclist-receiver = lt_address-smtp_addr.
* RECLIST-EXPRESS = 'X'. "发送快件
reclist-rec_type = 'U'.
translate reclist-receiver to upper case.
append reclist.
endloop.
loop at lt_ccaddress.
clear reclist .
reclist-receiver = lt_ccaddress-smtp_addr.
reclist-copy = 'X'. "抄送
reclist-rec_type = 'U'.
translate reclist-receiver to upper case.
append reclist.
endloop.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = doc_chng
put_in_outbox = 'X'
sender_address = sender_address "'qyyu@teamwisepower.com.cn'
sender_address_type = 'SMTP'"B
commit_work = 'X'
tables
packing_list = objpack
object_header = objhead
* contents_bin = objbin
contents_txt = objtxt
contents_hex = objhex
* OBJECT_PARA =
* OBJECT_PARB =
receivers = reclist
exceptions
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.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
wait up to 2 seconds.
submit rsconn01 with mode = 'INT' and return.
message '发送成功' type 'S'.
endif.
endform. " FRM_SEND_MAIL
*&---------------------------------------------------------------------*
*& Form itabtostr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->INTAB text
* -->OUTSTR text
*----------------------------------------------------------------------*
form itabtostr tables intab
using outstr type string.
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:
type abap_compdescr ,
,
type any .
data:str type string,
str2 type string ,
text1 type c.
descr_ref ?= cl_abap_typedescr=>describe_by_data( intab ).
loop at descr_ref->components assigning .
move-corresponding to headtab.
append headtab.
endloop.
describe table headtab lines n.
loop at intab assigning .
do n times.
assign component sy-index of structure to .
str = .
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 outstr str2 enter into outstr.
clear str2.
endloop.
endform. " ITABTOSTR
*&---------------------------------------------------------------------*
*& Form STRTORECORD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_RECORD text
* -->P_TMPSTR text
* -->P_FILELEN text
*----------------------------------------------------------------------*
form strtorecord tables record using str len.
data:tmpbuffer type xstring.
call function 'SCMS_STRING_TO_XSTRING'
exporting
text = str
mimetype = '"text/html; charset=gb2312"'
* 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 = len
tables
binary_tab = record.
endform. "strtorecord