REPORT z_test_email.
DATA:
subject TYPE so_obj_des,
it_body_text TYPE soli_tab,
it_body_html TYPE soli_tab,
from TYPE ad_smtpadr,
to TYPE ad_smtpadr.
DATA:
document TYPE REF TO cl_document_bcs,
request TYPE REF TO cl_bcs,
mime_helper TYPE REF TO cl_gbt_multirelated_service,
sender TYPE REF TO if_sender_bcs,
recipient TYPE REF TO if_recipient_bcs.
to = 'receiver@gmail.com'.
from = 'sendor@gmail.com'.
subject = 'Test Email Data'.
APPEND 'Hello World' TO it_body_text.
APPEND 'Column 1 Column 2' TO it_body_text.
APPEND 'a b' TO it_body_text.
APPEND 'xyz test' TO it_body_text.
APPEND '4711 0815' TO it_body_text.
APPEND '<html>' TO it_body_html.
APPEND '<head>' TO it_body_html.
APPEND '<title>MY HTML part</title>' TO it_body_html.
APPEND '</head>' TO it_body_html.
APPEND '<body>' TO it_body_html.
APPEND '<h1>Hello World!</h1>' TO it_body_html.
APPEND '<table border="1">' TO it_body_html.
APPEND '<tr><td>Column 1</td><td>Column 2</td></tr>' TO it_body_html.
APPEND '<tr><td>a</td><td>b</td></tr>' TO it_body_html.
APPEND '<tr><td>xyz</td><td>test</td></tr>' TO it_body_html.
APPEND '<tr><td>4711</td><td>0815</td></tr>' TO it_body_html.
APPEND '</table>' TO it_body_html.
APPEND '</body>' TO it_body_html.
APPEND '</html>' TO it_body_html.
CREATE OBJECT mime_helper.
mime_helper->set_main_text( content = it_body_text ).
mime_helper->set_main_html( content = it_body_html ).
document = cl_document_bcs=>create_from_multirelated(
i_subject = subject
i_multirel_service = mime_helper ).
request = cl_bcs=>create_persistent( ).
request->set_document( document ).
IF from IS NOT INITIAL.
sender = cl_cam_address_bcs=>create_internet_address( from ).
ELSE.
sender = cl_sapuser_bcs=>create( sy-uname ).
ENDIF.
request->set_sender( sender ).
recipient = cl_cam_address_bcs=>create_internet_address( to ).
request->add_recipient( EXPORTING i_recipient = recipient ).
request->set_send_immediately( 'X' ).
IF request->send( i_with_error_screen = 'X' ) = 'X'.
WRITE:/ 'Email sent succesfully'.
ELSE.
WRITE:/ ' Error sending email'.
ENDIF.
COMMIT WORK.
DATA:
subject TYPE so_obj_des,
it_body_text TYPE soli_tab,
it_body_html TYPE soli_tab,
from TYPE ad_smtpadr,
to TYPE ad_smtpadr.
DATA:
document TYPE REF TO cl_document_bcs,
request TYPE REF TO cl_bcs,
mime_helper TYPE REF TO cl_gbt_multirelated_service,
sender TYPE REF TO if_sender_bcs,
recipient TYPE REF TO if_recipient_bcs.
to = 'receiver@gmail.com'.
from = 'sendor@gmail.com'.
subject = 'Test Email Data'.
APPEND 'Hello World' TO it_body_text.
APPEND 'Column 1 Column 2' TO it_body_text.
APPEND 'a b' TO it_body_text.
APPEND 'xyz test' TO it_body_text.
APPEND '4711 0815' TO it_body_text.
APPEND '<html>' TO it_body_html.
APPEND '<head>' TO it_body_html.
APPEND '<title>MY HTML part</title>' TO it_body_html.
APPEND '</head>' TO it_body_html.
APPEND '<body>' TO it_body_html.
APPEND '<h1>Hello World!</h1>' TO it_body_html.
APPEND '<table border="1">' TO it_body_html.
APPEND '<tr><td>Column 1</td><td>Column 2</td></tr>' TO it_body_html.
APPEND '<tr><td>a</td><td>b</td></tr>' TO it_body_html.
APPEND '<tr><td>xyz</td><td>test</td></tr>' TO it_body_html.
APPEND '<tr><td>4711</td><td>0815</td></tr>' TO it_body_html.
APPEND '</table>' TO it_body_html.
APPEND '</body>' TO it_body_html.
APPEND '</html>' TO it_body_html.
CREATE OBJECT mime_helper.
mime_helper->set_main_text( content = it_body_text ).
mime_helper->set_main_html( content = it_body_html ).
document = cl_document_bcs=>create_from_multirelated(
i_subject = subject
i_multirel_service = mime_helper ).
request = cl_bcs=>create_persistent( ).
request->set_document( document ).
IF from IS NOT INITIAL.
sender = cl_cam_address_bcs=>create_internet_address( from ).
ELSE.
sender = cl_sapuser_bcs=>create( sy-uname ).
ENDIF.
request->set_sender( sender ).
recipient = cl_cam_address_bcs=>create_internet_address( to ).
request->add_recipient( EXPORTING i_recipient = recipient ).
request->set_send_immediately( 'X' ).
IF request->send( i_with_error_screen = 'X' ) = 'X'.
WRITE:/ 'Email sent succesfully'.
ELSE.
WRITE:/ ' Error sending email'.
ENDIF.
COMMIT WORK.
감사합니다.