‎2010 Mar 22 5:53 AM
hi to all,
I trying to create program for sending mail through SAP. my program is
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.
*****Parameters
SELECTION-SCREEN BEGIN OF BLOCK ADDR WITH FRAME TITLE TEXT-001.
Parameters: p_rcvrI1 like RECLIST-RECEIVER OBLIGATORY.
Parameters: p_rcvrI2 like RECLIST-RECEIVER.
Parameters: p_rcvrI3 like RECLIST-RECEIVER.
Parameters: p_rcvrI4 like RECLIST-RECEIVER.
Parameters: p_rcvrI5 like RECLIST-RECEIVER.
SELECTION-SCREEN END OF BLOCK ADDR.
skip.
SELECTION-SCREEN BEGIN OF BLOCK SUBJ WITH FRAME TITLE TEXT-002.
Parameters: p_subj like DOC_CHNG-OBJ_DESCR OBLIGATORY
default 'This is the subject line of the email'.
SELECTION-SCREEN END OF BLOCK SUBJ.
SELECTION-SCREEN BEGIN OF BLOCK MSG WITH FRAME TITLE TEXT-003.
Parameters: p_txtL1 like OBJTXT OBLIGATORY
default 'This is the first line of msg'.
Parameters: p_txtL2 like OBJTXT
default 'This is the second line of msg'.
Parameters: p_txtL3 like OBJTXT
default 'This is the third line of msg'.
Parameters: p_txtL4 like OBJTXT
default 'This is the fourth line of msg'.
Parameters: p_txtL5 like OBJTXT
default 'This is the fifth line of msg'.
SELECTION-SCREEN END OF BLOCK MSG.
*******CREATING A DOCUMENT,SUBJECT, and MESSAGE TEXT
* File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
* Mail Subject
DOC_CHNG-OBJ_DESCR = p_subj.
* Mail Contents
OBJTXT = p_txtL1.
APPEND OBJTXT.
OBJTXT = p_txtL2.
APPEND OBJTXT.
OBJTXT = p_txtL3.
APPEND OBJTXT.
OBJTXT = p_txtL4.
APPEND OBJTXT.
OBJTXT = p_txtL5.
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.
******CREATING THE MAILING LIST
* Receiver = Internet Mail Account
RECLIST-RECEIVER = p_rcvrI1.
RECLIST-REC_TYPE = 'U'.
if reclist-receiver NE ' '.
APPEND RECLIST.
endif.
RECLIST-RECEIVER = p_rcvrI2.
RECLIST-REC_TYPE = 'U'.
if reclist-receiver NE ' '.
APPEND RECLIST.
endif.
RECLIST-RECEIVER = p_rcvrI3.
RECLIST-REC_TYPE = 'U'.
if reclist-receiver NE ' '.
APPEND RECLIST.
endif.
RECLIST-RECEIVER = p_rcvrI4.
RECLIST-REC_TYPE = 'U'.
if reclist-receiver NE ' '.
APPEND RECLIST.
endif.
RECLIST-RECEIVER = p_rcvrI5.
RECLIST-REC_TYPE = 'U'.
if reclist-receiver NE ' '.
APPEND RECLIST.
endif.
*Receiver = SAP Mail User
*RECLIST-RECEIVER = p_rcvrS2.
*RECLIST-REC_TYPE = 'P'.
*APPEND RECLIST.
******SENDING THE DOCUMENT
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
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.
WRite: / 'Address List ************'.
skip.
Write: / 'Address 1',p_rcvrI1.
Write: / 'Address 2',p_rcvrI2.
Write: / 'Address 3',p_rcvrI3.
Write: / 'Address 4',p_rcvrI4.
Write: / 'Address 5',p_rcvrI5.
skip.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the send process **********'.
skip.
*LOOP AT RECLIST.
* WRITE: / reclist-REC_ID,reclist-REC_DATE,reclist-retrn_CODE,
*RECLIST-RECEIVER(48).
* IF RECLIST-RETRN_CODE = 0.
* WRITE 'No Errors'.
* ELSE.
* WRITE 'The document could not be sent'.
*ENDIF.
*ENDLOOP.
WHEN 1.
WRITE: / 'No authorization for sending to the specified number',
'of recipients'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient'.
WHEN 4.
WRITE: / 'No send authorization'.
WHEN OTHERS.
WRITE: / 'Error occurred while sending'.
ENDCASE.
Skip.Skip.
Write:/ 'Mail Message ******** '.
skip.
Write:/10 p_subj.
skip.
Write:/10 'Message Content'.
skip.
Write:/10 p_txtL1.
Write:/10 P_txtL2.
Write:/10 P_txtL3.
Write:/10 P_txtL4.
Write:/10 P_txtL5.
is there any configuration for this. thank you.
‎2010 Mar 22 6:23 AM
Hi,
as your receipent is an external user, you have to make some settings in SCOT.
‎2010 Mar 22 6:30 AM
hi jaya ,
Can you telme the navigation . I just gone through SDN . I did't find solution. thank you
‎2010 Mar 22 7:07 AM
Hi,
pls go through this link and take help from your BASIS team.
[https://wiki.sdn.sap.com/wiki/display/Basis/SAP%20to%20send%20external%20mails]
‎2010 Mar 22 6:33 AM
Try This
REPORT ZSAPMAIL NO STANDARD PAGE HEADING.
TABLES: DRAD,
QINF,
DRAW,
SOUC,
SOFD,
DRAP.
DATA: P_RETURN_CODE LIKE SY-SUBRC.
data: d_username LIKE DRAP-PRNAM.
mail declarations
DATA : BEGIN OF NEW_OBJECT_ID. " the newly created email object
INCLUDE STRUCTURE SOODK.
DATA : END OF NEW_OBJECT_ID.
DATA : BEGIN OF FOLDER_ID. " the folder id of the outbox
INCLUDE STRUCTURE SOODK.
DATA : END OF FOLDER_ID.
DATA : BEGIN OF REC_TAB OCCURS 5. " the table which will contain the
INCLUDE STRUCTURE SOOS1. " information on the destination
DATA : END OF REC_TAB.
DATA : BEGIN OF OBJECT_HD_CHANGE. " the table which contains the
INCLUDE STRUCTURE SOOD1. " info for the object we will be
DATA : END OF OBJECT_HD_CHANGE. " creating
DATA : OBJECT_TYPE LIKE SOOD-OBJTP. " the type of object
DATA : BEGIN OF OBJHEAD OCCURS 5. " the header of the object
INCLUDE STRUCTURE SOLI.
DATA : END OF OBJHEAD.
DATA : BEGIN OF OBJCONT OCCURS 0. " the contents of the object
INCLUDE STRUCTURE SOLI. " i.e. the text etc
DATA : END OF OBJCONT.
DATA : BEGIN OF OBJPARA OCCURS 5. " formatting options
INCLUDE STRUCTURE SELC.
DATA : END OF OBJPARA.
DATA : BEGIN OF OBJPARB OCCURS 5. " formatting options
INCLUDE STRUCTURE SOOP1.
DATA : END OF OBJPARB.
DATA : BEGIN OF T_MAIL_TEXT OCCURS 0, "Message table for messages to
STRING(255), "user via mailbox
END OF T_MAIL_TEXT.
Parameter: p_uname like sy-uname.
************************************************************************
**START-OF-SELECTION
START-OF-SELECTION.
d_username = p_uname.
PERFORM POPULATE_EMAIL_TEXT.
PERFORM SETUP_TRX_AND_RTX_MAILBOXES USING P_RETURN_CODE.
PERFORM CREATE_AND_SEND_MAIL_OBJECT.
----
FORM POPULATE_EMAIL_TEXT *
----
Inserts text for email message *
----
FORM POPULATE_EMAIL_TEXT.
CLEAR T_MAIL_TEXT-STRING. "puts a blank line in
APPEND T_MAIL_TEXT.
APPEND T_MAIL_TEXT.
adds failed list on to end of success list.
T_MAIL_TEXT-STRING = 'Test email message line 1'.
APPEND T_MAIL_TEXT.
T_MAIL_TEXT-STRING = 'Test email message line 1'.
APPEND T_MAIL_TEXT.
CLEAR T_MAIL_TEXT-STRING. "puts a blank line in
APPEND T_MAIL_TEXT.
T_MAIL_TEXT-STRING = 'Header1 Header2 Header3'.
APPEND T_MAIL_TEXT.
T_MAIL_TEXT-STRING = '----
-
-
'.
APPEND T_MAIL_TEXT.
ENDFORM.
&----
*& Form SETUP_TRX_&_RTX_MAILBOXES
&----
Ensure that the mailboxes of the sender (INTMGR) are set up OK
----
FORM SETUP_TRX_AND_RTX_MAILBOXES USING P_RETURN_CODE.
get the user no of the sender in order to add the mail to the
user name's outbox for future reference
SELECT SINGLE * FROM SOUC
WHERE SAPNAM = SY-UNAME. "SAP name of a SAPoffice user
IF SY-SUBRC NE 0.
"Error finding the SAPoffice user info for the user
MESSAGE E064(ZR53) WITH SY-UNAME.
P_RETURN_CODE = 1.
EXIT.
ENDIF.
*Get the outbox No for the sender from the user No where the folder
" type is an outbox
SELECT * FROM SOFD WHERE OWNTP = SOUC-USRTP "Owner type from ID
AND OWNYR = SOUC-USRYR "Owner year from the ID
AND OWNNO = SOUC-USRNO "Owner number from the I
AND FOLRG = 'O'."Output box
ENDSELECT.
IF SY-SUBRC NE 0.
" Error getting folder information for the user
MESSAGE E065(ZR53) WITH SY-UNAME.
P_RETURN_CODE = 1.
EXIT.
ENDIF.
ENDFORM. " SETUP_TRX_&_RTX_MAILBOXES
&----
*& Form CREATE_AND_SEND_MAIL_OBJECT
&----
FORM CREATE_AND_SEND_MAIL_OBJECT.
FOLDER_ID-OBJTP = SOFD-FOLTP. " the folder type ( usually FOL )
FOLDER_ID-OBJYR = SOFD-FOLYR. " the folder year ( usually 22 )
FOLDER_ID-OBJNO = SOFD-FOLNO. " the folder no.
OBJECT_TYPE = 'RAW'. " the type of object being added
build up the object information for creating the object
OBJECT_HD_CHANGE-OBJLA = SY-LANGU. " the language of the email
OBJECT_HD_CHANGE-OBJNAM = 'PS to DM Interface'. " the object name
mail subject 'Mass Linking of QA, pass/fail'
MOVE TEXT-002 TO OBJECT_HD_CHANGE-OBJDES.
OBJECT_HD_CHANGE-DLDAT = SY-DATUM. " the date of the email
OBJECT_HD_CHANGE-DLTIM = SY-UZEIT. " the time of the email
OBJECT_HD_CHANGE-OBJPRI = '1'. " the priority ( highest )
OBJECT_HD_CHANGE-OBJSNS = 'F'. " the object sensitivity
F is functional, C - company sensitive
object_hd_change-skips = ' '. " Skip first screen
object_hd_change-acnam = 'SM35'. " Batch imput transaction
object_hd_change-vmtyp = 'T'. " Transaction type
add the text lines into the contents of the email
CLEAR OBJCONT.
REFRESH OBJCONT.
free objcont. " added this to delete the mail contents records
LOOP AT T_MAIL_TEXT.
OBJCONT-LINE = T_MAIL_TEXT-STRING.
APPEND OBJCONT.
ENDLOOP.
CLEAR OBJCONT.
build up the table of receivers for the email
REC_TAB-RCDAT = SY-DATUM. " the date to send the email
REC_TAB-RCTIM = SY-UZEIT. " the time to send the email
the SAP username of the person who will receive the email
REC_TAB-RECNAM = D_USERNAME.
the user type of the person who will send the email ( USR )
REC_TAB-SNDTP = SOUC-USRTP.
the user year of the person who will send the email ( 22 )
REC_TAB-SNDYR = SOUC-USRYR.
the user number of the person who will send the email
REC_TAB-SNDNO = SOUC-USRNO.
the sap username of the person who will send the email
REC_TAB-SNDNAM = SY-UNAME.
get the user info for the receiver of the document
SELECT SINGLE * FROM SOUC WHERE SAPNAM = D_USERNAME.
IF SY-SUBRC NE 0.
WRITE : / TEXT-001, D_USERNAME. "usnam.
EXIT.
ENDIF.
the user number of the person who will receive the email ( USR )
REC_TAB-RECNO = SOUC-USRNO.
the user type of the person who will receive the email ( USR )
REC_TAB-RECTP = SOUC-USRTP.
the user year of the person who will receive the email ( USR )
REC_TAB-RECYR = SOUC-USRYR.
the priority of the email ( highest )
REC_TAB-SNDPRI = '1'.
check for delivery on the email
REC_TAB-DELIVER = 'X'.
send express so recipient knows there is a problem
REC_TAB-SNDEX = 'X'.
check for a return receipt
REC_TAB-READ = 'X'.
the sap username of the person receiving the email
REC_TAB-ADR_NAME = D_USERNAME. "usnam.
add this receiver to the internal table
APPEND REC_TAB.
CLEAR REC_TAB.
call the function to create the object in the outbox of the sender
CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
FOLDER_ID = FOLDER_ID
OBJECT_HD_CHANGE = OBJECT_HD_CHANGE
OBJECT_TYPE = OBJECT_TYPE
OWNER = SY-UNAME
IMPORTING
OBJECT_ID = NEW_OBJECT_ID
TABLES
OBJCONT = OBJCONT
OBJHEAD = OBJHEAD
OBJPARA = OBJPARA
OBJPARB = OBJPARB
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 NE 0.
MESSAGE A063(ZR53) WITH SY-SUBRC.
EXIT.
ENDIF.
call the function to send the already created email to the receivers
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
FOLDER_ID = FOLDER_ID
OBJECT_ID = NEW_OBJECT_ID
OUTBOX_FLAG = 'X'
OWNER = SY-UNAME
TABLES
RECEIVERS = REC_TAB
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 EQ 0.
MESSAGE I035(ZR53) WITH NEW_OBJECT_ID D_USERNAME. "usnam.
ELSE.
MESSAGE I036(ZR53) WITH D_USERNAME." sy-subrc.
ENDIF.
ENDFORM. " CREATE_AND_SEND_MAIL_OBJECT
‎2010 Mar 22 7:10 AM
hi
I am trying to send mail to extranal user like normal gmails . I tried to program which mentioned in first. solve my problem. thank you
‎2010 Mar 22 7:22 AM