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

Mail using ABAP

Former Member
0 Likes
745

Hi all,

What is mail using ABAP?

reply me soon,

s.suresh

5 REPLIES 5
Read only

Former Member
0 Likes
639

Hi,

Refer to the link below:

http://sapdev.co.uk/reporting/email/emailhome.htm

Hope this helps.

Reward if helpful.

Regards,

Sipra

Read only

Former Member
0 Likes
639

hi,

Also follo this link for wiki.....

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/sending%2bemails%2band%2bsap%2bmails%2busing...



&--------------------------------------------------------------------- 
*& Report ZWBSAP_EMAIL * 
*& * 
&--------------------------------------------------------------------- 
*& * 
*& * 
&--------------------------------------------------------------------- 
*Send an email via SAP Workplace 
*Select files from SAP server 


*Note: 

Uses custom table zlookup to pick up a group of email addresses to send to 
if more than one is needed. 

Please note some hard coding. 

REPORT zsap_email MESSAGE-ID z001. 

TABLES: rlgrap, btcxpm, zlookup. 

DATA: 
v_zcode(3) TYPE c, 
svrname LIKE zlookup-zdesc, 
wa_error(80) TYPE c, 
global_filemask_all(80). 


DATA: t_soud LIKE soud. 
DATA: p_infolder LIKE sofdk. 
DATA: p_outfolder LIKE sofdk. 
DATA: object_hd_display LIKE sood2. 
DATA: object_id LIKE soodk. 
DATA: document LIKE sood4. 
DATA: header_data LIKE sood2. 
DATA: link_folder_id LIKE soodk. 
DATA: folder_selections LIKE sofds. 

DATA: folder_list LIKE soxli OCCURS 0 WITH HEADER LINE. 
DATA: receivers LIKE soos1 OCCURS 0 WITH HEADER LINE. 
DATA: objcont LIKE soli OCCURS 0 WITH HEADER LINE. 
DATA: objhead LIKE soli OCCURS 0 WITH HEADER LINE. 
DATA: object_content LIKE solisti1 OCCURS 0 WITH HEADER LINE. 
DATA: object_hd_change LIKE sood1. 



DATA: BEGIN OF files OCCURS 0, 
line(200) TYPE c, 
END OF files. 
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE. 


*Email to addresses 
SELECTION-SCREEN: BEGIN OF BLOCK bl1 WITH FRAME TITLE text-bl1. 
PARAMETERS: p_mailto(240) TYPE c. 
SELECTION-SCREEN SKIP 1. 
SELECTION-SCREEN COMMENT 10(2) text-001. 
*Use zlookup-ztype as group to define multiple email to addresses 
SELECT-OPTIONS: s_mailto FOR zlookup-ztype. 
SELECTION-SCREEN: END OF BLOCK bl1. 

*Subject 
SELECTION-SCREEN: BEGIN OF BLOCK bl2 WITH FRAME TITLE text-bl2. 
PARAMETERS: p_subj LIKE document-objdes. 
SELECTION-SCREEN: END OF BLOCK bl2. 

*Body 
SELECTION-SCREEN: BEGIN OF BLOCK bl3 WITH FRAME TITLE text-bl3. 
PARAMETERS: p_body1 LIKE solisti1-line LOWER CASE. 
PARAMETERS: p_body2 LIKE solisti1-line LOWER CASE. 
PARAMETERS: p_body3 LIKE solisti1-line LOWER CASE. 
PARAMETERS: p_body4 LIKE solisti1-line LOWER CASE. 
PARAMETERS: p_body5 LIKE solisti1-line LOWER CASE. 
PARAMETERS: p_body6 LIKE solisti1-line LOWER CASE. 
SELECTION-SCREEN: END OF BLOCK bl3. 

*Attachments 
SELECTION-SCREEN: BEGIN OF BLOCK bl4 WITH FRAME TITLE text-bl4. 
PARAMETERS: p_fname1 LIKE files-line. 
PARAMETERS: p_fname2 LIKE files-line. 
PARAMETERS: p_fname3 LIKE files-line. 
PARAMETERS: p_fname4 LIKE files-line. 
PARAMETERS: p_fname5 LIKE files-line. 
PARAMETERS: p_fname6 LIKE files-line. 
SELECTION-SCREEN: END OF BLOCK bl4. 


AT SELECTION-SCREEN. 

PERFORM chk_selection. 
IF NOT wa_error IS INITIAL. 
MESSAGE e001 WITH wa_error. 
ENDIF. 


