Skip to Content
0
Former Member
Jul 20, 2009 at 06:35 AM

Sending Mail SAP to External Mail ID

1688 Views

+

Dear all ,+ 

 +I am using this Program for sending email through SAP.This Program is working fine, finally i got the message Successfully mail  sent.+  
+But i checked my external mail id (yahoo) , what i had to sent that is  not there in mail .+

 +where shall i check the Error? could u explain me.+



----


" Data retrieval related declarations

----


types:

begin of t_emp_dat,

pernr type pa0001-pernr,

persg type pa0001-persg,

persk type pa0001-persk,

plans type pa0001-plans,

stell type pa0001-stell,

end of t_emp_dat.

data:

w_emp_data type t_emp_dat.

data:

i_emp_data type standard table of t_emp_dat.

----


" 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 char120.

----


"Start-of-selection.

----


start-of-selection.

perform get_data.

perform build_xls_data_table.

----


"End-of-selection.

----


end-of-selection.

perform send_mail.

&----


"Form get_data from PA0001

&----


form get_data.

select pernr

persg

persk

plans

stell

from pa0001

into corresponding fields of table i_emp_data

up to 4 rows.

endform. " get_data

&----


"Form build_xls_data_table

&----


form build_xls_data_table.

"If you have Unicode check active in program attributes then

"you will need to declare constants as follows.

class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>horizontal_tab,

con_cret type c value cl_abap_char_utilities=>cr_lf.

concatenate 'PERNR' 'PERSG' 'PERSK' 'PLANS' 'STELL'

into w_attachment

separated by con_tab.

concatenate con_cret

w_attachment

into w_attachment.

append w_attachment to i_attachment.

clear w_attachment.

loop at i_emp_data into w_emp_data.

concatenate w_emp_data-pernr

w_emp_data-persg

w_emp_data-persk

w_emp_data-plans

w_emp_data-stell

into w_attachment

separated by con_tab.

concatenate con_cret w_attachment

into w_attachment.

append w_attachment to i_attachment.

clear w_attachment.

endloop.

endform. "build_xls_data_table

&----


"Form send_mail

"----


"PACKING LIST

"This 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 = 'Regarding Mail Program by 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. ',

'Regards,',

'Venkat.O,',

'SAP HR Technical Consultant.'.

"Write Packing List for 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.

"Write Packing List for Attachment

w_packing_list-transf_bin = 'X'.

w_packing_list-head_start = 1.

w_packing_list-head_num = 1.

w_packing_list-body_start = 1.

describe table i_attachment lines w_packing_list-body_num.

w_packing_list-doc_type = 'XLS'.

w_packing_list-obj_descr = 'Excell Attachment'.

w_packing_list-obj_name = 'XLS_ATTACHMENT'.

w_packing_list-doc_size = w_packing_list-body_num * 255.

append w_packing_list to i_packing_list.

clear w_packing_list.

"Fill the document data and get size of attachment

w_document_data-obj_langu = sy-langu.

read table i_attachment into w_attachment index g_tab_lines.

w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + strlen( w_attachment ).

"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_bin = i_attachment

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.

"This program starts the SAPconnect send process.

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

 

Regards ,

Shankar GJ