Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Is there a Function module to send email ?

Former Member
0 Likes
829

Hi all,

is there a FM that can be used to send E mails?

i found so_document_send_api on the SDN, but it doesnt exist.

any pointers?

Thanks,

Sonal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
711

Hi sonal,

you can use

<b>SO_NEW_DOCUMENT_ATT_SEND_API1</b>

this is to send with attachment.

to send without attachment

<b>SO_NEW_DOCUMENT_SEND_API1</b>

regards,

pankaj singh

      • dont forget to give points

Message was edited by:

Pankaj Singh

5 REPLIES 5
Read only

Former Member
0 Likes
712

Hi sonal,

you can use

<b>SO_NEW_DOCUMENT_ATT_SEND_API1</b>

this is to send with attachment.

to send without attachment

<b>SO_NEW_DOCUMENT_SEND_API1</b>

regards,

pankaj singh

      • dont forget to give points

Message was edited by:

Pankaj Singh

Read only

Former Member
0 Likes
711

Hi Sonal,

http://www.sap-img.com/fu016.htm

SO_DOCUMENT_SEND_API1

SO_NEW_DOCUMENT_ATT_SEND_API1

How to send a report to an external mail-id?

REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING LINE-SIZE 200.

DATA : BEGIN OF ITAB OCCURS 0,

PERNR LIKE PA0001-PERNR,

ENAME LIKE PA0001-ENAME,

END OF ITAB.

DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,

receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,

listobject LIKE abaplist OCCURS 10,

compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,

w_object_hd_change LIKE sood1,

compressed_size LIKE sy-index.

START-OF-SELECTION.

SELECT PERNR ENAME

INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM PA0001

WHERE PERNR < 50.

LOOP AT ITAB.

WRITE :/02 SY-VLINE , ITAB-PERNR, 15 SY-VLINE , ITAB-ENAME, 50

SY-VLINE.

ENDLOOP.

  • Receivers

receiver_list-recextnam = 'EXTERNAL-MAIL-ID@YAHOO.COM'. "-->

  • EMAIL ADDRESS

RECEIVER_list-RECESC = 'E'. "<-

RECEIVER_list-SNDART = 'INT'."<-

RECEIVER_list-SNDPRI = '1'."<-

APPEND receiver_list.

  • General data

w_object_hd_change-objla = sy-langu.

w_object_hd_change-objnam = 'Object name'.

w_object_hd_change-objsns = 'P'.

  • Mail subject

w_object_hd_change-objdes = 'Message subject'.

  • Mail body

APPEND 'Message content' TO message_content.

  • Attachment

CALL FUNCTION 'SAVE_LIST'

EXPORTING

list_index = '0'

TABLES

listobject = listobject.

CALL FUNCTION 'TABLE_COMPRESS'

IMPORTING

compressed_size = compressed_size

TABLES

in = listobject

out = compressed_attachment.

DESCRIBE TABLE compressed_attachment.

CLEAR packing_list.

packing_list-transf_bin = 'X'.

packing_list-head_start = 0.

packing_list-head_num = 0.

packing_list-body_start = 1.

packing_list-body_num = sy-tfill.

packing_list-objtp = 'ALI'.

packing_list-objnam = 'Object name'.

packing_list-objdes = 'Attachment description'.

packing_list-objlen = compressed_size.

APPEND packing_list.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = w_object_hd_change

object_type = 'RAW'

owner = sy-uname

TABLES

objcont = message_content

receivers = receiver_list

packing_list = packing_list

att_cont = compressed_attachment.

http://www.sap-img.com/abap/sending-mail-with-attachment-report-in-background.htm

Here is the sample code:

z_send_email_fax_global

FUNCTION-POOL z_gfaian_mail_fax. "MESSAGE-ID ..

*----


  • WORK TABLE AREAS

*----


TABLES: tsp01.

*----


  • INTERNAL TABLES

*----


DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,

lt_note_text LIKE STANDARD TABLE OF soli WITH HEADER LINE,

lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.

DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,

lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.

DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.

TYPES: BEGIN OF y_files,

file(60) TYPE c,

END OF y_files.

DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.

DATA: l_objcont LIKE soli OCCURS 0 WITH HEADER LINE.

DATA: l_objhead LIKE soli OCCURS 0 WITH HEADER LINE.

*----


  • STRUCTURES

