REPORT mailtest.
DATA gv_method1 LIKE sy-ucomm.
DATA gs_user LIKE soudnamei1.
DATA gs_user_data LIKE soudatai1.
DATA gv_owner LIKE soud-usrnam.
DATA gt_receipients LIKE soos1 OCCURS 0 WITH HEADER LINE.
DATA gs_document LIKE sood4 .
DATA gs_header2 LIKE sood2.
DATA gs_folmam LIKE sofm2.
DATA gt_objcnt LIKE soli OCCURS 0 WITH HEADER LINE.
DATA gt_objhead LIKE soli OCCURS 0 WITH HEADER LINE.
DATA gt_objpara LIKE selc OCCURS 0 WITH HEADER LINE.
DATA gt_objparb LIKE soop1 OCCURS 0 WITH HEADER LINE.
DATA gt_attachments LIKE sood5 OCCURS 0 WITH HEADER LINE.
DATA gt_references LIKE soxrl OCCURS 0 WITH HEADER LINE.
DATA gs_reciver LIKE soos6 .
DATA gv_authority LIKE sofa-usracc.
DATA gs_ref_document LIKE sood4.
DATA gs_new_parent LIKE soodk.
DATA: BEGIN OF gt_files OCCURS 10 ,
text(4096) TYPE c,
END OF gt_files.
DATA : gv_fold_number(12) TYPE c,
gv_fold_yr(2) TYPE c,
gv_fold_type(3) TYPE c.
DATA: gs_folder_id LIKE soodk,
gs_order_id LIKE soodk.
DATA: gv_mail_title(50).
DATA: gt_receivers LIKE soos1 OCCURS 0 WITH HEADER LINE.
INITIALIZATION.
START-OF-SELECTION.
gv_mail_title = '这是邮件标题'.
** 发件人信息 edit
PERFORM so_user_read.
**邮件信息、属性定义
PERFORM document_repository.
**附件生成
PERFORM creat_attachments.
**send mail
PERFORM send.
*&---------------------------------------------------------------------*
*& Form SO_USER_READ
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM so_user_read .
gs_user-sapname = sy-uname.
CALL FUNCTION 'SO_USER_READ_API1'
EXPORTING
user = gs_user
IMPORTING
user_data = gs_user_data
EXCEPTIONS
user_not_exist = 1
parameter_error = 2
x_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
gv_fold_type = gs_user_data-outboxfol+0(3).
gv_fold_yr = gs_user_data-outboxfol+3(2).
gv_fold_number = gs_user_data-outboxfol+5(12).
CLEAR: gt_files[], gt_files.
REFRESH : gt_objcnt,
gt_objhead,
gt_objpara,
gt_objparb,
gt_receipients,
gt_attachments,
gt_references,
gt_files.
CLEAR : gs_document,
gs_header2,
gt_objcnt,
gt_objhead,
gt_objpara,
gt_objparb,
gt_receipients,
gt_attachments,
gt_references,
gt_files.
ENDFORM. " SO_USER_READ
*&---------------------------------------------------------------------*
*& Form DOCUMENT_REPOSITORY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM document_repository .
gv_method1 = 'SAVE'.
gs_document-foltp = gv_fold_type.
gs_document-folyr = gv_fold_yr.
gs_document-folno = gv_fold_number.
gs_document-objtp = gs_user_data-object_typ.
*g_document-OBJYR = '27'.
*g_document-OBJNO = '000000002365'.
*g_document-OBJNAM = 'MESSAGE'.
gs_document-objdes = 'mail of sap by program'.
gs_document-folrg = 'O'.
*g_document-okcode = 'CHNG'.
gs_document-objlen = '0'.
* g_document-file_ext = 'TXT'.
gs_header2-objdes = gv_mail_title.
* g_header-file_ext = 'TXT'.
gt_objcnt-line = 'Dear liuxy'.
APPEND gt_objcnt.
gt_objcnt-line = ' this is my first email.'.
APPEND gt_objcnt.
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
EXPORTING
method = gv_method1
office_user = sy-uname
ref_document = gs_ref_document
new_parent = gs_new_parent
IMPORTING
authority = gv_authority
TABLES
objcont = gt_objcnt
objhead = gt_objhead
objpara = gt_objpara
objparb = gt_objparb
recipients = gt_receipients
attachments = gt_attachments
references = gt_references
files = gt_files
CHANGING
document = gs_document
header_data = gs_header2.
ENDFORM. " DOCUMENT_REPOSITORY
*&---------------------------------------------------------------------*
*& Form CREAT_ATTACHMENTS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM creat_attachments .
* File from the pc to send..
gv_method1 = 'ATTCREATEFROMPC'.
* GV_SAVE_PATHT = P_FILE.
gt_files-text = 'D:\AAA.pdf'.
APPEND gt_files.
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
EXPORTING
method = gv_method1
office_user = gv_owner
ref_document = gs_ref_document
new_parent = gs_new_parent
IMPORTING
authority = gv_authority
TABLES
objcont = gt_objcnt
objhead = gt_objhead
objpara = gt_objpara
objparb = gt_objparb
recipients = gt_receipients
attachments = gt_attachments
references = gt_references
files = gt_files
CHANGING
document = gs_document
header_data = gs_header2.
ENDFORM. " CREAT_ATTACHMENTS
*&---------------------------------------------------------------------*
*& Form SEND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send .
CLEAR: gs_folder_id,gs_order_id.
gs_folder_id-objtp = gs_document-foltp .
gs_folder_id-objyr = gs_document-folyr.
gs_folder_id-objno = gs_document-folno.
gs_order_id-objtp = gs_document-objtp.
gs_order_id-objyr = gs_document-objyr.
gs_order_id-objno = gs_document-objno.
*收件人信息可以添加多个收件人-----------------------------------
REFRESH gt_receivers.
gt_receivers-recesc = 'U'.
gt_receivers-sndex = 'X'.
gt_receivers-recextnam = '5923071@qq.com'.
APPEND gt_receivers.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
folder_id = gs_folder_id
object_id = gs_order_id
TABLES
objcont = gt_objcnt
objhead = gt_objhead
objpara = gt_objpara
objparb = gt_objparb
receivers = gt_receivers
packing_list = gt_attachments
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
x_error = 20
OTHERS = 21.
COMMIT WORK.
******直接发送邮件的代码********
SUBMIT rsconn01 WITH mode ='INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " SEND
ABAP 发送邮件(可用发送任何本地文件做为附件)
最新推荐文章于 2024-02-05 14:23:17 发布