‎2009 Aug 05 5:17 AM
hi,
I am trying to trigger a mail thru the following code.But, the mail is not getting triggered.
PARAMETERS: p_email(50) LOWER CASE.
DATA: document_data LIKE sodocchgi1.
DATA: t_content LIKE STANDARD TABLE OF solisti1.
DATA: s_content LIKE solisti1.
DATA: t_receivers LIKE STANDARD TABLE OF somlreci1.
DATA: s_receivers LIKE somlreci1.
START-OF-SELECTION.
Receivers.
s_receivers-receiver = p_email.
s_receivers-rec_type = 'U'.
s_receivers-express = 'X'.
APPEND s_receivers TO t_receivers.
Subject
document_data-obj_descr = 'New mail from Sap'.
Body
s_content = 'Hi,'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Test email from sap, please don''t reply to this email'.
APPEND s_content TO t_content.
CLEAR: s_content.
APPEND s_content TO t_content.
s_content = 'Thanks,'.
APPEND s_content TO t_content.
s_content = 'Naren.'.
APPEND s_content TO t_content.
Send the email.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
TABLES
object_content = t_content
receivers = t_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 e208(00) WITH 'Error in sending email :-(('.
ELSE.
MESSAGE s208(00) WITH 'Email sent )'.
ENDIF.
wait up to 2 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
with output = 'X'
AND RETURN.
Murali.c
‎2009 Aug 05 7:50 AM
Hi,
Please make one addition to FM and then try if it works
Send the email.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
commit_work = 'X'
TABLES
object_content = t_content
receivers = t_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 e208(00) WITH 'Error in sending email :-(('.
ELSE.
MESSAGE s208(00) WITH 'Email sent )'.
ENDIF.
‎2009 Aug 05 5:25 AM
Hi,
Use this following code
REPORT Ztest_MAIL.
Data Declaration
DATA: DOCDATA LIKE SODOCCHGI1,
OBJPACK LIKE SOPCKLSTI1 OCCURS 1 WITH HEADER LINE,
OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE,
OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
OBJHEX LIKE SOLIX OCCURS 10 WITH HEADER LINE,
RECLIST LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE.
DATA: TAB_LINES TYPE I,
DOC_SIZE TYPE I,
ATT_TYPE LIKE SOODK-OBJTP.
DATA: LISTOBJECT LIKE ABAPLIST OCCURS 1 WITH HEADER LINE.
OBJBIN = ' | '. APPEND OBJBIN.
OBJPACK-HEAD_START = 1.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJPACK-HEAD_START = 1.
NOTE: Create ALI/OTF Document in Spool
ALI Document can be created by displaying a list and selecting
menue System -> List -> Print (only put to Spool).
OTF Document can be created running report SF_EXAMPLE_01 in
*SYSTEM.
Example used here:
create list in memory
DATA: TAB TYPE TABLE OF SOLISTI1 WITH HEADER LINE.
TAB-LINE = 'data''.
APPEND TAB.
TAB-LINE = 'data''.
APPEND TAB.
EXPORT TAB TO MEMORY ID 'HC'.
SUBMIT ZHC_WRITE EXPORTING LIST TO MEMORY AND RETURN.
and read list from memory into table
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = LISTOBJECT
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
*PACKING_LIST = OBJPACK.
Because listobject is of size RAW(1000)
and objbin is of size CHAR(255) we make this table copy
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
COMPRESSED_SIZE =
TABLES
IN = LISTOBJECT
OUT = OBJBIN
EXCEPTIONS
OTHERS = 1 .
IF SY-SUBRC <> 0.
MESSAGE ID '61' TYPE 'E' NUMBER '731' WITH 'TABLE_COMPRESS'.
ENDIF.
*ELSE.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
*'recipients!'.
Create Message Body
Title and Description
DOCDATA-OBJ_NAME = 'TEST_ALI'.
DOCDATA-OBJ_DESCR = 'Test including ALI/HTML Attachment'.
Main Text
OBJTXT = 'Test Document.'.
APPEND OBJTXT.
OBJTXT = 'You will find an ALI/HTML attachment in this message.'.
APPEND OBJTXT.
OBJTXT = 'Have a nice day.'.
APPEND OBJTXT.
Write Packing List (Main)
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOCDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
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.
Create Message Attachment
Write Packing List (Attachment)
ATT_TYPE = 'ALI'.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
READ TABLE OBJBIN INDEX TAB_LINES.
OBJPACK-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJBIN ).
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = ATT_TYPE.
OBJPACK-OBJ_NAME = 'ATTACHMENT'.
OBJPACK-OBJ_DESCR = 'Attached Document'.
APPEND OBJPACK.
Create receiver list
RECLIST-RECEIVER = "<-- email address
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOCDATA
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X' "used from rel.6.10
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
CONTENTS_HEX = objhex
OBJECT_PARA =
OBJECT_PARB =
RECEIVERS = RECLIST
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 'SO' TYPE 'S' NUMBER '023' WITH DOCDATA-OBJ_NAME.
ENDIF.
*
*WAIT UP TO 2 SECONDS.
*SUBMIT RSCONN01 WITH MODE = 'INT'
WITH OUTPUT = 'X'
AND RETURN.
WRITE: / 'End of Program'.
Hope if helps.
Regards
Hiren K.Chitalia
‎2009 Aug 05 5:54 AM
Hi,
Can you check the status of the mail in SOST Tcode ,
Regards,
Dwaraka.
‎2009 Aug 05 6:08 AM
hi,
No messages are existing in SOST.and the submit program is throwing a message 'No Messages sent'.
murali
‎2009 Aug 05 6:12 AM
Hi,
Have you checked the program that i have given.
Regards
Hiren K.Chitalia
‎2009 Aug 05 6:22 AM
HI hiren,
My requirement is to just a send a mail with out attachment.
murali
‎2009 Aug 05 6:58 AM
Hi Murali,
Try this way.
<li>Continued--> REPORT zvenkat_mail_simple.
"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.
"Subject of the mail.
w_document_data-obj_name = 'MAIL_TO_HEAD'.
w_document_data-obj_descr = 'Simple mail using SAP ABAP'.
"Body of the mail
w_body_msg = 'Hi,'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
w_body_msg = 'This is body of the mail.'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
"Write Packing List (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.
"Fill the document data and get size of attachment
READ TABLE i_body_msg INTO w_body_msg INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_body_msg ).
"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.
‎2009 Aug 05 6:58 AM
<li> From above-->
Thanks
Venkat.O "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_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.
SUBMIT rsconn01 WITH mode = 'INT' WITH output = 'X' AND RETURN.
ENDIF.
‎2009 Aug 05 7:50 AM
Hi,
Please make one addition to FM and then try if it works
Send the email.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
commit_work = 'X'
TABLES
object_content = t_content
receivers = t_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 e208(00) WITH 'Error in sending email :-(('.
ELSE.
MESSAGE s208(00) WITH 'Email sent )'.
ENDIF.