05-08-2006 6:08 PM
Hi,
I have to send a notification when one of the condition occurs. I have to send email based on the role of the users, i.e first find the email addresses of the users based on the role and then send email to their non-sap email addresses(like the company outlook email). Can someone tell me the detailed steps need to be followed here..
Thanks in advance,
Henry.
05-08-2006 6:14 PM
Hi,
You can use the function SONEWDOCUMENTAPI for sending a mail to either a SAP user or a external mail address. You just will have to change the TYPE in the table where you specify the mail address.
So, depending on your condition populate the appropriate user type for the function module parameters.
Regards,
Ravi
Note : Please mark the helpful answers
05-08-2006 6:15 PM
You can use FM SO_NEW_DOCUMENT_SEND_API1. Search in the forum with string SO_NEW_DOCUMENT_SEND_API1, there is a lot of threads about it.
Regards.
05-08-2006 6:25 PM
hi David,
WELCOME TO SDN
Use FM <b>SO_NEW_DOCUMENT_SEND_API1.</b>
SAP Send mail via ABAP functions SO_NEW_DOCUMENT_SEND_API1
This abap mail sending program demonstrate how you can send a mail to the user SAP Office mailbox.
REPORT ZSEND .
TABLES: KNA1.
data for send function
DATA DOC_DATA LIKE SODOCCHGI1.
DATA OBJECT_ID LIKE SOODK.
DATA OBJCONT LIKE SOLI OCCURS 10 WITH HEADER LINE.
DATA RECEIVER LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE.
SELECT * FROM KNA1 WHERE ANRED LIKE 'C%'.
WRITE:/ KNA1-KUNNR, KNA1-ANRED.
send data internal table
CONCATENATE KNA1-KUNNR KNA1-ANRED
INTO OBJCONT-LINE SEPARATED BY SPACE.
APPEND OBJCONT.
ENDSELECT.
insert receiver (sap name)
REFRESH RECEIVER.
CLEAR RECEIVER.
MOVE: SY-UNAME TO RECEIVER-RECEIVER,
'X' TO RECEIVER-EXPRESS,
'B' TO RECEIVER-REC_TYPE.
APPEND RECEIVER.
insert mail description
WRITE 'Sending a mail through abap'
TO DOC_DATA-OBJ_DESCR.
CALL FUNCTION <b>'SO_NEW_DOCUMENT_SEND_API1'</b>
EXPORTING
DOCUMENT_DATA = DOC_DATA
IMPORTING
NEW_OBJECT_ID = OBJECT_ID
TABLES
OBJECT_CONTENT = OBJCONT
RECEIVERS = RECEIVER
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.
http://sapr3.tripod.com/abap011.htm
Regards,
Santosh
Note: Reward Points if helpful
05-08-2006 7:42 PM
Hi Santosh,
But what should i do if i have to send it Microsoft Outlook email address i.e non-SAP office address.
Thanks,
Henry
05-08-2006 7:46 PM
Here is an example.....
report zrich_0003 .
* For API
data: maildata type sodocchgi1.
data: mailtxt type table of solisti1 with header line.
data: mailrec type table of somlrec90 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test'.
maildata-obj_langu = sy-langu.
mailtxt-line = 'This is a test'.
append mailtxt.
<b> mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type = 'U'.
append mailrec.</b>
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'RAW'
put_in_outbox = 'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Regards.
Rich Heilman
05-08-2006 7:59 PM
Hey Rich,
Thanks for that example. Do you know how i can find the users from a role, because according to my requirement i have to find users for a role and then find their corresponding email addresses and then send an email to them.Any advise would be greatly appreciated.
Thanks in advance,
Henry.
05-08-2006 8:03 PM
Not sure how to get the users from the role, but once you get the user, you can get there email address like this.
select Single adr6~smtp_addr
into email_address from usr21
inner join adr6
on usr21~addrnumber = adr6~addrnumber
and usr21~persnumber = adr6~persnumber
where usr21~bname = sy-uname.
Please make sure to award points for any helpful answers. Thanks.
Regards,
Rich Heilman
05-08-2006 8:18 PM
Tables :
AGR_USERS
and AGR_1251 ( with object values for roles )
Hope thisll give you idea!!
<b>P.S award the points.!!! !!!</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise"
05-08-2006 9:37 PM
Hi rich,
The sample code you senti tried running it by giving my company ID but it doesn't work. Do i have to do anything else.
Thanks,
Henry
05-08-2006 9:42 PM
05-08-2006 9:55 PM
Hi Rich,
I am able to send it to my SAP Office mail thru ur code but not my outlook email address.
Thanks,
Henry.
05-08-2006 10:11 PM
Hey Rich,
How do we check if SAP Connect is configured properly or not..What are the settings that we should check for and where??..
Thanks in advance,
Henry.