‎2007 Sep 12 1:13 PM
Hi,
I have found an example code for sending E-Mails to an external address and tried it out. It worked perfectly, I received the E-Mail in my inbox... the second and the following times I run the programm, it wouldn't send the E-Mail anymore.
Meaning the programm only send the E-Mail on the first attempt.. what could be the reason for that?
*&---------------------------------------------------------------------*
*& Report ZSENDEMAIL *
*& *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT *
*& *
*&---------------------------------------------------------------------*
REPORT z_tl78_121007_email.
PARAMETERS: psubject(40) TYPE c DEFAULT 'Hello',
p_email(40) TYPE c DEFAULT 'abc@test.com'.
DATA: it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
it_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
gd_cnt TYPE i,
gd_sent_all(1) TYPE c,
gd_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
PERFORM populate_message_table.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
PERFORM send_email_message.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*&---------------------------------------------------------------------*
*& Form POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
* Adds text to email text table
*----------------------------------------------------------------------*
FORM populate_message_table.
APPEND 'Email line 1' TO it_message.
APPEND 'Email line 2' TO it_message.
APPEND 'Email line 3' TO it_message.
APPEND 'Email line 4' TO it_message.
ENDFORM. " POPULATE_MESSAGE_TABLE
*&---------------------------------------------------------------------*
*& Form SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
* Send email message
*----------------------------------------------------------------------*
FORM send_email_message.
* Fill the document data.
gd_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
* Describe the body of the message
CLEAR it_packing_list.
REFRESH it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
APPEND it_packing_list.
* Add the recipients email address
CLEAR it_receivers.
REFRESH it_receivers.
it_receivers-receiver = p_email.
it_receivers-rec_type = 'U'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
APPEND it_receivers.
* Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
IMPORTING
sent_to_all = gd_sent_all
TABLES
packing_list = it_packing_list
contents_txt = it_message
receivers = it_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.
* Store function module return code
gd_error = sy-subrc.
* Get it_receivers return code
LOOP AT it_receivers.
ENDLOOP.
ENDFORM. " SEND_EMAIL_MESSAGE
*&---------------------------------------------------------------------*
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
* Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
FORM initiate_mail_execute_program.
WAIT UP TO 2 SECONDS.
IF gd_error EQ 0.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAMAnyone got a clue, or any suggestions .. another way of sending E-Mails to an external E-Mail?
Message was edited by:
Yilmaz Akarsu
‎2007 Sep 12 1:21 PM
Add the commit_work parameter to the function call ie
* Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
............
............
Arya
‎2007 Sep 12 1:21 PM
Add the commit_work parameter to the function call ie
* Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
............
............
Arya
‎2007 Sep 12 1:31 PM
Hi
Thanks for your quick response, I must have missed that one.. thanks again.
I've got another question, I am looking for something like a distributer-list, is it possible to send out an e-mail to several receivers ( I guess so ).
I've already checked the forums and found some answers but those wouldn't help me.
On a side not, I'm kinda very new to the whole ABAP world, sorry for that.
‎2007 Sep 18 10:40 AM
Hi
I've got another question, after solving the ones above.
Is it somehow possible to add a 'reply to' email addy or hide my email, since I dont want any replies to this automaticly generated message.
‎2007 Sep 12 1:23 PM
hi akarsu
again u use the function module to connect
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'