<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sending Mail in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014039#M411422</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly go through this coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT YMS_EXTERNALMAIL   .&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp; Report  ZSENDEMAIL                                                  *&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp; Example of sending external email via SAPCONNECT                    *&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS: psubject(40) type c default  'Hello',&lt;/P&gt;&lt;P&gt;            p_email(40)   type c default 'test@sapdev.co.uk' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:   it_packing_list like sopcklsti1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        it_contents like solisti1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        it_receivers like somlreci1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        it_attachment like solisti1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        gd_cnt type i,&lt;/P&gt;&lt;P&gt;        gd_sent_all(1) type c,&lt;/P&gt;&lt;P&gt;        gd_doc_data like sodocchgi1,&lt;/P&gt;&lt;P&gt;        gd_error type sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:   it_message type standard table of SOLISTI1 initial size 0&lt;/P&gt;&lt;P&gt;                with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;***********************************************************************&lt;/P&gt;&lt;P&gt;*START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perform populate_message_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Send email message, although is not sent from SAP until mail send&lt;/P&gt;&lt;P&gt;*program has been executed(rsconn01)&lt;/P&gt;&lt;P&gt;PERFORM send_email_message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Instructs mail send program for SAPCONNECT to send email(rsconn01)&lt;/P&gt;&lt;P&gt;perform initiate_mail_execute_program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  POPULATE_MESSAGE_TABLE&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Adds text to email text table&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form populate_message_table.&lt;/P&gt;&lt;P&gt;  Append 'Email line 1' to it_message.&lt;/P&gt;&lt;P&gt;  Append 'Email line 2' to it_message.&lt;/P&gt;&lt;P&gt;  Append 'Email line 3' to it_message.&lt;/P&gt;&lt;P&gt;  Append 'Email line 4' to it_message.&lt;/P&gt;&lt;P&gt;endform.                    " POPULATE_MESSAGE_TABLE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  SEND_EMAIL_MESSAGE&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Send email message&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form send_email_message.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Fill the document data.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_doc_data-doc_size = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Populate the subject/generic message attributes&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_doc_data-obj_langu = sy-langu.&lt;/P&gt;&lt;P&gt;  gd_doc_data-obj_name  = 'SAPRPT'.&lt;/P&gt;&lt;P&gt;  gd_doc_data-obj_descr = psubject.&lt;/P&gt;&lt;P&gt;  gd_doc_data-sensitivty = 'F'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Describe the body of the message&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  clear it_packing_list.&lt;/P&gt;&lt;P&gt;  refresh it_packing_list.&lt;/P&gt;&lt;P&gt;  it_packing_list-transf_bin = space.&lt;/P&gt;&lt;P&gt;  it_packing_list-head_start = 1.&lt;/P&gt;&lt;P&gt;  it_packing_list-head_num = 0.&lt;/P&gt;&lt;P&gt;  it_packing_list-body_start = 1.&lt;/P&gt;&lt;P&gt;  describe table it_message lines it_packing_list-body_num.&lt;/P&gt;&lt;P&gt;  it_packing_list-doc_type = 'RAW'.&lt;/P&gt;&lt;P&gt;  append it_packing_list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Add the recipients email address&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  clear it_receivers.&lt;/P&gt;&lt;P&gt;  refresh it_receivers.&lt;/P&gt;&lt;P&gt;  it_receivers-receiver = p_email.&lt;/P&gt;&lt;P&gt;  it_receivers-rec_type = 'U'.&lt;/P&gt;&lt;P&gt;  it_receivers-com_type = 'INT'.&lt;/P&gt;&lt;P&gt;  it_receivers-notif_del = 'X'.&lt;/P&gt;&lt;P&gt;  it_receivers-notif_ndel = 'X'.&lt;/P&gt;&lt;P&gt;  append it_receivers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Call the FM to post the message to SAPMAIL&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'&lt;/P&gt;&lt;P&gt;       exporting&lt;/P&gt;&lt;P&gt;            document_data              = gd_doc_data&lt;/P&gt;&lt;P&gt;            put_in_outbox              = 'X'&lt;/P&gt;&lt;P&gt;       importing&lt;/P&gt;&lt;P&gt;            sent_to_all                = gd_sent_all&lt;/P&gt;&lt;P&gt;       tables&lt;/P&gt;&lt;P&gt;            packing_list               = it_packing_list&lt;/P&gt;&lt;P&gt;            contents_txt               = it_message&lt;/P&gt;&lt;P&gt;            receivers                  = it_receivers&lt;/P&gt;&lt;P&gt;       exceptions&lt;/P&gt;&lt;P&gt;            too_many_receivers         = 1&lt;/P&gt;&lt;P&gt;            document_not_sent          = 2&lt;/P&gt;&lt;P&gt;            document_type_not_exist    = 3&lt;/P&gt;&lt;P&gt;            operation_no_authorization = 4&lt;/P&gt;&lt;P&gt;            parameter_error            = 5&lt;/P&gt;&lt;P&gt;            x_error                    = 6&lt;/P&gt;&lt;P&gt;            enqueue_error              = 7&lt;/P&gt;&lt;P&gt;            others                     = 8.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Store function module return code&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_error = sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Get it_receivers return code&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  loop at it_receivers.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;endform.                    " SEND_EMAIL_MESSAGE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  INITIATE_MAIL_EXECUTE_PROGRAM&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Instructs mail send program for SAPCONNECT to send email.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form initiate_mail_execute_program.&lt;/P&gt;&lt;P&gt;  wait up to 2 seconds.&lt;/P&gt;&lt;P&gt;  if gd_error eq 0.&lt;/P&gt;&lt;P&gt;      submit rsconn01 with mode = 'INT'&lt;/P&gt;&lt;P&gt;                    with output = 'X'&lt;/P&gt;&lt;P&gt;                    and return.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Shankar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Mar 2007 10:54:49 GMT</pubDate>
    <dc:creator>p291102</dc:creator>
    <dc:date>2007-03-05T10:54:49Z</dc:date>
    <item>
      <title>Sending Mail</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014034#M411417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   Can any one tell me how to send a mail through program? What is the procedure for that and which FM i ve to use?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in Advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2007 10:46:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014034#M411417</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-05T10:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Mail</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014035#M411418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ravi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send the mail. The FM has a well documented help. You can go through that for details. Let me know if you require any further inputs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not forget to give the reward points if the answer helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Anurag&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2007 10:51:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014035#M411418</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-05T10:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Mail</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014036#M411419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ravi,&lt;/P&gt;&lt;P&gt;Check this report&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Example original file