*----


DATA: folder_id LIKE soodk,

object_id LIKE soodk,

link_folder_id LIKE soodk,

g_document LIKE sood4,

  • g_header_data LIKE sood2,

g_folmem_data LIKE sofm2,

g_header_data LIKE sood2,

g_receive_data LIKE soos6,

g_ref_document LIKE sood4,

g_new_parent LIKE soodk,

l_folder_id LIKE sofdk,

v_email(50).

DATA: hd_dat like sood1.

*----


  • VARIABLES

*----


DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

DATA: numbytes TYPE i,

arc_idx LIKE toa_dara,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

DATA: outbox_flag LIKE sonv-flag VALUE 'X',

store_flag LIKE sonv-flag,

delete_flag LIKE sonv-flag,

owner LIKE soud-usrnam,

on LIKE sonv-flag VALUE 'X',

sent_to_all LIKE sonv-flag,

g_authority LIKE sofa-usracc,

w_objdes LIKE sood4-objdes.

DATA: c_file LIKE rlgrap-filename,

n_spool(6) TYPE n.

DATA: cancel.

DATA: desired_type LIKE sood-objtp,

real_type LIKE sood-objtp,

attach_type LIKE sood-objtp,

otf LIKE sood-objtp VALUE 'OTF', " SAPscript Ausgabeformat

ali LIKE sood-objtp VALUE 'ALI'. " ABAP lists

*----


  • CONSTANTS

*----


CONSTANTS: ou_fol LIKE sofh-folrg VALUE 'O',

c_objtp LIKE g_document-objtp VALUE 'RAW',

c_file_ext LIKE g_document-file_ext VALUE 'TXT'.

=================================================================================

z_send_email_fax2

FUNCTION z_faian_mail_fax2.

*"----


""Interface local:

*" IMPORTING

*" REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT

*" REFERENCE(FAX_MAIL_NUMBER) TYPE SO_NAME

*" REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES

*" REFERENCE(OBJECT_TYPE) TYPE SO_ESCAPE

*" TABLES

*" LT_BODY_EMAIL STRUCTURE SOLI

*" EXCEPTIONS

*" ERR_NO_ABAP_SPOOLJOB

*"----


  • Fist part: Verify if the spool really exists

SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.

IF sy-subrc NE 0.

RAISE err_no_abap_spooljob. "doesn't exist

ELSE.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4

OTHERS = 5.

IF objtype(3) = 'OTF'.

desired_type = otf.

ELSE.

desired_type = ali.

ENDIF.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = src_spoolid

desired_type = desired_type

IMPORTING

real_type = real_type

TABLES

buffer = l_objcont

EXCEPTIONS

no_such_job = 14

type_no_match = 94

job_contains_no_data = 54

no_permission = 21

can_not_access = 21

read_error = 54.

IF sy-subrc EQ 0.

attach_type = real_type.

ENDIF.

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

owner = sy-uname

region = ou_fol

IMPORTING

folder_id = l_folder_id

EXCEPTIONS

OTHERS = 5.

  • fill out informations about the header of the email

CLEAR: g_document.

g_document-foltp = l_folder_id-foltp.

g_document-folyr = l_folder_id-folyr.

g_document-folno = l_folder_id-folno.

g_document-objtp = c_objtp.

g_document-objdes = header_mail.

g_document-file_ext = c_file_ext.

g_header_data-objdes = header_mail.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'

EXPORTING

method = 'SAVE'

office_user = sy-uname

IMPORTING

authority = g_authority

TABLES

objcont = lt_body_email

attachments = lt_attachments

CHANGING

document = g_document

header_data = g_header_data

EXCEPTIONS

OTHERS = 1.

folder_id-objtp = l_folder_id-foltp.

folder_id-objyr = l_folder_id-folyr.

folder_id-objno = l_folder_id-folno.

object_id-objtp = c_objtp.

object_id-objyr = g_document-objyr.

object_id-objno = g_document-objno.

link_folder_id-objtp = l_folder_id-foltp.

link_folder_id-objyr = l_folder_id-folyr.

link_folder_id-objno = l_folder_id-folno.

