邮件相关

Posted ckstock

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了邮件相关相关的知识,希望对你有一定的参考价值。

邮件相关一:SO00

SCOT的邮箱配置一般有basis处理

tcode:

SO00 :S O 零零

技术图片

 

点击执行后,还并没有发送过去

进入scot

 技术图片

 

 技术图片

邮件相关二:DEMO 发邮件

FUNCTION ZLM_TEST_MAIL_01.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(MAIL_TITLE) TYPE  SO_OBJ_DES OPTIONAL
*"     REFERENCE(MAIL_TEXT) TYPE  STRING
*"  EXPORTING
*"     VALUE(ERROR_TEXT) TYPE  STRING
*"  TABLES
*"      SEND_LIST STRUCTURE  SOLISTI1 OPTIONAL
*"----------------------------------------------------------------------

  DATA: BEGIN OF GT_SEND OCCURS 0.             "E-mail address
          INCLUDE STRUCTURE SOMLRECI1.
  DATA: END OF GT_SEND.

  DATA: GS_DATA LIKE SODOCCHGI1,              "E-mail setting
        TAB_LINES  TYPE I,
        DOC_SIZE   TYPE I.
  DATA: L_TEXT(50).

  DATA: BEGIN OF GT_ITAB OCCURS 0,            "E-mail text
          TEXT(255),
        END OF GT_ITAB.

  DATA: IT_SITAB TYPE TABLE OF STRING.
  SPLIT MAIL_TEXT AT /n/t INTO TABLE GT_ITAB.

* Email的接收人员
  LOOP AT SEND_LIST.
    GT_SEND-RECEIVER     = SEND_LIST-LINE.
    GT_SEND-REC_TYPE     =  U.
    GT_SEND-EXPRESS      =  X.
    APPEND GT_SEND.
  ENDLOOP.

  CLEAR: GS_DATA.

  GS_DATA-OBJ_NAME     =  URGENT.
  GS_DATA-OBJ_DESCR    =  MAIL_TITLE. "邮件标题
  GS_DATA-OBJ_LANGU    =  1. "中文
*GS_DATA-SENSITIVTY   =  ‘P‘.
  GS_DATA-OBJ_PRIO     =  1.
  GS_DATA-NO_CHANGE    =  X.
  GS_DATA-PRIORITY     =  1.
*   Write Packing List (Main)
  DESCRIBE TABLE GT_ITAB LINES TAB_LINES.
  READ     TABLE GT_ITAB INDEX TAB_LINES.
  GS_DATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( GT_ITAB ).

* SEND THE EMAIL
  CALL FUNCTION SO_NEW_DOCUMENT_SEND_API1
    EXPORTING
      DOCUMENT_DATA              = GS_DATA
      DOCUMENT_TYPE              = RAW
      PUT_IN_OUTBOX              = X
      COMMIT_WORK                = X
    TABLES
      OBJECT_CONTENT             = GT_ITAB
      RECEIVERS                  = GT_SEND
    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 NE 0.
    ERROR_TEXT = 邮件发送失败.
  ElseIF SY-SUBRC = 0.
* 
* 如果不自动送,加上执行邮件立即发送程序代码
  SUBMIT RSCONN01 WITH MODE = INT
                WITH OUTPUT = X "显示发送结果  可以使用空 
                AND RETURN.
  MESSAGE 发送成功 TYPE S.
  ENDIF.

ENDFUNCTION.

邮件相关三:Demo 发邮件的Report(带附件)

* Data Declaration
DATA: docdata    LIKE sodocchgi1,
      objpack    LIKE sopcklsti1 OCCURS  1 WITH HEADER LINE,
      objhead    LIKE solisti1   OCCURS  1 WITH HEADER LINE,
      objtxt     LIKE solisti1   OCCURS 10 WITH HEADER LINE,
      objbin     LIKE solisti1   OCCURS 10 WITH HEADER LINE,
      objhex     LIKE solix      OCCURS 10 WITH HEADER LINE,
      reclist    LIKE somlreci1  OCCURS  1 WITH HEADER LINE.
