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: 

Email to external address

sastry_gunturi
Active Participant
0 Kudos

I am using the below code to send emails to external address and getting error... let me if there's something wrong in the code..........

DATA: gs_obj_hd_change TYPE sood1.
DATA: gt_rec_tab TYPE STANDARD TABLE OF soos1.
DATA: gt_objcont TYPE STANDARD TABLE OF soli.

DATA: WA_REC_TAB TYPE SOOS1,
      WA_OBJCONT TYPE SOLI.

*   Subject
gs_obj_hd_change-objdes = 'Test Email from SAP'.

*   Recipient
WA_rec_tab-recextnam = 'Text-001'. " contains email.
WA_rec_tab-recesc    = 'U'.
APPEND WA_rec_tab TO gt_rec_tab.

* content.

wa_objcont-LINE = 'line1'.
append wa_objcont to gt_objcont.

CALL FUNCTION 'SO_OBJECT_SEND'
  EXPORTING
    object_hd_change           = gs_obj_hd_change " Subject
    object_type                = 'RAW'
    owner                      = sy-uname
  TABLES
    objcont                    = gt_objcont " Content
    receivers                  = gt_rec_tab " Recipient
  EXCEPTIONS
    active_user_not_exist      = 1
    communication_failure      = 2
    component_not_available    = 3
    folder_not_exist           = 4
    folder_no_authorization    = 5
    forwarder_not_exist        = 6
    note_not_exist             = 7
    object_not_exist           = 8
    object_not_sent            = 9
    object_no_authorization    = 10
    object_type_not_exist      = 11
    operation_no_authorization = 12
    owner_not_exist            = 13
    parameter_error            = 14
    substitute_not_active      = 15
    substitute_not_defined     = 16
    system_failure             = 17
    too_much_receivers         = 18
    user_not_exist             = 19
    originator_not_exist       = 20
    x_error                    = 21
    OTHERS                     = 22.
IF sy-subrc EQ  0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

5 REPLIES 5

Former Member
0 Kudos

Hi,

*   Recipient
WA_rec_tab-recextnam = Text-001. " contains email. " Remove the single quotes
WA_rec_tab-recesc    = 'U'.
APPEND WA_rec_tab TO gt_rec_tab.

you need to specify size of the mail, please search in SDn or wiki u can find the code.

it will be easy if u use below function modules.

SO_NEW_DOCUMENT_ATT_SEND_API1

SO_NEW_DOCUMENT_SEND_API1

Edited by: Avinash Kodarapu on Jun 4, 2009 12:30 AM

Former Member
0 Kudos

If you really hope to get some help in this, you're going to have to tell us more than you're getting an error. What kind of error - a message, a dump, a syntax error?

Rob

venkat_o
Active Contributor
0 Kudos

Hi Karthik,

Here is the sample program which has explanation in each step. Have a look and change accordingly.

<pre>

REPORT zvenkat_mail_simple.

----


  • Mail related declarations

----


"Variables

DATA :

g_sent_to_all TYPE sonv-flag,

g_tab_lines TYPE i.

"Types

TYPES:

t_document_data TYPE sodocchgi1,

t_packing_list TYPE sopcklsti1,

t_attachment TYPE solisti1,

t_body_msg TYPE solisti1,

t_receivers TYPE somlreci1.

"Workareas

DATA :

w_document_data TYPE t_document_data,

w_packing_list TYPE t_packing_list,

w_attachment TYPE t_attachment,

w_body_msg TYPE t_body_msg,

w_receivers TYPE t_receivers.

"Internal Tables

DATA :

i_document_data TYPE STANDARD TABLE OF t_document_data,

i_packing_list TYPE STANDARD TABLE OF t_packing_list,

i_attachment TYPE STANDARD TABLE OF t_attachment,

i_body_msg TYPE STANDARD TABLE OF t_body_msg,

i_receivers TYPE STANDARD TABLE OF t_receivers.

parameters:

p_mail type char100.

----


"start-of-selection.

----


START-OF-SELECTION.

PERFORM send_mail.

&----


"Form send_mail

"----


" PACKING LIST table requires information about how the data in the

" tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to be

" distributed to the documents and its attachments. The first row is

" for the document, the following rows are each for one attachment.

&----


FORM send_mail .

"Subject of the mail.

w_document_data-obj_name = 'MAIL_TO_HEAD'.

w_document_data-obj_descr = 'Simple mail using SAP ABAP'.

"Body of the mail

PERFORM build_body_of_mail

USING:space,

'Hi,',

'I am fine. How are you? How are you doing ? ',

'This program has been created to send simple mail',

'with Subject,Body with Address of the sender. ',

'Thanks and Regards,',

'Venkat.O,',

'SAP HR Technical Consultant.'.

"Write Packing List (Body)

DESCRIBE TABLE i_body_msg LINES g_tab_lines.

w_packing_list-head_start = 1.

w_packing_list-head_num = 0.

w_packing_list-body_start = 1.

w_packing_list-body_num = g_tab_lines.

w_packing_list-doc_type = 'RAW'.

APPEND w_packing_list TO i_packing_list.

CLEAR w_packing_list.

"Fill the document data and get size of attachment

READ TABLE i_body_msg INTO w_body_msg INDEX g_tab_lines.

w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_body_msg ).

"Receivers List.

w_receivers-rec_type = 'U'. "Internet address

w_receivers-receiver = p_mail

w_receivers-com_type = 'INT'.

w_receivers-notif_del = 'X'.

w_receivers-notif_ndel = 'X'.

APPEND w_receivers TO i_receivers .

CLEAR:w_receivers.

"Function module to send mail to Recipients

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_document_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = g_sent_to_all

TABLES

packing_list = i_packing_list

contents_txt = i_body_msg

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.

IF sy-subrc = 0 .

MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.

ELSE.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDIF.

ENDFORM. " send_mail

&----


" Form build_body_of_mail

&----


FORM build_body_of_mail USING l_message.

w_body_msg = l_message.

APPEND w_body_msg TO i_body_msg.

CLEAR w_body_msg.

ENDFORM. " build_body_of_mail

</pre

Thanks

Venkat.O

Former Member
0 Kudos

Hi,

use the bellow function module

SO_NEW_DOCUMENT_SEND_API1

regards,

munibabu.K

Former Member
0 Kudos

Hi,

use the bellow function module

SO_NEW_DOCUMENT_SEND_API1

regards,

munibabu.K