REFRESH lt_rec_tab.

  • CLEAR lt_rec_tab.

  • lt_rec_tab-sel = 'X'.

  • lt_rec_tab-recesc = object_type. "This field for FAX/MAIL

  • lt_rec_tab-recnam = 'U-'.

  • lt_rec_tab-deliver = 'X'.

  • lt_rec_tab-not_deli = 'X'.

  • lt_rec_tab-read = 'X'.

  • lt_rec_tab-mailstatus = 'E'.

  • lt_rec_tab-adr_name = fax_mail_number.

  • lt_rec_tab-sortfield = fax_mail_number.

  • lt_rec_tab-recextnam = fax_mail_number.

  • lt_rec_tab-sortclass = '5'.

  • APPEND lt_rec_tab.

lt_rec_tab-recextnam = fax_mail_number.

lt_rec_tab-recesc = object_type.

lt_rec_tab-sndart = 'INT'.

lt_rec_tab-sndpri = 1.

APPEND lt_rec_tab.

lt_files-file = c_file.

APPEND lt_files.

  • begin of insertion by faianf01

hd_dat-objdes = header_mail.

CALL FUNCTION 'SO_ATTACHMENT_INSERT'

EXPORTING

object_id = object_id

attach_type = attach_type

object_hd_change = hd_dat

owner = sy-uname

TABLES

objcont = l_objcont

objhead = l_objhead

EXCEPTIONS

active_user_not_exist = 35

communication_failure = 71

object_type_not_exist = 17

operation_no_authorization = 21

owner_not_exist = 22

parameter_error = 23

substitute_not_active = 31

substitute_not_defined = 32

system_failure = 72

x_error = 1000.

IF sy-subrc > 0.

ENDIF.

  • end of insertion by faianf01

  • send email from SAPOFFICE

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

folder_id = folder_id

object_id = object_id

outbox_flag = outbox_flag

link_folder_id = link_folder_id

owner = sy-uname

  • check_send_authority = 'X'

TABLES

receivers = lt_rec_tab

  • note_text = lt_note_text

EXCEPTIONS

active_user_not_exist = 35

communication_failure = 71

component_not_available = 1

folder_no_authorization = 5

folder_not_exist = 6

forwarder_not_exist = 8

object_no_authorization = 13

object_not_exist = 14

object_not_sent = 15

operation_no_authorization = 21

owner_not_exist = 22

parameter_error = 23

substitute_not_active = 31

substitute_not_defined = 32

system_failure = 72

too_much_receivers = 73

user_not_exist = 35.

ENDIF.

ENDFUNCTION.

=================================================================================

z_send_email_fax

FUNCTION ZCBFS_SEND_MAIL.

*"----


""Interface local:

*" IMPORTING

*" REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT

*" REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES

*" TABLES

*" LIST_FAX_MAIL_NUMBER STRUCTURE SOLI

*" EXCEPTIONS

*" ERR_NO_ABAP_SPOOLJOB

*"----


DATA: vg_achou(1) TYPE n.

  • Fist part: Verify if the spool really exists

vg_achou = 1.

DO 60 TIMES.

SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.

IF sy-subrc IS INITIAL.

CLEAR vg_achou.

EXIT.

ELSE.

WAIT UP TO 1 SECONDS.

ENDIF.

ENDDO.

IF vg_achou = 1.

RAISE err_no_abap_spooljob. "doesn't exist

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4

OTHERS = 5.

IF objtype(3) = 'OTF'.

desired_type = otf.

ELSE.

desired_type = ali.

ENDIF.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = src_spoolid

desired_type = desired_type

IMPORTING

real_type = real_type

TABLES

buffer = l_objcont

EXCEPTIONS

no_such_job = 14

type_no_match = 94

job_contains_no_data = 54

no_permission = 21

can_not_access = 21

read_error = 54.

IF sy-subrc EQ 0.

attach_type = real_type.

ENDIF.

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

owner = sy-uname

region = ou_fol

IMPORTING

folder_id = l_folder_id

EXCEPTIONS

OTHERS = 5.

  • fill out informations about the header of the email

CLEAR: g_document.

g_document-foltp = l_folder_id-foltp.

g_document-folyr = l_folder_id-folyr.

g_document-folno = l_folder_id-folno.

g_document-objtp = c_objtp.

g_document-objdes = header_mail.

g_document-file_ext = c_file_ext.

g_header_data-objdes = header_mail.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'

EXPORTING

method = 'SAVE'

office_user = sy-uname

IMPORTING

authority = g_authority

TABLES