12345 aa pq
Email attachment file
-&amp;gt; This line
12345 aa pq

This is my code:

REPORT ZTEST_FILE .
DATA:BEGIN OF t_upload occurs 0,
matnr LIKE zwplcsmev-matnr,
zwgehrrg LIKE zwplcsmev-zwgehrrg,
zwgehrct LIKE zwplcsmev-zwgehrct,
zwgbev LIKE zwplcsmev-zwgbev,
zwpldt LIKE zwplcsmev-zwpldt,
zwacdt LIKE zwplcsmev-zwacdt,
END OF t_upload.
*DATA: maildata type sodocchgi1.
*DATA: mailtxt type table of solisti1 with header line.
*DATA: mailrec type table of somlrec90 with header line.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA:REC(80) TYPE C.
DATA g_mask(20) TYPE c VALUE ',*.*, *.*.'.

DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA:P_ERROR(3).
DATA:P_REFO(3).
DATA: gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1.
selection-screen begin of block b1 with frame title text-001.
parameters:p_file type localfile.
parameter:p_email type ad_smtpadr.
selection-screen end of block b1.
*----------------------------------------------------------------------*
*---------------At Selection-Screen--- --------------------------------*
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'TB_LIMIT_WS_FILENAME_GET'
EXPORTING
def_filename = p_file
mask = g_mask
* mode = 'S'
title = 'INPUT FILE'
IMPORTING
filename = p_file
EXCEPTIONS
selection_cancel = 1
selection_error = 2
OTHERS = 3.
IF sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

START-OF-SELECTION.
PERFORM process_file.
if p_error = 'X' AND P_REFO &amp;lt;&amp;gt; 'X'.

PERFORM populate_message_body.
ENDIF.
IF P_REFO = 'X' AND P_ERROR &amp;lt;&amp;gt; 'X'.
it_message = 'Please find Attached file'.
APPEND it_message.

PERFORM send_attachment tables it_message
it_attach
using p_email
'Crest to Plc Data'
'TXT'
p_file
' '
' '
' '
changing gd_error
gd_reciever.
ENDIF.
* Instructs mail send program for SAPCONNECT to send email(rsconn01)
* PERFORM initiate_mail_execute_program.



END-OF-SELECTION.

*&amp;amp;--------------------------------------------------------------------*
*&amp;amp; Form process_file
*&amp;amp;--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM process_file.
*CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
* con_tab TYPE x VALUE '09'. "OK for non Unicode
DATA :l_path TYPE string.
l_path = p_file.

