05-22-2006 11:17 AM
Hi All,
I have a requirement of sending e-mail from my report to MS-OUTLOOK . please help me regarding function module
or any other source.
Thanks in advance,
Regards,
Srinivas
05-22-2006 11:34 AM
05-22-2006 11:22 AM
The useful fms in this regard are,
SO_NEW_DOCUMENT_ATT_SEND_API1 SAPoffice: Send new document with attachments using RFC
SO_NEW_DOCUMENT_SEND_API1 SAPoffice: Send new document
Refer this link for an example:
http://www.sap-img.com/fu016.htm
Regards,
Ravi
05-22-2006 11:23 AM
Check the below link about how to Send external email from within ABAP program
http://www.sapdevelopment.co.uk/reporting/email/email_mbody.htm
check the above thread and award points if helpful
05-22-2006 11:31 AM
05-22-2006 11:34 AM
05-22-2006 11:44 AM
if you are on 4.7 and above you can use the following code sample.
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2f9a6165a0">E-mail ABAP Report List output in HTML format</a>
Regards
Raja
05-22-2006 11:39 AM
HI
GOOD
CHECK THIS CODE=>
FORM SEND_MAIL.
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
DATA L_NUM(3).
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.
Mail Contents
OBJTXT = 'Object text'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
LOOP AT ITAB_DATA.
CONCATENATE ITAB_DATA-PRODUCTOR
ITAB_DATA-VBELN
ITAB_DATA-POSNR
ITAB_DATA-MATNR INTO OBJBIN.
APPEND OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'ORDERS'.
APPEND OBJHEAD.
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'TXT'.
OBJPACK-OBJ_NAME = 'WEBSITE'.
OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
target recipent
clear RECLIST.
RECLIST-RECEIVER = 'test@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
copy recipents
clear RECLIST.
RECLIST-RECEIVER = 'secondtest@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
RECLIST-COPY = 'X'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
ENDFORM. " SEND_MAIL
==============
FUNCTION z_send_email_itab_uname.
*"----
""Local interface:
*" IMPORTING
*" VALUE(APPLICATION) LIKE SOOD1-OBJNAM
*" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES
*" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM OPTIONAL
*" VALUE(SENDER) LIKE SOUD-USRNAM DEFAULT SY-UNAME
*" VALUE(UNAME) LIKE SOOS1-RECEXTNAM OPTIONAL
*" EXPORTING
*" VALUE(RETURN_CODE) LIKE SY-SUBRC
*" TABLES
*" TEXTTAB STRUCTURE SOLI
*"----
tables
TABLES: pa0105, "Employee detail for username and email address
usr21, "Login addition address data
adr6. "Address table for email addresses
*- local data declaration
DATA: ohd LIKE sood1,
oid LIKE soodk,
to_all LIKE sonv-flag,
t_uname LIKE sy-uname,
okey LIKE swotobjid-objkey.
DATA: BEGIN OF receivers OCCURS 0.
INCLUDE STRUCTURE soos1.
DATA: END OF receivers.
*- fill odh
CLEAR ohd.
ohd-objla = sy-langu.
ohd-objnam = application.
ohd-objdes = emailtitle.
ohd-objpri = 3.
ohd-objsns = 'F'.
ohd-ownnam = sy-uname.
IF NOT uname IS INITIAL.
Find personnel number of username
CONDENSE uname NO-GAPS.
WHILE uname CS ','.
t_uname = uname+0(sy-fdpos).
ADD 1 TO sy-fdpos.
SHIFT uname LEFT BY sy-fdpos PLACES.
PERFORM find_email_address USING t_uname
CHANGING recextnam.
ENDWHILE.
*Do the last record
IF uname <> space.
t_uname = uname.
PERFORM find_email_address USING t_uname
CHANGING recextnam.
ENDIF.
ENDIF.
*- send Email
IF NOT recextnam IS INITIAL.
CONDENSE recextnam NO-GAPS.
CHECK recextnam CS '@'.
ENDIF.
*- for every individual recipient send an Email
(see OSS message 0120050409/0000362105/1999)
WHILE recextnam CS ','.
PERFORM init_rec TABLES receivers.
READ TABLE receivers INDEX 1.
receivers-recextnam = recextnam+0(sy-fdpos).
ADD 1 TO sy-fdpos.
SHIFT recextnam LEFT BY sy-fdpos PLACES.
MODIFY receivers INDEX 1.
PERFORM so_object_send_rec
TABLES texttab receivers
USING ohd
sender.
ENDWHILE.
*- check last recipient in recipient list
IF recextnam <> space.
PERFORM init_rec TABLES receivers.
READ TABLE receivers INDEX 1.
receivers-recextnam = recextnam.
MODIFY receivers INDEX 1.
PERFORM so_object_send_rec
TABLES texttab receivers
USING ohd
sender.
ENDIF.
ENDFUNCTION.
----
FORM SO_OBJECT_SEND_REC *
----
FORM so_object_send_rec
TABLES objcont STRUCTURE soli
receivers STRUCTURE soos1
USING object_hd STRUCTURE sood1
sender LIKE soud-usrnam.
DATA: oid LIKE soodk,
to_all LIKE sonv-flag,
okey LIKE swotobjid-objkey.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
extern_address = 'X'
object_hd_change = object_hd
object_type = 'RAW'
outbox_flag = 'X'
sender = sender
IMPORTING
object_id_new = oid
sent_to_all = to_all
office_object_key = okey
TABLES
objcont = objcont
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
x_error = 20
OTHERS = 21.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
MESSAGE i999(b1) WITH 'Activer user does not exist.'
'Send Mail failed!'.
WHEN 2.
MESSAGE i999(b1) WITH 'Communication Failure.'
'Send Mail failed!'.
WHEN 3.
MESSAGE i999(b1) WITH 'Component not available.'
'Send Mail failed!'.
WHEN 4.
MESSAGE i999(b1) WITH 'Folder does not exist..'
'Send Mail failed!'.
WHEN 5.
MESSAGE i999(b1) WITH 'No authorization for folder.'
'Send Mail failed!'.
WHEN 6.
MESSAGE i999(b1) WITH 'Forwarder does not exist.'
'Send Mail failed!'.
WHEN 7.
MESSAGE i999(b1) WITH 'Note does not exist.'
'Send Mail failed!'.
WHEN 8.
MESSAGE i999(b1) WITH 'Object does not exist.'
'Send Mail failed!'.
WHEN 9.
MESSAGE i999(b1) WITH 'Object not sent.'
'Send Mail failed!'.
WHEN 10.
MESSAGE i999(b1) WITH 'No authorization for object.'
'Send Mail failed!'.
WHEN 11.
MESSAGE i999(b1) WITH 'Object type does not exist.'
'Send Mail failed!'.
WHEN 12.
MESSAGE i999(b1) WITH 'No authorization for operation.'
'Send Mail failed!'.
WHEN 13.
MESSAGE i999(b1) WITH 'Owner does not exist.'
'Send Mail failed!'.
WHEN 14.
MESSAGE i999(b1) WITH 'Parameter Error.'
'Send Mail failed!'.
WHEN 15.
MESSAGE i999(b1) WITH 'Substitute not active.'
'Send Mail failed!'.
WHEN 16.
MESSAGE i999(b1) WITH 'Substitute not defined.'
'Send Mail failed!'.
WHEN 17.
MESSAGE i999(b1) WITH 'System failure.'
'Send Mail failed!'.
WHEN 18.
MESSAGE i999(b1) WITH 'Too many receivers.'
'Send Mail failed!'.
WHEN 19.
MESSAGE i999(b1) WITH 'User does not exist.'
'Send Mail failed!'.
WHEN 20.
MESSAGE i999(b1) WITH 'Unknown error ocurred.'
'Send Mail failed!'.
WHEN 21.
MESSAGE i999(b1) WITH 'Unknown error ocurred.'
'Send Mail failed!'.
ENDCASE.
ENDIF.
ENDFORM.
*
*
*
*----
FORM INIT_REC *
*----
FORM init_rec TABLES receivers STRUCTURE soos1.
CLEAR receivers.
REFRESH receivers.
MOVE sy-datum TO receivers-rcdat .
MOVE sy-uzeit TO receivers-rctim.
MOVE '1' TO receivers-sndpri.
MOVE 'X' TO receivers-sndex.
MOVE 'U-' TO receivers-recnam.
MOVE 'U' TO receivers-recesc.
MOVE 'INT' TO receivers-sndart.
MOVE '5' TO receivers-sortclass.
APPEND receivers.
ENDFORM.
&----
*& Form find_email_address
&----
Returns the email address for a USERID whether they are an
employee or just a user.
----
<--P_RECEXTNAM Email address
-->P_UNAME USERID
----
FORM find_email_address USING p_uname
CHANGING p_recextnam LIKE soos1-recextnam.
DATA: t_pernr LIKE pa0105-pernr,
t_email LIKE pa0105-usrid_long.
STEP 1 - Find personnel number for UNAME
SELECT SINGLE pernr INTO t_pernr
FROM pa0105
WHERE subty = '0001' AND
endda >= sy-datum AND
begda <= sy-datum AND
usrid = p_uname.
Employee record found
IF sy-subrc = 0.
STEP 2 - Find email address for personnel number
SELECT SINGLE usrid_long INTO t_email
FROM pa0105
WHERE pernr = t_pernr AND
subty = '0022' AND
endda >= sy-datum AND
begda <= sy-datum.
IF sy-subrc = 0.
IF NOT p_recextnam IS INITIAL.
CONCATENATE p_recextnam t_email
INTO p_recextnam SEPARATED BY ','.
ELSE.
p_recextnam = t_email.
ENDIF.
ELSE. "Never found an email address for employee
WHO SHOULD WE SEND TO HERE??? ***
ENDIF.
Employee number not found. Search in ADR6 table
ELSE.
See if user name is in the username table.
i.e. The user is not an employee
SELECT SINGLE addrnumber persnumber
INTO (usr21-addrnumber, usr21-persnumber)
FROM usr21
WHERE bname = p_uname.
IF sy-subrc = 0.
Found user name now let's get the email address
SELECT SINGLE smtp_addr INTO t_email
FROM adr6
WHERE addrnumber = usr21-addrnumber AND
persnumber = usr21-persnumber.
IF sy-subrc <> 0 OR t_email IS INITIAL.
WHO SHOULD WE SEND TO HERE??? ***
ELSE. "Found email
IF NOT p_recextnam IS INITIAL.
CONCATENATE p_recextnam t_email
INTO p_recextnam SEPARATED BY ','.
ELSE.
p_recextnam = t_email.
ENDIF.
ENDIF.
ELSE. "UNAME just does not have an email address addigned at all
WHO SHOULD WE SEND TO HERE??? ***
ENDIF.
ENDIF.
ENDFORM. " find_email_address
THANKS
MRUTYUN
05-22-2006 1:08 PM
Hai Srinivas E
Try with the following Code
Email ITAB structure
DATA: BEGIN OF EMAIL_ITAB OCCURS 10.
INCLUDE STRUCTURE SOLI.
DATA: END OF EMAIL_ITAB.
DATA: T_EMAIL LIKE SOOS1-RECEXTNAM. "EMail distribution list
CONSTANTS: C_EMAIL_DISTRIBUTION LIKE SOOS1-RECEXTNAM VALUE
abc@here.com,abc@there.com.
Initialization
REFRESH EMAIL_ITAB.
Populate data
EMAIL_ITAB-LINE = Email body text 1.
APPEND EMAIL_ITAB.
EMAIL_ITAB-LINE = Email body text 2.
APPEND EMAIL_ITAB.
T_EMAIL = C_EMAIL_DISTRIBUTION.
--- EMAIL FUNCTION ---------------------------------------------------
REQUIRMENTS:
1) The user running the program needs a valid email address in their
address portion of tx SU01 under external comms -> SMTP -> internet
address.
2) A job called SAP_EMAIL is running with the following parameters:
Program: RSCONN01 Variant: INT User: XXX
This program moves mail from the outbox to the mail server using
RFC destination: SAP_INTERNET_GATEWAY_SERVER
INTERFACE:
1) APPLICATION: Anything
2) EMAILTITLE: EMail subject
3) RECEXTNAM: EMail distribution lists separated by commas
4) TEXTTAB: Internal table for lines of the email message
EXCEPTIONS:
Send OK = 0 otherwise there was a problem with the send.
----------------------------------------------------------------------
CALL FUNCTION 'Z_SEND_EMAIL_ITAB'
EXPORTING
APPLICATION = 'EMAIL'
EMAILTITLE = 'Email Subject'
RECEXTNAM = T_EMAIL
TABLES
TEXTTAB = EMAIL_ITAB
EXCEPTIONS
OTHERS = 1.
Function Z_SEND_EMAIL_ITAB
""Local interface:
*" IMPORTING
*" VALUE(APPLICATION) LIKE SOOD1-OBJNAM
*" VALUE(EMAILTITLE) LIKE SOOD1-OBJDES
*" VALUE(RECEXTNAM) LIKE SOOS1-RECEXTNAM
*" TABLES
*" TEXTTAB STRUCTURE SOLI
*"----
*- local data declaration
DATA: OHD LIKE SOOD1,
OID LIKE SOODK,
TO_ALL LIKE SONV-FLAG,
OKEY LIKE SWOTOBJID-OBJKEY.
DATA: BEGIN OF RECEIVERS OCCURS 0.
INCLUDE STRUCTURE SOOS1.
DATA: END OF RECEIVERS.
*- fill odh
CLEAR OHD.
OHD-OBJLA = SY-LANGU.
OHD-OBJNAM = APPLICATION.
OHD-OBJDES = EMAILTITLE.
OHD-OBJPRI = 3.
OHD-OBJSNS = 'F'.
OHD-OWNNAM = SY-UNAME.
*- send Email
CONDENSE RECEXTNAM NO-GAPS.
CHECK RECEXTNAM <> SPACE AND RECEXTNAM CS '@'.
*- for every individual recipient send an Email
(see OSS message 0120050409/0000362105/1999)
WHILE RECEXTNAM CS ','.
PERFORM INIT_REC TABLES RECEIVERS.
READ TABLE RECEIVERS INDEX 1.
RECEIVERS-RECEXTNAM = RECEXTNAM+0(SY-FDPOS).
ADD 1 TO SY-FDPOS.
SHIFT RECEXTNAM LEFT BY SY-FDPOS PLACES.
MODIFY RECEIVERS INDEX 1.
PERFORM SO_OBJECT_SEND_REC
TABLES TEXTTAB RECEIVERS
USING OHD.
ENDWHILE.
*- check last recipient in recipient list
IF RECEXTNAM <> SPACE.
PERFORM INIT_REC TABLES RECEIVERS.
READ TABLE RECEIVERS INDEX 1.
RECEIVERS-RECEXTNAM = RECEXTNAM.
MODIFY RECEIVERS INDEX 1.
PERFORM SO_OBJECT_SEND_REC
TABLES TEXTTAB RECEIVERS
USING OHD.
ENDIF.
ENDFUNCTION.
----
FORM SO_OBJECT_SEND_REC *
----
FORM SO_OBJECT_SEND_REC
TABLES OBJCONT STRUCTURE SOLI
RECEIVERS STRUCTURE SOOS1
USING OBJECT_HD STRUCTURE SOOD1.
DATA: OID LIKE SOODK,
TO_ALL LIKE SONV-FLAG,
OKEY LIKE SWOTOBJID-OBJKEY.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
EXTERN_ADDRESS = 'X'
OBJECT_HD_CHANGE = OBJECT_HD
OBJECT_TYPE = 'RAW'
OUTBOX_FLAG = 'X'
SENDER = SY-UNAME
IMPORTING
OBJECT_ID_NEW = OID
SENT_TO_ALL = TO_ALL
OFFICE_OBJECT_KEY = OKEY
TABLES
OBJCONT = OBJCONT
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
X_ERROR = 20
OTHERS = 21.
IF SY-SUBRC <> 0.
RAISE OTHERS.
ENDIF.
ENDFORM.
----
FORM INIT_REC *
----
FORM INIT_REC TABLES RECEIVERS STRUCTURE SOOS1.
CLEAR RECEIVERS.
REFRESH RECEIVERS.
MOVE SY-DATUM TO RECEIVERS-RCDAT .
MOVE SY-UZEIT TO RECEIVERS-RCTIM.
MOVE '1' TO RECEIVERS-SNDPRI.
MOVE 'X' TO RECEIVERS-SNDEX.
MOVE 'U-' TO RECEIVERS-RECNAM.
MOVE 'U' TO RECEIVERS-RECESC.
MOVE 'INT' TO RECEIVERS-SNDART.
MOVE '5' TO RECEIVERS-SORTCLASS.
APPEND RECEIVERS.
ENDFORM.
Thanks & regards
Sreeni
05-22-2006 1:55 PM
Hi
Try this piece of code:
parameters : P_TO(30),
P_SUBJ(100),
P_BODY1(10000),
P_ATTACH(50).
************************************************************************
include OLE2INCL.
************************************************************************
start-of-selection.
perform INVIO_MAIL.
************************************************************************
*&----
*
*& Form INVIO_MAIL
*&----
*
form INVIO_MAIL.
data: APPOUTLOOK type OLE2_OBJECT.
data: APPOUT2 type OLE2_OBJECT.
data: APPITEM type OLE2_OBJECT.
data: NAMESPACE type OLE2_OBJECT.
data: ATTACH type OLE2_OBJECT, NEW_MES type OLE2_OBJECT.
Crea oggetto OLE: outlook.application (vedi help VB -> macro).
create object APPOUTLOOK 'outlook.application'.
Apre Outlook nel caso sia chiuso.
call method of APPOUTLOOK 'GetNameSpace' = NAMESPACE
exporting #1 = 'MAPI'.
Crea nouva mail.
call method of APPOUTLOOK 'CreateItem' = APPITEM
exporting #1 = '0'.
Propietà: SEND TO, SUBJECT and BODY.
set property of APPITEM 'To' = P_TO.
set property of APPITEM 'Subject' = P_SUBJ.
set property of APPITEM 'Body' = P_BODY1.
if not P_ATTACH is initial.
call method of APPITEM 'ATTACHMENTS' = ATTACH.
*Attachment
call method of ATTACH 'ADD'
exporting #1 = P_ATTACH. "File su PC
endif.
Send ITEM
call method of APPITEM 'Send'.
Free object
free object APPITEM.
free object NAMESPACE.
CALL METHOD OF APPOUTLOOK 'Quit'.
free object APPOUTLOOK.
endform. " INVIO_MAIL
Max
05-23-2006 5:16 AM
Hi max,
Thanks for your Answer, That will works fine.
Cheers..
Srinivas