DATA: BEGIN OF it_obj_descr  OCCURS 0,
        obj_desc LIKE objpack-obj_descr ,
      END OF it_obj_descr.
DATA: listobject LIKE abaplist   OCCURS  1 WITH HEADER LINE.

DATA: tab_lines  TYPE i,
      des_lines  TYPE i,
      doc_size   TYPE i,
      att_type   LIKE soodk-objtp.

PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY,
            p_email TYPE so_recname OBLIGATORY.                        "收件人邮箱

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  DATA: tmp_filename LIKE rlgrap-filename.
  CALL FUNCTION WS_FILENAME_GET
    EXPORTING
*     def_filename     = p_file
      mask             = ,*.XLSX,*.XLSX;,*.TXT,*.TXT;,*.PDF,*.PDF;,*.*,*.*.
      mode             = O
    IMPORTING
      filename         = tmp_filename
    EXCEPTIONS
      inv_winsys       = 01
      no_batch         = 02
      selection_cancel = 03
      selection_error  = 04.
  IF sy-subrc = 0.
    p_file = tmp_filename.
  ENDIF.

START-OF-SELECTION.
  DATA: l_file TYPE string.
  l_file = p_file.
  CALL FUNCTION GUI_UPLOAD
    EXPORTING
      filename                = l_file
      filetype                = BIN                  "获取时采用二进制
*     HAS_FIELD_SEPARATOR     = ‘X‘
    TABLES
      data_tab                = objbin[]
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* NOTE: 以下部分为制作邮件的标题,文本内容等信息

* Create Message Body
*   Title and Description

  docdata-obj_name  = ADAF.                 "文档名称 名称随便取
  docdata-obj_descr = 测试附件传输.         "邮件的主题

  "邮件正文
*   Main Text
  objtxt = Test Document..
  APPEND objtxt.
  objtxt = HAVE A NICE DAY..
  APPEND objtxt.

*   Write Packing List (Main)
  DESCRIBE TABLE objtxt LINES tab_lines.
  READ     TABLE objtxt INDEX tab_lines.
  docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
  CLEAR objpack-transf_bin.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = tab_lines.
  objpack-doc_type   = RAW.
  APPEND objpack.

* 获取附件文件名称
  SPLIT l_file AT \\‘ INTO TABLE it_obj_descr.
  DESCRIBE TABLE it_obj_descr LINES des_lines.
  READ     TABLE it_obj_descr INDEX des_lines.

* 这里开始添加附件相关信息
  att_type = EXT. "这里可能的输入参数可以参考表TSOTD, EXT表示外部文件

  DESCRIBE TABLE objbin LINES tab_lines.
  READ     TABLE objbin INDEX tab_lines.
  objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).                          "附件的大小
  objpack-transf_bin = X.       "表示以二进制传输,由于上传时选择二进制,所以这里必须给值
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.         "附件内容开始行,如果添加多个附件则下一个附件的起始行为 TAB_LINES + 1
  objpack-body_num   = tab_lines. "附件内容总行数
  objpack-doc_type   = att_type.
  objpack-obj_name   = ATTACHMENT.
  objpack-obj_descr  = it_obj_descr-obj_desc.                 "附件的名称
  APPEND objpack.

  "收件人信息----邮箱
* CREATE RECEIVER LIST
  reclist-receiver = p_email.  "接收人邮箱
  reclist-rec_type = U.
  reclist-express      =  X.
*RECLIST-REC_TYPE = A.
  APPEND reclist.


"调用函数发送邮件
* SEND MESSAGE
  CALL FUNCTION SO_NEW_DOCUMENT_ATT_SEND_API1
    EXPORTING
      document_data                    = docdata "邮件标题的属性
      put_in_outbox                    = X
      commit_work                      = X     "USED FROM REL. 6.10
