function zint_send_email.
*"----------------------------------------------------------------------
*"*"區域介面:
*" IMPORTING
*" VALUE(KTYPE) TYPE SO_OBJ_TP DEFAULT 'RAW'
*" VALUE(SUBJECT) TYPE SO_OBJ_DES
*" VALUE(TEXT) TYPE SOLI_TAB
*" VALUE(SENDER_ADDRESS) TYPE AD_SMTPADR
*" VALUE(SENDER_NAME) TYPE AD_SMTPADR OPTIONAL
*" VALUE(ATTACHMENTS) TYPE RMPS_T_POST_CONTENT OPTIONAL
*" VALUE(IMMEDIATELY) TYPE BOOLEAN OPTIONAL
*" EXPORTING
*" VALUE(E_RESULT) TYPE BOOLEAN
*" TABLES
*" T_RECIPIENT STRUCTURE UPS_YS_HR_CPERSON
*" RETURN STRUCTURE BAPIRET2
*"----------------------------------------------------------------------

data:send_request type ref to cl_bcs,
document type ref to cl_document_bcs,
sender_id type ref to if_sender_bcs,
fail type ref to cx_bcs,
recipient type ref to if_recipient_bcs.

data:w_return like bapiret2,
w_rename type ad_smtpadr,
w_attachment like line of attachments,
w_attachment_subject type sood-objdes.

*BREAK CP900.
refresh return.
clear e_result.
e_result = 'X'.
if ktype is initial.
w_return-type = 'E'.
w_return-message = '未指定文件類別代碼'.
w_return-parameter = 'KTYPE'.
append w_return to return.
clear e_result.
endif.

if subject is initial.
w_return-type = 'E'.
w_return-message = '未指定郵件主題'.
w_return-parameter = 'SUBJECT'.
append w_return to return.
clear e_result.
endif.

if text[] is initial.
w_return-type = 'E'.
w_return-message = '未指定郵件內容'.
w_return-parameter = 'TEXT'.
append w_return to return.
clear e_result.
endif.

if sender_address is initial.
w_return-type = 'E'.
w_return-message = '未指定發送人郵件地址'.
w_return-parameter = 'SENDER_ADDRESS'.
append w_return to return.
clear e_result.
endif.
if t_recipient[] is initial.
w_return-type = 'E'.
w_return-message = '未指定接收人郵件地址'.
w_return-parameter = 'RECIPIENT'.
append w_return to return.
clear e_result.
endif.

clear w_return.

check e_result is not initial.

try.
* 第一步: 创建发送请求
send_request = cl_bcs=>create_persistent( ).

* 第二步: 创建整理发送内容
document = cl_document_bcs=>create_document(
i_type = ktype
i_text = text
i_subject = subject ).
* 增加附件內容
loop at attachments into w_attachment.
w_attachment_subject = w_attachment-subject.
document->add_attachment(
exporting
i_attachment_type = w_attachment-objtp
i_attachment_subject = w_attachment_subject
i_att_content_hex = w_attachment-cont_hex ).
endloop.
* 第三步: 添加邮件内容到发送请求
send_request->set_document( document ).

* 第四步:設置發送人出件地址
sender_id = cl_cam_address_bcs=>create_internet_address(
i_address_string = sender_address
i_address_name = sender_name ).
send_request->set_sender( sender_id ).

* 第五步: 接收者邮件地址转换
loop at t_recipient where cperson ne '99999999'.
w_rename = t_recipient-emnam.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = t_recipient-e_mail
i_address_name = w_rename ).
send_request->add_recipient( recipient ).
endloop.

