cancel
Showing results for 
Search instead for 
Did you mean: 

Send email from WDA

Former Member
0 Kudos

Hi,

I would like to send an email from Web dynpro ABAP.

How can I proceed to do this ???

Code samples are most welcome.

Thx,

Suba

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

There is nothing particularly different about sending email from WDA. It is just normal ABAP stuff and really should be in a model or assistance class any and not in the WDA itself (good MVC design). Here is a link with details on sending email in ABAP:

[/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface|/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface]

Former Member
0 Kudos

Hi,

Thanks for ur response.

I couldnt able to create the function module successfully.

Any web dynpro code will be helpful...

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi,

> Thanks for ur response.

> I couldnt able to create the function module successfully.

> Any web dynpro code will be helpful...

There is no Web Dynpro specific coding to this. It is just normal ABAP coding. Web Dynpro is just UI - not business logic. What couldn't you create sucessfully? All the coding necessarily is available in the links that have been given.

Former Member
0 Kudos

Jung,

I created as per the blog.

But when activating i'm getting below error:

"Documents neither specified under TABLES nor defined as an internal table"

FYI, I'm using ECC.

correct me if i'm wrong

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

First of all, you wouldn't even have to recreate the function module. That was just to make the logic more reusable. The logic within the function module is what you are really after. You could just place it within the method of an assistance class and call that from WDA. However it is fine to call the function module as well. I suspect that you have not create the function module interface correctly. Notice the screen shot at the start of the section called Function Interface. That is where I declare the definition of DOCUMENTS. Based upon the error message you have, you have not created this interface parameter. Also pay special attention, that because I wanted to use this function module remotely, I needed to create my interface types in the data dictionary. Therefore I had to create Structures (there is a screen shot) and table tables (no screen shots).

Former Member
0 Kudos

Jung,

I did the same from ur blog.

But getting the same error.

Pls update the blog with hidden tables table.

It will be useful for others.

Thanks

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Jung,

> I did the same from ur blog.

> But getting the same error.

> Pls update the blog with hidden tables table.

> It will be useful for others.

>

> Thanks

I can assure you that if you have defined it as it is in the blog correct, then you would not be getting that error message. As I said before though, you don't absolutely need the function module. If you getting hung up on defining the function module interface, then consider just adapting the coding in the function module to your needs.

There is nothing hidden in the blog. Do you really need a screen shot that shows the table type? I've provided the line type already. Creating a table type from that is really basic stuff. By the same token, I don't show every single menu path to perform every operation.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi RAM,

If your problem is not solved yet then please use following code for ur reference. Its a running code for which i have used Thomas Jung's blog .

Its very easy so just understand the code step by step.

Here i am sending an internal table to a customer .



  DATA: l_text1  TYPE char255. " Text
  DATA: l_lines TYPE i,
        l_size  TYPE  sood-objlen. " Size of Attachment
  DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
  DATA lo_api_controller     TYPE REF TO if_wd_controller.
  lo_api_controller ?= wd_this->wd_get_api( ).
  lo_message_manager = lo_api_controller->get_message_manager( ).

* Mail related
  DATA: i_content TYPE   soli_tab, " Mail content
        i_attach  TYPE   soli_tab. " Attachment

  DATA: l_send_request    TYPE REF TO    cl_bcs,  " E-Mail Send Request
        l_document        TYPE REF TO    cl_document_bcs,  " E-Mail Attachment
        l_recipient       TYPE REF TO    if_recipient_bcs, " Distribution List
        l_sender          TYPE REF TO    if_sender_bcs,  " Address of Sender
        l_uname           TYPE           salrtdrcpt,  " Sender Name(SY-UNAME)
        l_bcs_exception   TYPE REF TO    cx_document_bcs, " BCS Exception
        l_addr_exception  TYPE REF TO    cx_address_bcs,  " Address Exception
        l_send_exception  TYPE REF TO    cx_send_req_bcs. " E-Mail sending Exception
