Application Development 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: 

Regarding Mail Send

Former Member
0 Kudos

Hi

I want to send an email with out attachments through internet from SAP using ABAP code.

Plz give me the code and any configurations and settings (steps) asap

Thanks in Advance

venkat

3 REPLIES 3

Former Member
0 Kudos

Hi,

Do the configurations in SCOT transaction first.

see the sample code:

----


  • INCLUDE ZINCUSMAIL *

----


include <symbol>.

data : i_doc_data like sodocchgi1.

data : begin of i_pack_list occurs 0.

include structure sopcklsti1.

data : end of i_pack_list.

data : begin of i_receivers occurs 0.

include structure somlreci1.

data : end of i_receivers.

data : begin of i_contents occurs 0.

include structure solisti1.

data : end of i_contents.

data : begin of i_header occurs 0.

include structure solisti1.

data : end of i_header.

data : begin of i_att occurs 0.

include structure solisti1.

data : end of i_att.

  • Internal Table for Internet address.

data: begin of it_inad occurs 0,

kunnr like kna1-kunnr, " Customer Code

name1 like kna1-name1, " Customer Name

ssobl like knkk-ssobl, " Security Deposit

klimk like knkk-klimk, " Credit Limit

opbal like bsid-wrbtr, " Opening Balance

clbal like bsid-wrbtr, " Closing Balance

smtp like adr6-smtp_addr, " Internet mail (SMTP) address

end of it_inad.

data : pdf_line(134),

asdf like pdf_line occurs 0 with header line.

data : pdf_table like tline occurs 0 with header line,

pdf_fsize type i.

data : stuff(65000),

len type i,

pos type i,

tab_lines like sy-tabix.

data: spoolid type tsp01-rqident,

spdel type tsp01sys.

data: v_gjahrt like bsid-gjahr,

fmondest(10),

tmondest(10),

kunnr1 like kna1-kunnr,

gjah(4),

fmon(10).

&----


*& Form hide_write

&----


form hide_write.

new-page print on

line-size 160

  • line-count 58

no-title

no-heading

destination 'LOCL'

immediately ' '

new list identification 'X'

no dialog.

set blank lines on.

endform. " hide_write

&----


*& Form end_write

&----


form end_write using kunnr1.

set blank lines off.

new-page print off.

***Using Spoolid we are getting PDF formated file

spoolid = spdel-rqident = sy-spono.

spdel-sys = sy-sysid.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = spoolid

no_dialog = 'X'

importing

pdf_bytecount = pdf_fsize

tables

pdf = pdf_table

exceptions

others = 0.

***Delleting Spool request

call function 'RSPO_IDELETE_SPOOLREQ'

exporting

spoolreq = spdel

exceptions

others = 2.

***Converting PDF table line size 134 into standard list size 255

loop at pdf_table into pdf_line.

if pos = 34170.

perform attach.

endif.

stuff+pos(134) = pdf_line.

add 134 to pos.

endloop.

if not ( stuff is initial ).

perform attach.

endif.

clear pdf_line.

clear pdf_table[].

describe table i_att lines tab_lines.

i_pack_list-transf_bin = 'X'.

i_pack_list-head_start = '1'.

i_pack_list-head_num = '1'.

i_pack_list-body_start = '1'.

i_pack_list-body_num = tab_lines.

i_pack_list-doc_type = 'PDF'.

i_pack_list-obj_name = 'LedgerMail'.

concatenate fmon '-' gjah into i_pack_list-obj_descr.

*i_pack_list-obj_descr = '2092-Oct03'.

i_pack_list-obj_langu = 'E'.

i_pack_list-doc_size = tab_lines * 255.

append i_pack_list.

***Data for receivers list

loop at it_inad where kunnr eq kunnr1.

i_receivers-receiver = it_inad-smtp.

i_receivers-rec_type = 'U'.

i_receivers-rec_date = sy-datum.

i_receivers-express = 'X'.

i_receivers-com_type = 'INT'.

i_receivers-notif_del = 'X'.

append i_receivers.

endloop.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = i_doc_data

  • PUT_IN_OUTBOX = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

packing_list = i_pack_list

object_header = i_header

contents_bin = i_att

contents_txt = i_contents

receivers = i_receivers

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

.

refresh i_att. clear i_att.

refresh i_receivers. clear i_receivers.

delete i_pack_list where doc_type = 'PDF'.

*refresh i_header.

*refresh i_contents.

*clear i_doc_data.

endform. " end_write

&----


*& Form doc_data

&----


form doc_data using fmondest v_gjahrt.

gjah = v_gjahrt.

fmon = fmondest.