START-OF-SELECTION. 

END-OF-SELECTION. 

PERFORM send_email. 


--------------------------------------------------------------------- 


FORM chk_selection * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 
FORM chk_selection. 
CLEAR wa_error. 
*Loop only once ??? 
*If more checkings to be done. 
*Think about it and if not clear. 
*Let it sink in for a couple of minutes. 
*Still doesn't make sence? Go home and sleep on it. 
DO 1 TIMES. 
*Check Email to 
IF p_mailto IS INITIAL 
AND s_mailto IS INITIAL. 
wa_error = 'Invalid or no EMAIL TO selection'. 
EXIT. 
ENDIF. 
ENDDO. 
ENDFORM. 

&--------------------------------------------------------------------- 
*& Form send_email 
&--------------------------------------------------------------------- 


text 
---------------------------------------------------------------------- 

--> p1 text 
<-- p2 text 
---------------------------------------------------------------------- 
FORM send_email. 
PERFORM get_folder_info. 
PERFORM fill_body. 
PERFORM ins_new_object. 
PERFORM crt_attachments. 
PERFORM fill_receivers_info. 
PERFORM snd_email. 
ENDFORM. " send_email 

--------------------------------------------------------------------- 


FORM Get_folder_info * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 
FORM get_folder_info. 
CLEAR t_soud. 
*Small so should be quick. 
SELECT * FROM soud 
INTO t_soud 
WHERE sapnam = sy-uname. 
p_infolder-foltp = 'FOL'. 
p_infolder-folyr = t_soud-inbyr. "inbox 
p_infolder-folno = t_soud-inbno. 
p_outfolder-foltp = 'FOL'. 
p_outfolder-folyr = t_soud-outyr. "outbox 
p_outfolder-folno = t_soud-outno. 
ENDSELECT. 
ENDFORM. 

--------------------------------------------------------------------- 

FORM fill_body * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 
FORM fill_body. 
object_content-line = p_body1. 
APPEND object_content. 
object_content-line = p_body2. 
APPEND object_content. 
object_content-line = p_body3. 
APPEND object_content. 
object_content-line = p_body4. 
APPEND object_content. 
object_content-line = p_body5. 
APPEND object_content. 
object_content-line = p_body6. 
APPEND object_content. 
ENDFORM. 

--------------------------------------------------------------------- 

FORM ins_new_object * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 
FORM ins_new_object. 
object_hd_change-objnam = 'Notes'. 
object_hd_change-objdes = p_subj. 

CALL FUNCTION 'SO_OBJECT_INSERT' 
EXPORTING 
folder_id = p_outfolder 
object_hd_change = object_hd_change 
object_type = 'RAW' 
owner = sy-uname 
IMPORTING 
object_hd_display = object_hd_display 
object_id = object_id 
TABLES 
objcont = object_content 
objhead = objhead 
EXCEPTIONS 
active_user_not_exist = 1 
communication_failure = 2 
component_not_available = 3 
dl_name_exist = 4 
folder_not_exist = 5 
folder_no_authorization = 6 
object_type_not_exist = 7 
operation_no_authorization = 8 
owner_not_exist = 9 
parameter_error = 10 
substitute_not_active = 11 
substitute_not_defined = 12 
system_failure = 13 
x_error = 14 
OTHERS = 15. 
IF sy-subrc 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
ENDFORM. 

--------------------------------------------------------------------- 

FORM crt_attachments * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 

--> P_SUBJ * 
--------------------------------------------------------------------- 
FORM crt_attachments. 
document-foltp = p_outfolder-foltp. 
document-folyr = p_outfolder-folyr. 
document-folno = p_outfolder-folno. 
document-objtp = object_id-objtp. 
document-objyr = object_id-objyr. 
document-objno = object_id-objno. 
document-objnam = 'Notes'. 
document-objdes = p_subj. 
document-okcode = 'CHNG'. 
document-file_ext = 'TXT'. 
link_folder_id = object_id. 

header_data-objla = 'EN'. 
header_data-objnam = document-objnam. 
header_data-objdes = document-objdes. 
header_data-objpri = '5'. 
header_data-objsns = 'O'. 
header_data-file_ext = 'TXT'. 