*   IMPORTING
*     SENT_TO_ALL                      =
*     NEW_OBJECT_ID                    =
    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
          .
 
************************************************
* 如果不自动发送,就加上执行邮件立即发送程序
    SUBMIT rsconn01 WITH mode = INT
                  WITH output = X "显示发送结果 ,
                  AND RETURN.

邮件相关四:Sf转PDF 发邮件

*"----------------------------------------------------------------------
*发邮件
  DATA: lv_fm_name TYPE rs38l_fnam.
  DATA: ls_job_out_info         TYPE ssfcrescl,
        ls_document_output_info TYPE ssfcrespd,
        ls_job_out_options      TYPE ssfcresop.
  DATA: lt_otfdata      TYPE ssfcrescl-otfdata,
        lt_lines        TYPE TABLE OF tline,
        lv_bin_filesize TYPE i,
        lv_bin_file     TYPE xstring.
  DATA: lv_length  TYPE so_obj_len,
        lv_subject TYPE so_obj_des,
        lt_text    TYPE soli_tab.
  DATA: lt_item     TYPE TABLE OF zsd_f001_s WITH HEADER LINE,
        ls_item     TYPE  zsd_f001_s,
        lt_item_col TYPE TABLE OF zsd_f001_s,
        ls_item_col TYPE zmms002.
  DATA: lv_num   TYPE int4.
  DATA: ls_lfa1 TYPE lfa1.
  DATA: lv_werks TYPE lfa1-lifnr.
  DATA: lt_log TYPE TABLE OF zmmt002_log,
        ls_log TYPE zmmt002_log,
        lv_msg TYPE string.
*call
  CALL FUNCTION SSF_FUNCTION_MODULE_NAME
    EXPORTING
      formname           = ZSDSF01
    IMPORTING
      fm_name            = lv_fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  IF sy-subrc <> 0.
    CLEAR: lv_msg.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
    ls_log-zmsg = lv_msg && ; && ls_log-zmsg.
  ENDIF.

  DATA(ls_control_parameters) = VALUE ssfctrlop( no_dialog = X preview = ‘‘ getotf = X langu = sy-langu ).
  DATA(ls_output_options) = VALUE ssfcompop( tddest = LP01 tdprinter = CNSAPWIN ).

*process
  lt_item[] = ot_table[].
  READ TABLE lt_item INDEX 1.
  IF sy-subrc = 0.
    SELECT SINGLE *         INTO @DATA(ls_lfa1_tmp) FROM lfa1 WHERE lifnr      EQ @lt_item-lifnr.
  ENDIF.

  SELECT SINGLE smtp_addr INTO @DATA(lv_address)  FROM adr6 WHERE addrnumber EQ @ls_lfa1_tmp-adrnr."邮箱

  CALL FUNCTION lv_fm_name
    EXPORTING
      control_parameters   = ls_control_parameters
      output_options       = ls_output_options
    IMPORTING
      document_output_info = ls_document_output_info
      job_output_info      = ls_job_out_info
      job_output_options   = ls_job_out_options
    TABLES
      i_table              = ot_table
    EXCEPTIONS
      formatting_error     = 1
      internal_error       = 2
      send_error           = 3
      user_canceled        = 4
      OTHERS               = 5.
  IF sy-subrc NE 0.
    CLEAR: lv_msg.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
    ls_log-zmsg = lv_msg && ; && ls_log-zmsg.
  ENDIF.

  lt_otfdata[] = ls_job_out_info-otfdata[].

  CALL FUNCTION CONVERT_OTF
    EXPORTING
      format                = PDF