*        l_SO_OBJECT_MIME_GET type ref to SO_OBJECT_MIME_GET.

  DATA: l_recipient_soos  TYPE  soos1.

  DATA: lv_i_with_error_screen TYPE os_boolean.
  DATA: lv_result TYPE os_boolean.

  CONSTANTS: c_tab(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,  " Tab Character
             c_cr(1)  TYPE c VALUE cl_abap_char_utilities=>cr_lf, " Line Feed for End-Of_line
             c_ext    TYPE soodk-objtp VALUE 'XLS'. " XLS Extension

  DATA p_uname TYPE so_dir_ext .
  p_uname = 'sumit.goenka -avaya.co.in'.

* Preparing body of the Mail
  MOVE 'Please execute the trade given in the attached excel file' TO l_text1.
  APPEND l_text1 TO i_content.
  MOVE '' TO l_text1.
  APPEND l_text1 TO i_content.
  MOVE '' TO l_text1.
  APPEND l_text1 TO i_content.
  MOVE 'Warm Regards SAP' TO  l_text1.
  APPEND l_text1 TO i_content.

* Preparing contents of attachment with Change Log

  FIELD-SYMBOLS: <lfs_table> TYPE ANY,    " Internal table structure
                 <lfs_con> TYPE ANY.      " Field Content
  DATA: l_text TYPE char1024.    " Text content for mail attachment
  DATA: l_con(50) TYPE c.        " Field Content in character format


* Columns to be tab delimeted
  LOOP AT detail ASSIGNING <lfs_table>.
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
             TO <lfs_con>.
      IF sy-subrc NE 0.
        CONCATENATE c_cr l_text INTO l_text.
        APPEND l_text TO i_attach.
        EXIT.
      ELSE.
        CLEAR: l_con.
        MOVE <lfs_con> TO l_con.
        CONDENSE l_con.
        IF sy-index = 1.
          CLEAR: l_text.
          MOVE l_con TO l_text.
        ELSE.
          CONCATENATE l_text l_con INTO l_text
             SEPARATED BY c_tab.
        ENDIF.
      ENDIF.
    ENDDO.
  ENDLOOP.


* Creates persistent send request
  TRY.
      l_send_request = cl_bcs=>create_persistent( ).

* Creating Document
      l_document = cl_document_bcs=>create_document(
                                    i_type  = 'RAW'
                                    i_text  = i_content[]
                                    i_subject = 'Buy / Sell Order' ).

      DESCRIBE TABLE detail LINES l_lines.
* Size to multiplied by 2 for UNICODE enabled systems
      l_size = l_lines * 2 * 255.

* Adding Attachment
      CALL METHOD l_document->add_attachment
        EXPORTING
          i_attachment_type    = c_ext
          i_attachment_size    = l_size
          i_attachment_subject = 'Buy Sell Order Detail'
          i_att_content_text   = i_attach[].

* Add document to send request
      CALL METHOD l_send_request->set_document( l_document ).

* Get Sender Object
      l_uname = sy-uname.

      l_sender = cl_sapuser_bcs=>create( l_uname ).

      CALL METHOD l_send_request->set_sender
        EXPORTING
          i_sender = l_sender.

* E-Mail
      TRANSLATE p_uname TO UPPER CASE.

      l_recipient_soos-recesc = 'U'.
      l_recipient_soos-recextnam = p_uname.

* Preparing recepient from SAP Logon Name
      CALL METHOD cl_send_request_bcs=>create_recipient_from_soos1
        EXPORTING
          i_soos1 = l_recipient_soos
        RECEIVING
          result  = l_recipient.

* Add Recipient
      CALL METHOD l_send_request->add_recipient
        EXPORTING
          i_recipient  = l_recipient
          i_express    = 'U'
          i_copy       = ' '
          i_blind_copy = ' '
          i_no_forward = ' '.

*Trigger E-Mail immediately
      l_send_request->set_send_immediately( 'X' ).

      CALL METHOD l_send_request->send( lv_result ).
      IF lv_result IS INITIAL.
*       *    report message
        CALL METHOD lo_message_manager->REPORT_SUCCESS
          EXPORTING
            message_text = 'Mail sent successfully '.
      ENDIF.                                                              .

      COMMIT WORK.

    CATCH cx_document_bcs INTO l_bcs_exception.

    CATCH cx_send_req_bcs INTO l_send_exception.

    CATCH cx_address_bcs  INTO l_addr_exception.

  ENDTRY.

if any doubt please ask.

regards

panky

Former Member
0 Kudos

Hi PG,

It was nice stuff given by u.

I want to receive mail into my personal email id.

When i executed ur code mail is sent to my SAP inbox.

Can you help me sending mail to personal mail id.

Thanks

Former Member
0 Kudos

Hi ram,

observe the code carefully u will find followinf sections which are responsible for sending mail.

DATA p_uname TYPE so_dir_ext .

p_uname = 'sumit.goenka -avaya.co.in'."This has to be ur email id.(i coudnt write it since wasnt allowd)

  • E-Mail

TRANSLATE p_uname TO UPPER CASE.

l_recipient_soos-recesc = 'U'. * " This has to be 'U'(it basically dicides that you want to send the mail on certain email id ) *

l_recipient_soos-recextnam = p_uname."This is yor email id

  • Preparing recepient from SAP Logon Name

CALL METHOD cl_send_request_bcs=>create_recipient_from_soos1

EXPORTING

i_soos1 = l_recipient_soos

RECEIVING

result = l_recipient.

  • Add Recipient

CALL METHOD l_send_request->add_recipient

EXPORTING

i_recipient = l_recipient

i_express = 'U'

i_copy = ' '

i_blind_copy = ' '

i_no_forward = ' '.

Try to understand these lines u will find they are only repsoncibale to send the mail.

if any doubt feel free to ask

regards

PG

Former Member
0 Kudos

Hi PG,

I tried specifying mail id. But receiving mail in workflow inbox instead of my personal email.

I dont know y?

Thanks

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi

is the SMTP server in SAP and your mail box is same, ask your basis guy to connect to the same SMTP server

Abhi

Former Member
0 Kudos

Hi Ram,

There can be only two issues that u r getting mail in sap inbox.

1) instead of U u have specified B for below value.