CONSTANTS: con_tab type c value cl_abap_char_utilities=&amp;gt;HORIZONTAL_TAB
,
con_cret type c value cl_abap_char_utilities=&amp;gt;newline.

OPEN DATASET P_FILE FOR INPUT IN TEXT MODE encoding default.
if sy-subrc = 0.
do.
read dataset p_file into IT_ATTACH.
IF SY-SUBRC NE 0 .
EXIT.
ELSE.
T_UPLOAD = IT_ATTACH.
CONCATENATE con_cret it_attach INTO it_attach .
append it_attach.
clear it_attach.

P_REFO = 'X'.
APPEND T_UPLOAD .
clear t_upload.
ENDIF.
ENDDO.
else.
p_error = 'X'.


ENDIF.

ENDFORM. "process_file
*&amp;amp;--------------------------------------------------------------------*
*&amp;amp; Form populate_message_body
*&amp;amp;--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM populate_message_body.
w_doc_data-obj_name = 'TEST'.
w_doc_data-obj_descr = 'Crest to Plc Data'.
w_doc_data-obj_langu = sy-langu.
it_message = 'File Not Found'.
APPEND it_message.
t_receivers-receiver = p_email.
t_receivers-rec_type = 'U'.
append t_receivers.

call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = w_doc_data
document_type = 'RAW'
put_in_outbox = 'X'
tables
object_header = it_message
object_content = it_message
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.
commit work.
SUBMIT rsconn01 USING SELECTION-SET 'SAP&amp;amp;CONNECTINT' AND RETURN.

else.
MESSAGE s027(vv) WITH 'E-mail not sent'.

endif.




ENDFORM. "populate_message_body
*&amp;amp;--------------------------------------------------------------------*
*&amp;amp; Form send_attachment
*&amp;amp;--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM send_attachment tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.

DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.

w_doc_data-doc_size = 1.

w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.

* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
clear t_attachment.

* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.

* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.

* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
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.
commit work.
SUBMIT rsconn01 USING SELECTION-SET 'SAP&amp;amp;CONNECTINT' AND RETURN.

else.
MESSAGE s027(vv) WITH 'E-mail not sent'.

endif.

* Populate error return code
ld_error = sy-subrc.

* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.