***Data for Document Data

i_doc_data-obj_name = 'LedgerMail'.

concatenate 'Customer Ledger for : ' fmondest gjah

into i_doc_data-obj_descr separated by space.

i_doc_data-obj_langu = 'E'.

i_doc_data-obj_prio = '1'.

i_doc_data-no_change = 'X'.

i_doc_data-doc_size = '5101'.

***Data for Packing list

i_pack_list-head_start = '1'.

i_pack_list-head_num = '1'.

i_pack_list-body_start = '1'.

i_pack_list-body_num = '20'.

i_pack_list-doc_type = 'RAW'.

i_pack_list-obj_langu = 'E'.

append i_pack_list.

***Data for Header

i_header-line = 'Header'. append i_header.

***Data for contents

i_contents-line = 'Dear Customer,'. append i_contents.

i_contents-line = ' '. append i_contents.

concatenate 'Please find your enclosed Ledger for the month of : '

fmondest gjah into i_contents-line separated by space.

append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'This is a computer generated document and does not

require a signature.'. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'Note : If you do not have Acrobat Reader please click

on the below link.'. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'http://www.adobe.com/products/acrobat/readstep2.html'

. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

endform. " doc_data

&----


*& Form attach

&----


form attach.

clear pos.

len = strlen( stuff ).

while len > 0.

subtract 255 from len.

i_att = stuff+pos(255).

append i_att.

add 255 to pos.

endwhile.

clear pos.

clear stuff.

endform. " attach

check this for ur info

to send mail

http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html

reward if useful

regards,

Anji

Former Member
0 Kudos

Hi,

Use this Fm

SO_NEW_DOCUMENT_ATT_SEND_API1

Former Member
0 Kudos

Hi,

Here is the Sample Program

*&---------------------------------------------------------------------*
*& Report  ZSENDEMAIL                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT                    *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  zsendemail                    .

PARAMETERS: psubject(40) type c default  'Hello',
            p_email(40)   type c default 'test@sapdev.co.uk' .

data:   it_packing_list like sopcklsti1 occurs 0 with header line,
        it_contents like solisti1 occurs 0 with header line,
        it_receivers like somlreci1 occurs 0 with header line,
        it_attachment like solisti1 occurs 0 with header line,
        gd_cnt type i,
        gd_sent_all(1) type c,
        gd_doc_data like sodocchgi1,
        gd_error type sy-subrc.

data:   it_message type standard table of SOLISTI1 initial size 0
                with header line.

***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.


*&---------------------------------------------------------------------*
*&      Form  POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
*       Adds text to email text table
*----------------------------------------------------------------------*
form populate_message_table.
  Append 'Email line 1' to it_message.
  Append 'Email line 2' to it_message.
  Append 'Email line 3' to it_message.
  Append 'Email line 4' to it_message.
endform.                    " POPULATE_MESSAGE_TABLE


*&---------------------------------------------------------------------*
*&      Form  SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
*       Send email message
*----------------------------------------------------------------------*
form send_email_message.
* Fill the document data.
  gd_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-obj_name  = 'SAPRPT'.
  gd_doc_data-obj_descr = psubject.
  gd_doc_data-sensitivty = 'F'.

* Describe the body of the message
  clear it_packing_list.
  refresh it_packing_list.
  it_packing_list-transf_bin = space.
  it_packing_list-head_start = 1.
  it_packing_list-head_num = 0.
  it_packing_list-body_start = 1.
  describe table it_message lines it_packing_list-body_num.
  it_packing_list-doc_type = 'RAW'.
  append it_packing_list.

* Add the recipients email address
  clear it_receivers.
  refresh it_receivers.
  it_receivers-receiver = p_email.
  it_receivers-rec_type = 'U'.
  it_receivers-com_type = 'INT'.
  it_receivers-notif_del = 'X'.
  it_receivers-notif_ndel = 'X'.
  append it_receivers.

* Call the FM to post the message to SAPMAIL
  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       exporting
            document_data              = gd_doc_data
            put_in_outbox              = 'X'
       importing
            sent_to_all                = gd_sent_all
       tables
            packing_list               = it_packing_list
            contents_txt               = it_message
            receivers                  = it_receivers
       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.

* Store function module return code
  gd_error = sy-subrc.

* Get it_receivers return code
  loop at it_receivers.
  endloop.
endform.                    " SEND_EMAIL_MESSAGE


*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
form initiate_mail_execute_program.
  wait up to 2 seconds.
  if gd_error eq 0.
      submit rsconn01 with mode = 'INT'
                    with output = 'X'
                    and return.
  endif.
endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM

Regards

Sudheer