Showing posts with label emails. Show all posts
Showing posts with label emails. Show all posts

Sunday, August 6, 2017

Minimal ABAP code to send out an email from ABAP NetWeaver system

Yesterday I blogged about minimal ABAP code needed to display data from internal table in ALV grid. Today I post similar “minimal ABAP code“ thing just this time related to sending an emails from SAP NetWeaver ABAP stack based systems.

I came up with below to example program demonstrating minimal ABAP code for sending email:

Minimal version:
REPORT zmm_email_send_01.

DATA: lt_recepeints TYPE TABLE OF somlreci1,
      ls_recepeints TYPE somlreci1,
      ls_docdata    TYPE sodocchgi1,
      lt_bodydata   TYPE TABLE OF solisti1,
      ls_bodydata   TYPE solisti1.

SELECT * FROM usr02 INTO TABLE @DATA(lt_users).

LOOP AT lt_users INTO DATA(ls_users).
  ls_bodydata-line = ls_users-bname.
  APPEND ls_bodydata TO lt_bodydata.
ENDLOOP.

ls_recepeints-receiver = 'x.x@domain.com'.
ls_recepeints-rec_type = 'U'.
ls_recepeints-express = 'X'.
APPEND ls_recepeints TO lt_recepeints.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    document_type  = 'RAW'
    put_in_outbox  = 'X'
  TABLES
    object_content = lt_bodydata
    receivers      = lt_recepeints.
COMMIT WORK.

Regular version (with subject etc):
REPORT zmm_email_send_01.

DATA: lt_recepeints TYPE TABLE OF somlreci1,
      ls_recepeints TYPE somlreci1,
      ls_docdata    TYPE sodocchgi1,
      lt_bodydata   TYPE TABLE OF solisti1,
      ls_bodydata   TYPE solisti1.

SELECT * FROM usr02 INTO TABLE @DATA(lt_users).

LOOP AT lt_users INTO DATA(ls_users).
  ls_bodydata-line = ls_users-bname.
  APPEND ls_bodydata TO lt_bodydata.
ENDLOOP.

ls_docdata-obj_name   = 'Email'.
ls_docdata-obj_descr  = 'Email from' && sy-sysid. “subject

ls_recepeints-receiver = 'x.x@domain.com'.
ls_recepeints-rec_type = 'U'.
ls_recepeints-express = 'X'.
APPEND ls_recepeints TO lt_recepeints.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
  EXPORTING
    document_data  = ls_docdata
    document_type  = 'RAW'
    put_in_outbox  = 'X'
  TABLES
    object_content = lt_bodydata
    receivers      = lt_recepeints.
COMMIT WORK.


Source code of the example can be found here: gsofty12/MINIMAL_EMAIL_SENT 

Tuesday, September 15, 2015

Maximum attachment size limit for an email sent from SAP

Sometimes it may happen that outgoing emails from SAP instance are not going through. They are stuck in queue and have red status saying following error:

Cannot process message; maximum size exceeded
Message No. XS850

This clearly indicates that email is too big to get it sent over. Case might be that it has an attachment which size is causing this. It is worth to investigate actual size of the email and the attachment. However one may end up having email already compressed and facing this issue. So further compressing of the email attachment makes no sense. Therefore chance is to check what actually the limit of the email size is. Parameters related to the size of email and its attachment are customizable. The customizing table is called SXPARAMS - SAPconnect: Parameter Table. Its maintenance is available t-code SOST -> Utilities -> General Parameters or via SM30 -> SXPARAMS.

Few parameters related to size of email and its components:

Parameter                                        Parameter value

MAXLEN_BODYPART_SMTP             0 ... 999999999999   size for a document
MAXLEN_BODYPART_ALI_SMTP       0 ... 999999999999   lists of the type ALI
MAXLEN_BODYPART_OTF_SMTP      0 ... 999999999999   SAPscript documents

MAXLEN_MIME_MESSAGE_SMTP     0 ... 999999999999   MIME MIME attachments



Update 02-08-2016
There is one more parameter of SCOT. It is related to size of email.
MAXLEN_BODYPART_EXT_SMTP      size for an attachment, default value: 10485760