REFRESH files. 
CLEAR files. 
IF NOT p_fname1 IS INITIAL. 
files-line = p_fname1. 
APPEND files. 
ENDIF. 
IF NOT p_fname2 IS INITIAL. 
files-line = p_fname2. 
APPEND files. 
ENDIF. 
IF NOT p_fname3 IS INITIAL. 
files-line = p_fname3. 
APPEND files. 
ENDIF. 
IF NOT p_fname4 IS INITIAL. 
files-line = p_fname4. 
APPEND files. 
ENDIF. 
IF NOT p_fname5 IS INITIAL. 
files-line = p_fname5. 
APPEND files. 
ENDIF. 
IF NOT p_fname6 IS INITIAL. 
files-line = p_fname6. 
APPEND files. 
ENDIF. 
IF NOT files[] IS INITIAL. 
CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER' 
EXPORTING 
method = 'ATTCREATEFROMPC' 
TABLES 
files = files 
CHANGING 
document = document 
header_data = header_data. 

IF sy-subrc = 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
ENDIF. 
ENDFORM. 


--------------------------------------------------------------------- 


FORM fill_receivers_info * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 
FORM fill_receivers_info. 
DATA: BEGIN OF reclist OCCURS 0, 
rec LIKE receivers-recextnam, 
END OF reclist. 

*Build reclist 
REFRESH reclist. 
IF NOT p_mailto IS INITIAL. 
reclist-rec = p_mailto. 
APPEND reclist. 
ENDIF. 

IF NOT s_mailto IS INITIAL. 
SELECT zdesc 
INTO reclist-rec 
FROM zlookup 
WHERE ztype IN s_mailto. 
APPEND reclist. 
ENDSELECT. 
ENDIF. 

REFRESH receivers. 
LOOP AT reclist. 

folder_selections-folnam = 'INBOX'. 
CALL FUNCTION 'SO_FOLDER_LIST_READ' 
EXPORTING 
folder_selections = folder_selections 
owner = sy-uname 
region = 'P' 
TABLES 
folder_list = folder_list 
EXCEPTIONS 
component_not_available = 1 
operation_no_authorization = 2 
owner_not_exist = 3 
parameter_error = 4 
x_error = 5 
OTHERS = 6. 
IF sy-subrc = 0. 
CLEAR receivers. 
receivers-rcdat = sy-datum. 
receivers-rctim = sy-uzeit. 
receivers-recnam = reclist-rec. 
receivers-recno = folder_list-parno. 
receivers-rectp = folder_list-partp. 
receivers-recyr = folder_list-paryr. 
receivers-sndtp = folder_list-partp. 
receivers-sndyr = folder_list-paryr. 
receivers-sndno = folder_list-parno. 
receivers-sndnam = sy-uname. 
receivers-sndpri = '1'. 
receivers-msgid = 'SO'. 
receivers-msgno = '619'. 
receivers-deliver = 'X'. 
receivers-not_deli = 'X'. 
receivers-read = 'X'. 
receivers-mailstatus = 'E'. 
*receivers-ADR_NAME 
receivers-resend = ' '. 
receivers-sortfield = ' '. "'USER WF_BATCH INDIGO BATCH'. 
receivers-sortclass = '5'. 
APPEND receivers. 
ELSE. 
CLEAR receivers. 
receivers-sel = 'X'. 
receivers-recesc = 'U'. 
receivers-recnam = 'U-'. 
receivers-recextnam = reclist-rec. 
receivers-deliver = 'X'. 
receivers-not_deli = 'X'. 
receivers-read = 'X'. 
receivers-mailstatus = 'E'. 
receivers-adr_name = reclist-rec. 
receivers-sortfield = reclist-rec. 
receivers-sortclass = '5'. 
APPEND receivers. 
ENDIF. 
ENDLOOP. 
ENDFORM. 

--------------------------------------------------------------------- 


FORM snd_email * 
--------------------------------------------------------------------- 

........ * 
--------------------------------------------------------------------- 
FORM snd_email. 
CALL FUNCTION 'SO_OBJECT_SEND' 
EXPORTING 
folder_id = p_outfolder 
object_id = object_id 
outbox_flag = 'X' 
owner = sy-uname 
check_send_authority = 'X' 
originator_type = 'J' 
link_folder_id = link_folder_id 
TABLES 
objcont = object_content 
receivers = receivers 
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 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
ENDFORM. 


Hope this helps, Do reward.

Edited by: Runal Singh on Apr 3, 2008 12:40 PM

Read only

0 Likes
639

Hi Runal,

I cannot understand your program.......

Read only

0 Likes
639

hi,

Follow this link, it gives step by step procedure.

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Hope this helps

Read only

Former Member
0 Likes
639

hi check out the similar forums below..

[]

[]

[]

Regards,

Balaram