08-02-2007 1:23 PM
Hi Experts,
Is there any function module to send a mail from the ABAP program.
My requirement is to run a report and send the content of the an Internal table as mail.
Thanks in Advance
08-02-2007 1:28 PM
Hi,
u can use the following FM's
1) <b>SO_NEW_DOCUMENT_ATT_SEND_API1</b>(Send new document with attachments)
2) <b>SO_NEW_DOCUMENT_SEND_API1</b>(Send new document with out attachment)
This is a small program which is used for sending mail.
data : maildata type SODOCCHGI1.
data : mailtxt type table of SOLISTI1 with header line.
data : mailrec type table of SOMLRECI1 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 mail'.
append mailtxt.
mailrec-receiver = 'mailid@gmail.com'.
mailrec-rec_type = 'U'.
append mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = maildata
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = ' '
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
OBJECT_HEADER = mailtxt
OBJECT_CONTENT = mailtxt
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
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,
Padmam.
08-02-2007 1:26 PM
hi ,
Check this FM,
'SO_NEW_DOCUMENT_ATT_SEND_API1'
check even these :
sap_new_document_send_api1(send document)
sap_new_document_att_send_api1(send with attachments) .
Hope these solve your problem !
Regards,
Ranjita
08-02-2007 1:26 PM
hI,
Here is the example program
&----
*& Report ZSENDEMAIL *
*& *
&----
*& Example of sending external email via SAPCONNECT *
*& *
&----
REPORT zsendemail .
PARAMETERS: psubject(40) type c default 'Hello',
p_email(40) type c default 'test@sapdev.co.uk' .
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_PROGRAM
Regards
08-02-2007 1:29 PM
Hi Kiran/Ranjitha
Thanks for ur quick response...!!!
Is there any configurations are to be made in order to send mail....
08-02-2007 1:33 PM
Yes, you need to do the correct settings in transaction SCOT.
The documentation for sapconnect can be found here : http://help.sap.com/saphelp_erp2005/helpdata/EN/2b/d926324b8a11d1894c0000e8323c4f/frameset.htm
Aditionally you also need to schedule the actual sending of the mails, more info here : http://help.sap.com/saphelp_erp2005/helpdata/EN/2b/d926324b8a11d1894c0000e8323c4f/frameset.htm
08-02-2007 1:28 PM
Hi,
u can use the following FM's
1) <b>SO_NEW_DOCUMENT_ATT_SEND_API1</b>(Send new document with attachments)
2) <b>SO_NEW_DOCUMENT_SEND_API1</b>(Send new document with out attachment)
This is a small program which is used for sending mail.
data : maildata type SODOCCHGI1.
data : mailtxt type table of SOLISTI1 with header line.
data : mailrec type table of SOMLRECI1 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 mail'.
append mailtxt.
mailrec-receiver = 'mailid@gmail.com'.
mailrec-rec_type = 'U'.
append mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = maildata
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = ' '
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
OBJECT_HEADER = mailtxt
OBJECT_CONTENT = mailtxt
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
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,
Padmam.
08-03-2007 8:29 AM
Hi Padmam,
Thanks for ur code.. It is working perfect...
Kiran: Thanks to u... ur code too did the job.
I am closing this thread.....
02-24-2020 3:17 PM
Hi guys,
this doesn't work for me.
Shouldnt it send me an email if i replace "mailrec-receiver = 'mailid@gmail.com'". with "mailrec-receiver = 'myemail@gmail.com'".
Thanks in advance
08-02-2007 1:31 PM
Hi,
If you look at the Kiran respone, there in the Code there is a Submit statment,
<b>submit rsconn01 with mode = 'INT'</b>
If you use the Submit statment, then there is no need for any configuration, if you are not using this then you need to do the configuration from SCOT transaction code
Regards
Sudheer