*     max_linewidth         = 132
*     ARCHIVE_INDEX         = ‘ ‘
*     COPYNUMBER            = 0
*     ASCII_BIDI_VIS2LOG    = ‘ ‘
*     PDF_DELETE_OTFTAB     = ‘ ‘
*     PDF_USERNAME          = ‘ ‘
*     PDF_PREVIEW           = ‘ ‘
*     USE_CASCADING         = ‘ ‘
*     MODIFIED_PARAM_TABLE  =
    IMPORTING
      bin_filesize          = lv_bin_filesize
      bin_file              = lv_bin_file
    TABLES
      otf                   = lt_otfdata[]
      lines                 = lt_lines
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 4
      OTHERS                = 5.
  IF sy-subrc NE 0.
    CLEAR: lv_msg.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
    ls_log-zmsg = lv_msg && ; && ls_log-zmsg.
  ENDIF.

  TRY.
      DATA(lo_send_request) = cl_bcs=>create_persistent( ).
      DATA(lo_document_bcs) = NEW cl_document_bcs( ).
*设置内容
      lt_text = VALUE #( BASE lt_text ( line = 请查收附件订单,请严格按订单交期,数量交货,收到请回复,谢谢! ) ).
      lt_text = VALUE #( BASE lt_text ( line = PS:需附送货单(1份)和采购订单(2份),如果走物流,就将单据放在箱内(注明箱内有单据)或贴在箱外;若为食材类还需提供批次出厂报告; ) ).
      lt_text = VALUE #( BASE lt_text ( line = 如有疑问请联系采购人员: ) ).
*      lv_subject = lv_butxt && ‘PO‘ && im_ekko-ebeln && `_` && sy-datum && sy-uzeit && ‘采购订单明细‘.
      lv_subject =  订货单明细.
      lo_document_bcs = cl_document_bcs=>create_document( i_type    = RAW
                                                          i_length  = lv_length
                                                          i_text    = lt_text
                                                          i_subject = lv_subject
                                                          i_language   = sy-langu
                                                          i_importance = 1
                                                          ).
*添加附件
*      lv_subject = ‘PO‘ && im_ekko-ebeln && `_` && sy-datum && sy-uzeit.
      lv_subject = PO && ot_table-znum && `_` && sy-datum && sy-uzeit.
      lo_document_bcs->add_attachment( EXPORTING i_attachment_type    = PDF
                                                 i_att_content_hex    = cl_document_bcs=>xstring_to_solix( lv_bin_file )"pdf content
                                                 i_attachment_subject = lv_subject
                                                 ).
*设置邮箱并发送
      lo_send_request->set_document( lo_document_bcs ).
      lo_send_request->add_recipient( cl_cam_address_bcs=>create_internet_address( lv_address ) )."recipient
      lo_send_request->set_send_immediately( X ).  "no hesitation

*返回消息
      DATA(lv_result) = lo_send_request->send( i_with_error_screen = X ).
      IF lv_result IS INITIAL."error
        CLEAR: lv_msg.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
        ls_log-zmsg = lv_msg && ; && ls_log-zmsg.
      ENDIF.

    CATCH cx_bcs INTO DATA(lo_bcs_exception).
      lv_msg = lo_bcs_exception->get_text(  ).
  ENDTRY.
*cococo*
*  
*cococo*

*save log
  APPEND VALUE #(
  ebeln       = ot_table-znum
  zrecv_email = lv_address
  ztype       = COND #( WHEN lv_result IS NOT INITIAL THEN S ELSE E )
  zmsg        = COND #( WHEN lv_result IS NOT INITIAL THEN 邮件发送成功 ELSE 邮件发送失败: && ls_log-zmsg )
  ersda       = sy-datum
  ernam       = sy-uname ) TO lt_log.
  MODIFY zmmt002_log FROM TABLE lt_log.

 文中内容来自公众号:SAP干货铺

欢迎关注:博主很帅!!!

以上是关于邮件相关的主要内容,如果未能解决你的问题,请参考以下文章

JAVA发送邮件相关

KnowBe4网络钓鱼测试结果揭示向商业相关邮件转变的趋势

邮件相关的协议

如果我使用 laravel 8,请选择与相关的电子邮件

jenkins发送邮件

Linux 下邮件服务相关介绍