l_recipient_soos-RECESC

B SAP user

U Internet address

2) Yor SAP Connect setting is not done properly(as abhi suggested u ask your basis guy)

I dont find any other reason that you are not getting the mail in your email.

regards

PG

Former Member
0 Kudos

Hi ,

Are you still looking for this solution to send a mail from Webdynpro compnent.

As i have implemented some what similar kind of requirement and i can send you the code for that if you require it still.

Former Member
0 Kudos

Hi Phani,

Still i'm looking for a solution.

sending me ur code, it will be useful for me.

abhimanyu_lagishetti7
Active Contributor
0 Kudos

see Function Module SUSR_INTERNET_PASSWORD_RESET, there is form SEND_PWD_MAIL

go through the code to send Email.

or use BCS API

http://help.sap.com/saphelp_nw2004s/helpdata/en/2d/1c5d3aebba4c38e10000000a114084/frameset.htm

Abhi

Former Member
0 Kudos

Hi Suba,

You can refer the below bog.

It will help.

[https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sampleCodeforprocessingInboundMailwithAdobeInteractive+Forms]

Thanks.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi Suba,

>

> You can refer the below bog.

> It will help.

>

> [https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sampleCodeforprocessingInboundMailwithAdobeInteractive+Forms]

>

> Thanks.

Actually that link is not correct! That document talks about processing of input email and this person wants to send an email. Two completely different things.

Former Member
0 Kudos

Hi Suba,

Did you checked the application WDR_TEST_MAILTO

Thanks.