attachments = lt_attachments

CHANGING

document = g_document

header_data = g_header_data

EXCEPTIONS

OTHERS = 1.

folder_id-objtp = l_folder_id-foltp.

folder_id-objyr = l_folder_id-folyr.

folder_id-objno = l_folder_id-folno.

object_id-objtp = c_objtp.

object_id-objyr = g_document-objyr.

object_id-objno = g_document-objno.

link_folder_id-objtp = l_folder_id-foltp.

link_folder_id-objyr = l_folder_id-folyr.

link_folder_id-objno = l_folder_id-folno.

REFRESH lt_rec_tab.

LOOP AT LIST_FAX_MAIL_NUMBER.

lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.

lt_rec_tab-recesc = 'U'.

lt_rec_tab-sndart = 'INT'.

lt_rec_tab-sndpri = 1.

APPEND lt_rec_tab.

ENDLOOP.

lt_files-file = c_file.

APPEND lt_files.

hd_dat-objdes = header_mail.

CALL FUNCTION 'SO_ATTACHMENT_INSERT'

EXPORTING

object_id = object_id

attach_type = attach_type

object_hd_change = hd_dat

owner = sy-uname

TABLES

objcont = l_objcont

objhead = l_objhead

EXCEPTIONS

active_user_not_exist = 35

communication_failure = 71

object_type_not_exist = 17

operation_no_authorization = 21

owner_not_exist = 22

parameter_error = 23

substitute_not_active = 31

substitute_not_defined = 32

system_failure = 72

x_error = 1000.

IF sy-subrc > 0.

ENDIF.

  • send email from SAPOFFICE

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

folder_id = folder_id

object_id = object_id

outbox_flag = outbox_flag

link_folder_id = link_folder_id

owner = sy-uname

TABLES

receivers = lt_rec_tab

note_text = lt_note_text

EXCEPTIONS

active_user_not_exist = 35

communication_failure = 71

component_not_available = 1

folder_no_authorization = 5

folder_not_exist = 6

forwarder_not_exist = 8

object_no_authorization = 13

object_not_exist = 14

object_not_sent = 15

operation_no_authorization = 21

owner_not_exist = 22

parameter_error = 23

substitute_not_active = 31

substitute_not_defined = 32

system_failure = 72

too_much_receivers = 73

user_not_exist = 35.

ENDFUNCTION.

Regards,

Srilatha.

Read only

0 Likes
711

Hi sri,

postin code you may use the Code button above, TNX.

Regards,

Clemens

Read only

Clemenss
Active Contributor
0 Likes
711

Hi sonal sharda,

the function 'SO_NEW_DOCUMENT_SEND_API1' is more or less not state of the art and difficult to handle. Meanwhile, SAP introduced the Business Communcation Services, a much more flexible and future-oriented OO attempt to Mail.

See this code snippet for a mail with a subject longer than the old-fashioned limit of 50 characters:


*     -------- create persistent send request ------------------------
      send_request = cl_bcs=>create_persistent( ).
 
*     -------- create and set document with attachment ---------------
*     create document from internal table with text
      APPEND 'Hello world!' TO text.
      document = cl_document_bcs=>create_document(
                      i_type    = 'RAW'
                      i_text    = text
                      i_length  = '12'
                      i_subject = '' ).
 
*     add attachment to document
*     BCS expects document content here e.g. from document upload
*     binary_content = ...
      CALL METHOD document->add_attachment
        EXPORTING  i_attachment_type = 'DOC'
                   i_attachment_subject = 'My attachment'
                   i_att_content_hex    = binary_content.
 
*subject line more than 50 chars
      DATA: T_SUB TYPE STRING.
      t_sub = 'This is testing to send email where subject line more than 50''.
      call method send_request->set_message_subject( t_sub ).

Using the new Class CL_BCS is quite easy. SAP provides sample programs

BCS_EXAMPLE_1

BCS_EXAMPLE_2

BCS_EXAMPLE_3

BCS_EXAMPLE_4

BCS_EXAMPLE_5

BCS_TEST01

BCS_TEST04

BCS_TEST05

BCS_TEST06

BCS_TEST09

I checked BCS_EXAMPLE_1. This program provides what you need in very simple matter.

Good luck!

Regards,

Clemens

Read only

former_member572947
Discoverer
0 Likes
711

Thank you very much. this information was helpful to us.