邮件发送功能

      在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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx是一个高性能的Web服务器和反向代理服务器,不支持邮件发送功能。如果您需要在服务器上实现邮件发送功能,可以考虑使用其他邮件服务器软件,如Postfix、Exim、Sendmail等。这些软件都是开源的,并且具有良好的性能和可靠性。在安装和配置这些软件之前,请确保您已经拥有一个域名和一个有效的邮件地址。以下是一些基本步骤,以便在服务器上安装和配置Postfix邮件服务器: 1. 安装Postfix 使用以下命令在服务器上安装Postfix: sudo apt-get install postfix 2. 配置Postfix 打开Postfix配置文件/etc/postfix/main.cf,并进行以下更改: - myhostname = yourdomain.com (将yourdomain.com替换为您的域名) - mydestination = yourdomain.com, localhost.localdomain, localhost (将yourdomain.com替换为您的域名) - inet_interfaces = all(允许Postfix监听所有网络接口) 保存并关闭文件。 3. 重启Postfix 使用以下命令重启Postfix服务: sudo systemctl restart postfix 4. 验证邮件发送功能 使用以下命令向您的邮件地址发送一封测试邮件: echo "This is a test email" | mail -s "Test email" yourname@yourdomain.com 如果您收到了这封邮件,那么您的Postfix邮件服务器已经成功配置并且正在工作。如果您没有收到邮件,请检查您的邮件日志文件,以了解哪里出了问题。 总之,要在服务器上实现邮件发送功能,您需要安装和配置一个邮件服务器软件。Postfix是一个广泛使用的邮件服务器软件,它具有良好的性能和可靠性,并且易于配置。在安装和配置Postfix之前,请确保您已经拥有一个域名和一个有效的邮件地址。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值