‎2007 Mar 08 5:43 PM
Hi All,
I have a requirement to send just a basic email in SAP. I am using the following code but for some reason it is not working. It says that I don't have an recipient address even though a correctly formatted address is in LT_ADSMTP-E_MAIL.
Can anyone help me please?
Thank you.
INCLUDE <CNTN01>.
DATA: MESSAGE TYPE SWC_OBJECT.
DATA: RECIPIENT TYPE SWC_OBJECT.
DATA: CONTENT LIKE SOLI-LINE OCCURS 0 WITH HEADER LINE.
SWC_CONTAINER CONTAINER.
SWC_CREATE_OBJECT RECIPIENT 'RECIPIENT' SPACE.
SWC_CLEAR_CONTAINER CONTAINER.
SWC_SET_ELEMENT CONTAINER 'AddressString' LT_ADSMTP-E_MAIL.
SWC_SET_ELEMENT CONTAINER 'TypeId' 'B'.
SWC_CALL_METHOD RECIPIENT 'CreateAddress' CONTAINER.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO.
ENDIF.
SWC_CLEAR_CONTAINER CONTAINER.
SWC_SET_ELEMENT CONTAINER 'SendExpress' 'X'.
SWC_CALL_METHOD RECIPIENT 'SetExpress' CONTAINER.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SWC_CREATE_OBJECT MESSAGE 'MESSAGE' SPACE.
SWC_CLEAR_CONTAINER CONTAINER.
SWC_SET_ELEMENT CONTAINER 'Document Title'(001).
SWC_SET_ELEMENT CONTAINER 'Document Name'(002).
SWC_SET_ELEMENT CONTAINER 'DOCUMENTTYPE' 'RAW'.
SWC_SET_ELEMENT CONTAINER 'NO_DIALOG' 'X'.
CONTENT = 'First Line of content'(003).
APPEND CONTENT.
CONTENT = 'Second line of content'(004).
APPEND CONTENT.
SWC_SET_TABLE CONTAINER 'DocumentContent' CONTENT.
SWC_CALL_METHOD MESSAGE 'Create' CONTAINER.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SWC_CLEAR_CONTAINER CONTAINER.
SWC_SET_ELEMENT CONTAINER 'NewRecipient' RECIPIENT.
SWC_CALL_METHOD MESSAGE 'AddCopyOfRecipient' CONTAINER.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SWC_CLEAR_CONTAINER CONTAINER.
SWC_SET_ELEMENT CONTAINER 'OutboxFlag' 'X'.
SWC_CALL_METHOD MESSAGE 'SetOutboxFlag' CONTAINER.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SWC_CLEAR_CONTAINER CONTAINER.
SWC_CALL_METHOD MESSAGE 'Submit' CONTAINER.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
commit work.
SWC_FREE_OBJECT MESSAGE.
SWC_FREE_OBJECT RECIPIENT.
‎2007 Mar 08 6:02 PM
Never tried it quite that way, but here is some coding that works to send a simple mail.
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.
mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type = 'U'.
append mailrec.
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.
* Force the send process by uncommenting the next line
* submit rsconn01 with mode = 'INT' and return.
Regards,
RIch Heilman
‎2007 Mar 08 6:02 PM
Never tried it quite that way, but here is some coding that works to send a simple mail.
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.
mailrec-receiver = 'you@yourcompany.com'.
mailrec-rec_type = 'U'.
append mailrec.
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.
* Force the send process by uncommenting the next line
* submit rsconn01 with mode = 'INT' and return.
Regards,
RIch Heilman
‎2007 Mar 09 10:35 AM
Brilliant as always Rich, thanks! One thing though, when I look in the SOST queue, the send date is set as 00.00.000 is there anyway of sorting this?
‎2007 Mar 09 12:13 PM
Hi
Set the date field to sy-datum wherever it appears in the tables before using the SO_API_NEW_DOCUMENT function call.
Regards
- Atul
‎2007 Mar 09 12:23 PM
The only date field in the MAILDATA table is OBJ_EXPDAT which is the Expiration date of object so I don't think thats what I'm after.
Thanks anyway