loop at t_recipient where cperson eq '99999999'.
w_rename = t_recipient-emnam.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = t_recipient-e_mail
i_address_name = w_rename ).
* SEND_REQUEST->ADD_RECIPIENT( RECIPIENT ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_copy = 'X'.
endloop.

* 第六步,設置狀態屬性
send_request->set_status_attributes(
i_requested_status = 'E'
i_status_mail = 'E' ).
send_request->set_send_immediately( immediately ).

* 第七步: 正式发送并提交作业
send_request->send( i_with_error_screen = 'X' ).
commit work and wait.
catch cx_bcs into fail.
e_result = ''.
w_return-type = 'E'.
w_return-message = fail->get_text( ).
append w_return to return.
clear w_return.
endtry.

endfunction.

ABAP 邮件的更多相关文章

  1. ABAP发邮件函数

    步骤: 一.检查输入参数, (1)未指定文件類別代碼,(2)未指定郵件主題, (3)未指定郵件內容, (4)未指定發送人郵件地址, (5)未指定接收人郵件地址, 二.调用发送功能, (1)创建发送请求 ...

  2. ABAP 发邮件(三)

    [转自http://blog.sina.com.cn/s/blog_7c7b16000101bnxk.html]SAP ABAP 发邮件方法三(OO) *&------------------ ...

  3. 【ABAP系列】SAP 如何用ABAP实现自动发送外部邮件

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 如何用ABAP实现自动发 ...

  4. 【ABAP系列】SAP ABAP实现发送外部邮件(添加附件)功能

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP实现发送外部邮件(添 ...

  5. 【ABAP系列】SAP ABAP模块-任意report作为附件以邮件形式发送

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP模块-任意rep ...

  6. ABAP开发顾问必备:SAP ABAP开发技术总结

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  7. ABAP常用函数集锦

    函数名 描述 SD_VBAP_READ_WITH_VBELN 根据销售订单读取表vbap中的信息EDIT_LINES 把READ_TEXT返回的LINES中的行按照TDFORMAT=“*”重新组织VI ...

  8. ABAP 常用FUNCTION集锦(转)

    此文章从网上抄摘,目的用于自己记录 DYNP_VALUES_READ – 读取SCREEN字段的值,也可以用来读取报表SELECTION SCREEN. DYNP_VALUES_UPDATE – 更新 ...

  9. abap 常用 function

    ABAP常用函数总结  alv .smartform. excel .text.邮件 .远程访问,FTP服务器...  **********常用功能function REUSE_ALV_GRID_DI ...

随机推荐

  1. Druid配置

    spring-mybatis.xml <!-- 定义数据源Bean --> <!-- Druid --> <bean id="dataSource" ...

  2. 阿里巴巴集团加入W3C,成为W3C会员

    根据W3C官方推特最新消息:阿里巴巴集团正式加入W3C,成为W3C会员. W3C官方推特:https://twitter.com/w3c/status/566244180372889601 同时可以在 ...

  3. spring用到的设计模式

    https://www.cnblogs.com/yuefan/p/3763898.html https://www.cnblogs.com/hwaggLee/p/4510687.html https: ...

  4. python007 Python3 数字(Number)

    var1 = 1 var2 = 10 您也可以使用del语句删除一些数字对象的引用.del语句的语法是: del var1[,var2[,var3[....,varN]]]] 您可以通过使用del语句 ...

  5. 【网络流】【待补】C. Heidi and Library (hard)

    http://codeforces.com/contest/802/problem/C

  6. hdu 2795线段树

    #include<stdio.h> #define N 200005 int h,w,n; struct node { int x,y,max; }a]; int mmax(int e,i ...

  7. lubuntu通过Smb访问Windows共享目录

    lubuntu通过Smb访问Windows共享目录 如果未安装Smb,先安装: apt-get install smbclient smbfs 安装后,查看共享主机上的共享目录: CentOS/Red ...

  8. Iahub and Permutations(codeforces 314c)

    题意:给出一组排列,某些位置不知道(-1),要求求出有多少种还原方式,使得所有a[i]!=i /* 这是一道关于排列的动态规划,这种体大都可以当作棋盘来做,如果把i这个数放到第j个位置,那么就将棋盘的 ...

  9. PAT (Advanced Level) 1038. Recover the Smallest Number (30)

    注意前导零的消去. #include <iostream> #include <string> #include <sstream> #include <al ...

  10. React学习及实例开发(一)——开始

    本文基于React v16.4.1 初学react,有理解不对的地方,欢迎批评指正^_^ 一.构建一个新项目 1.命令行运行如下命令,构建一个新的react项目 npm install -g crea ...