ENDFORM. "send_attachment

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If useful reward.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vasanth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2007 10:51:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014036#M411419</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-05T10:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Mail</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014037#M411420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please refer the links,&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sap-img.com/abap/sending-email-with-attachment.htm" target="test_blank"&gt;http://www.sap-img.com/abap/sending-email-with-attachment.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hema.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;Reward points if it is useful.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2007 10:52:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014037#M411420</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-05T10:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Mail</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014038#M411421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check out this blog: /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap&lt;DEL&gt;version-610-and-higher&lt;/DEL&gt;bcs-interface&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Tamá&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2007 10:54:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014038#M411421</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-05T10:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sending Mail</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014039#M411422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly go through this coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT YMS_EXTERNALMAIL   .&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp; Report  ZSENDEMAIL                                                  *&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp; Example of sending external email via SAPCONNECT                    *&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PARAMETERS: psubject(40) type c default  'Hello',&lt;/P&gt;&lt;P&gt;            p_email(40)   type c default 'test@sapdev.co.uk' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:   it_packing_list like sopcklsti1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        it_contents like solisti1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        it_receivers like somlreci1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        it_attachment like solisti1 occurs 0 with header line,&lt;/P&gt;&lt;P&gt;        gd_cnt type i,&lt;/P&gt;&lt;P&gt;        gd_sent_all(1) type c,&lt;/P&gt;&lt;P&gt;        gd_doc_data like sodocchgi1,&lt;/P&gt;&lt;P&gt;        gd_error type sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:   it_message type standard table of SOLISTI1 initial size 0&lt;/P&gt;&lt;P&gt;                with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;***********************************************************************&lt;/P&gt;&lt;P&gt;*START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perform populate_message_table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Send email message, although is not sent from SAP until mail send&lt;/P&gt;&lt;P&gt;*program has been executed(rsconn01)&lt;/P&gt;&lt;P&gt;PERFORM send_email_message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Instructs mail send program for SAPCONNECT to send email(rsconn01)&lt;/P&gt;&lt;P&gt;perform initiate_mail_execute_program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  POPULATE_MESSAGE_TABLE&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Adds text to email text table&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form populate_message_table.&lt;/P&gt;&lt;P&gt;  Append 'Email line 1' to it_message.&lt;/P&gt;&lt;P&gt;  Append 'Email line 2' to it_message.&lt;/P&gt;&lt;P&gt;  Append 'Email line 3' to it_message.&lt;/P&gt;&lt;P&gt;  Append 'Email line 4' to it_message.&lt;/P&gt;&lt;P&gt;endform.                    " POPULATE_MESSAGE_TABLE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  SEND_EMAIL_MESSAGE&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Send email message&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form send_email_message.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Fill the document data.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_doc_data-doc_size = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Populate the subject/generic message attributes&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_doc_data-obj_langu = sy-langu.&lt;/P&gt;&lt;P&gt;  gd_doc_data-obj_name  = 'SAPRPT'.&lt;/P&gt;&lt;P&gt;  gd_doc_data-obj_descr = psubject.&lt;/P&gt;&lt;P&gt;  gd_doc_data-sensitivty = 'F'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Describe the body of the message&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  clear it_packing_list.&lt;/P&gt;&lt;P&gt;  refresh it_packing_list.&lt;/P&gt;&lt;P&gt;  it_packing_list-transf_bin = space.&lt;/P&gt;&lt;P&gt;  it_packing_list-head_start = 1.&lt;/P&gt;&lt;P&gt;  it_packing_list-head_num = 0.&lt;/P&gt;&lt;P&gt;  it_packing_list-body_start = 1.&lt;/P&gt;&lt;P&gt;  describe table it_message lines it_packing_list-body_num.&lt;/P&gt;&lt;P&gt;  it_packing_list-doc_type = 'RAW'.&lt;/P&gt;&lt;P&gt;  append it_packing_list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Add the recipients email address&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  clear it_receivers.&lt;/P&gt;&lt;P&gt;  refresh it_receivers.&lt;/P&gt;&lt;P&gt;  it_receivers-receiver = p_email.&lt;/P&gt;&lt;P&gt;  it_receivers-rec_type = 'U'.&lt;/P&gt;&lt;P&gt;  it_receivers-com_type = 'INT'.&lt;/P&gt;&lt;P&gt;  it_receivers-notif_del = 'X'.&lt;/P&gt;&lt;P&gt;  it_receivers-notif_ndel = 'X'.&lt;/P&gt;&lt;P&gt;  append it_receivers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Call the FM to post the message to SAPMAIL&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'&lt;/P&gt;&lt;P&gt;       exporting&lt;/P&gt;&lt;P&gt;            document_data              = gd_doc_data&lt;/P&gt;&lt;P&gt;            put_in_outbox              = 'X'&lt;/P&gt;&lt;P&gt;       importing&lt;/P&gt;&lt;P&gt;            sent_to_all                = gd_sent_all&lt;/P&gt;&lt;P&gt;       tables&lt;/P&gt;&lt;P&gt;            packing_list               = it_packing_list&lt;/P&gt;&lt;P&gt;            contents_txt               = it_message&lt;/P&gt;&lt;P&gt;            receivers                  = it_receivers&lt;/P&gt;&lt;P&gt;       exceptions&lt;/P&gt;&lt;P&gt;            too_many_receivers         = 1&lt;/P&gt;&lt;P&gt;            document_not_sent          = 2&lt;/P&gt;&lt;P&gt;            document_type_not_exist    = 3&lt;/P&gt;&lt;P&gt;            operation_no_authorization = 4&lt;/P&gt;&lt;P&gt;            parameter_error            = 5&lt;/P&gt;&lt;P&gt;            x_error                    = 6&lt;/P&gt;&lt;P&gt;            enqueue_error              = 7&lt;/P&gt;&lt;P&gt;            others                     = 8.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Store function module return code&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_error = sy-subrc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Get it_receivers return code&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  loop at it_receivers.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;endform.                    " SEND_EMAIL_MESSAGE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  INITIATE_MAIL_EXECUTE_PROGRAM&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Instructs mail send program for SAPCONNECT to send email.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form initiate_mail_execute_program.&lt;/P&gt;&lt;P&gt;  wait up to 2 seconds.&lt;/P&gt;&lt;P&gt;  if gd_error eq 0.&lt;/P&gt;&lt;P&gt;      submit rsconn01 with mode = 'INT'&lt;/P&gt;&lt;P&gt;                    with output = 'X'&lt;/P&gt;&lt;P&gt;                    and return.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;endform.                    " INITIATE_MAIL_EXECUTE_PROGRAM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Shankar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2007 10:54:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sending-mail/m-p/2014039#M411422</guid>
      <dc:creator>p291102</dc:creator>
      <dc:date>2007-03-05T10:54:49Z</dc:date>
    </item>
  </channel>
</rss>

