邮件相关

邮件相关一: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干货铺

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

原文地址:https://www.cnblogs.com/ckstock/p/11580174.html

时间: 2024-11-02 05:40:24

邮件相关的相关文章

邮件相关的协议

背景 配置邮件客户端的时候,有几个协议可以选,分别了解下这些协议. POP3(Post Office Protocol 3) 即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的电子协议.主要功能是用在传送电子邮件,当我 们寄信给另外一个人时,对方当时多半不会在线上,所以邮件服务器必须为收信者保存这封信,直到收信者来检查这封信件.当收信人收信的时候,必须通过POP 通讯协定,才能取得邮件. IMAP (Internet Message Access P

JavaMail(JAVA邮件服务) API详解

一.JavaMail API简介JavaMail API是读取.撰写.发送电子信息的可选包.我们可用它来建立如Eudora.Foxmail.MS Outlook Express一般的邮件用户代理程序(Mail User Agent,简称MUA).而不是像sendmail或者其它的邮件传输代理(Mail Transfer Agent,简称MTA)程序那样可以传送.递送.转发邮件.从另外一个角度来看,我们这些电子邮件用户日常用MUA程序来读写邮件,而MUA依赖着MTA处理邮件的递送.在清楚了到MUA

(转)linux口令相关文件(/etc/passwd和/etc/shadow)

在linux中,口令文件在/etc/passwd中,早期的这个文件直接存放加密后的密码,前两位是"盐"值,是一个随机数,后面跟的是加密的密码.为了安全,现在的linux都提供了 /etc/shadow这个影子文件,密码放在这个文件里面,并且是只有root可读的. 下面来分析一下/etc/passwd文件,他的每个条目有7个域,分别是名字:密码:用户id:组id:用户信息:主目录:shell 例如:test:x:509:510::/home/test:/bin/bash 在利用了shad

JavaMail(二):利用JavaMail发送复杂邮件

上一篇文章我们学习了利用JavaMail发送简单邮件,这篇文章我们利用JavaMail发送稍微复杂一点的邮件(包含文本.图片.附件).这里只贴出核心代码,其余代码可参考JavaMail(一):利用JavaMail发送简单邮件 封装发送邮件代码 /** * 封装发送邮件代码 * @author fly * @时间 2017-05-09 * */ public class Email { /** * 创建并发送一封包含文本.图片.附件的复杂邮件 * @throws Exception */ publ

Apache James使用的方法及相关心得(转)

经过一番的辛苦努力,终于把James 配置搞定啦,好记性不如烂笔头啊,赶紧记下我的成功经过,以备以后查阅! 首先要做的就是配置域名的MX 记录啦: 先添加一条A记录: mail.abc.com 指向 你的服务器IP! 然后添加域名的MX 记录,指向mail.abc.com A 记录( 即域名MX 记录的值为mail.abc.com). OK ,域名的配置就完成啦! 接下来安装配置James : James 不需要编译安装,解压即可以使用,把james 下载来后,必须先启动一下! 进入James 

关于工作邮件要点总结

好多工作中的同事在写邮件方面不注意,做个简单的总结. 1.主题 工作邮件必须要有主题,方便他人阅读和处理与邮件有关的内容. 2.主送人.抄送人 朱送人:就是与邮件内容相关的主要责任人. 抄送人:就是与邮件相关的非直接责任人. 注意点就是不要写的邮件很随便,朱送人,抄送人乱填一通,很不专业也给同事造成工作的不便. 3.邮件内容 格式清晰,该加粗和标记的就加上.该重点标注就标注. 文字内容表述明确,什么问题需要谁做做什么均要描述清楚.不要邮件胡乱写,看一遍都不知道要干嘛,给他人造成理解的不便.

用JAMES实现自己的邮件服务器

简介 James 是一个企业级的邮件服务器,它完全实现了smtp 和 pops 以及nntp 协议.同时,james服务器又是一个邮件应用程序平台.James的核心是Mailet API,而james 服务齐是一个mailet的容器.它可以让你非常容易的实现出很强大的邮件应用程序.James开源项目被广泛的应用于与邮件有关的项目中.你可以通过它来搭建自己的邮件服务器.我们可以利用Mailet API,编程接口来实现自己所需的业务.James集成了Avalon 应用程序框架以及Phoenix Av

Java邮件服务学习之一:邮件服务概述

java可以提供邮件服务:一般理解的邮件服务就是可以发送和接收邮件的客户端,但是使用java编写邮件服务端: 一.邮件客户端: web应用根据依赖的API,常用的有两种: 第一种:J2EE中提供的java mail API(javax.mail.*) Javamail API是一个用于阅读.编写和发送电子消息的可选包(标准扩展),可以用来建立基于标准的电子邮件客户机,它支持各种因特网邮件协议,包括:SMTP.POP.IMAP.MIME.NNTP.S/MIME及其它协议. 第二种:spring 对

linux登录档(日志)相关简介

1.登录文件中记载了许多重要的信息,因此登录文件的权限通常仅为root能够阅读而已. 1)/var/log/cron:例行性工作排程的日志 2)/var/log/dmesg:记录系统在开机的时候核心侦测过程所产生的各项信息. 3)var/log/lastlog:可以记录系统上面的所有账号最近一次登入系统的相关信息,lastlog指令就是利用该文件来显示的. 4)/var/log/maillog或/var/log/mail/*:记录邮件来往信息,其实主要是记录sendmail(STMP 协议提供者