Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9159

Re: How do I send e-mail from ABAP Web Dynpro Application

$
0
0

This is what I have so far. I get the message "e-mail sent successfully" but the minute i go back to application code, I get the message visible on the screenshot attatched:

 

*&---------------------------------------------------------------------*

*& Report  Z_TEST_AREA

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

 

REPORT  z_test_area_hubert.

 

**Prepare Mail Object

DATALO_SEND_REQUEST TYPE REF TO CL_BCS VALUE IS INITIAL.

*CLASS CL_BCS DEFINITION LOAD.

DATA: LO_DOCUMENT TYPE REF TO CL_DOCUMENT_BCS VALUE IS INITIAL. "document object

DATA : I_TEXT TYPE BCSY_TEXT. "Table for body

DATA : W_TEXT LIKE LINE OF I_TEXT. "work area for message body

DATA: LO_SENDER TYPE REF TO IF_SENDER_BCS VALUE IS INITIAL. "sender

DATA: LO_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS VALUE IS INITIAL. "recipient

***Selection screen

PARAMETERS : P_EMAIL TYPE ADR6-SMTP_ADDR. "Emai input

PARAMETERS: P_SUB TYPE CHAR50. "email subject

PARAMETERS : P_SEND AS CHECKBOX. "send immediatly flag

**

START-OF-SELECTION.

   LO_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

** Message body and subject

**Set body

   W_TEXT-LINE = 'This is the first tutorial of sending email using SAP ABAP programming by SAPNuts.com'.

   APPEND W_TEXT TO I_TEXT.

   CLEAR W_TEXT.

   W_TEXT-LINE = 'SAPNuts.com is the best SAP ABAP learning portal'.

   APPEND W_TEXT TO I_TEXT.

   CLEAR W_TEXT.

   LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT( "create document

   I_TYPE = 'TXT' "Type of document HTM, TXT etc

   I_TEXT I_TEXT "email body internal table

   I_SUBJECT = P_SUB ). "email subject here p_sub input parameter

   Pass the document to send request

    LO_SEND_REQUEST->SET_DOCUMENT( LO_DOCUMENT ).

 

 

   TRY.

       LO_SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ). "sender is the logged in user

** Set sender to send request

       LO_SEND_REQUEST->SET_SENDER(

       EXPORTING

       I_SENDER = LO_SENDER ).

     CATCH CX_ADDRESS_BCS.

*****Catch exception here

   ENDTRY.

***Set recipient

   LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( P_EMAIL ). "Here Recipient is email input p_email

   TRY.

       LO_SEND_REQUEST->ADD_RECIPIENT(

           EXPORTING

           I_RECIPIENT = LO_RECIPIENT

           I_EXPRESS = 'X' ).

     CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .

*Catch exception here

   ENDTRY.

 

   TRY.

       CALL METHOD LO_SEND_REQUEST->SET_SEND_IMMEDIATELY

         EXPORTING

           I_SEND_IMMEDIATELY = P_SEND. "here selection screen input p_send

     CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .

***Catch exception here

   ENDTRY.

   TRY.

*** Send email

       LO_SEND_REQUEST->SEND(

       EXPORTING

       I_WITH_ERROR_SCREEN = 'X' ).

       COMMIT WORK.

       IF SY-SUBRC = 0. "mail sent successfully

         WRITE :/ 'Mail sent successfully'.

       ENDIF.

*    CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .

**catch exception here

  ENDTRY.


This is program input parameters screen (given e-mail address is my valid sap e-mail address):

Capture.PNG

 

When I press execute i get this screen, as expected:

 

Capture1.PNG

 

Then when I go back to the code (F3):

Capture2.PNG

Then I press Inbox button:

 

Capture3.PNG

This is whats being left in the inbox ^ ^ ^

 

When i view that message I see this:

 

Capture4.PNG

 

Scenario is the same for all different VALID emails i have tried, none of them would work.

 

Any suggestions please and thank you?


Viewing all articles
Browse latest Browse all 9159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>