Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

sending email to external address in abap getting error when sending

Former Member
0 Kudos

see attached code.. when using :

set property of outmail 'SenderEmailAddress'.....

Call Method of outlmail 'SEND''

sy-subrc = '3' please help..

CALL METHOD OF OUTMAIL 'ATTACHMENTS' = ATTS.

CALL METHOD OF ATTS 'ADD'

EXPORTING #1 = sav_email-pfile1 .

move sav_email-smtp_addr to eaddress.

MOVE 'abcefg' ' TO EADDRESS2.

SET PROPERTY OF OUTMAIL 'SUBJECT' = sy-title.

SET PROPERTY OF OUTMAIL 'BODY' = g_body.

SET PROPERTY OF OUTMAIL 'TO' = eaddress.

SET PROPERTY OF OUTMAIL 'SenderEmailAddress' = EADDRESS2.

CALL METHOD OF OUTMAIL 'SEND'.

.....

thanx, Keith

ps: each set property has sy-subrc = 0 !!

14 REPLIES 14

former_member189779
Active Contributor
0 Kudos

Hi,

Check if this is something to do with Authorizations....just a suggestion..!!

Regards

Vinit

Former Member
0 Kudos

Hi,

Check whether the EADDRESS field have a valid email address in the format.

Former Member
0 Kudos

ideally.. i'd like to change the 'From' email address .. but i don't think this is a Set Property of...

if i add 'set property of outmail 'CC' = abcd this workes..

but 'SenderEnmailAddress' doesn't..

when i added 'get property of outmail 'SenderEnmailAddress' ...

i got the same error !!

where would i check for authorizations for this Property 'SenderEnmailAddress' !!

0 Kudos

Hi,

Try changing the email address in your user master.

If it works, then try using the BAPI "BAPI_USER_CHANGE" to change the user master email inside the program.

First get the current user master email id and save it in a varible.

Now just before the 'SenderEnmailAddress' , change the user master email id to the desired one.

Now set the 'SenderEnmailAddress' and send the email.

Again use the BAPI to change the user master email id to the previous one which was stored in the variable.

Don't forget to use the commit statement after BAPI and if needed also use the WAIT command for saving the changes to DB level..

Former Member
0 Kudos

changed to eaddress.. same results..

0 Kudos

Hi,

Why can't you use the FM SO_DOCUMENT_SEND_API1 to send mail. Its simple and you can also add attachments.

Regards,

Aravind.

Former Member
0 Kudos

thanx Aravind.. question.. can i send Multiple ( upto 15 files) and types: like PDF or CSV greater than 255 bytes !! and can i change the 'FROM' emailaddress to a generic one..

if it handles these conditions,, then i will give it a try..

0 Kudos

Aravind has recommended old technology that should no longer be used. Class BCS does email and if you look at the example programs, you'll see that BCS_TEST01 and BCS_TEST10 both deal with sender name. However, I don't know if it will let you set something other than your userid. BCS_TEST01 uses sendername as a parameter, so perhaps it can, in fact, override your userid with the userid entered on screen.

Do you have a userid in your instance that has the return email that you want? In one case, I had the client set batch_user username to the desired value, since the emails were being sent from backkground jobs.

Former Member
0 Kudos

the BCS_* processes send the email to SAP internally.. I need it sent an external email address..

0 Kudos

I don't know how you got internal only...I send to outlook using an internet email address with BCS... just look at BCS_EXAMPLE_6. But, have to say...lots of folks still apparently love those antique APIs.

0 Kudos

Keith,

it is true: You can do everything using CL_BCS.

And it is easy.

Regards,

Clemens

Former Member
0 Kudos

i don't have bcs_example_06 !! only up to bcs_example_05

0 Kudos

Did you test if your SAP even sends emails to external addresses (through tcode SO00)? If not you have to check the network/systems administrator to open the port for the IP address you maintained in SCOT, SMTP node.

Former Member
0 Kudos

Hi Keith,

Try this simple code...

mailto is the 'email address'....



try.

*     -------- create persistent send request ------------------------
      send_request = cl_bcs=>create_persistent( ).

*     -------- create and set document with attachment ---------------
*     create document object from internal table with text
      append 'Hello world!' to main_text.                   "#EC NOTEXT
      document = cl_document_bcs=>create_document(
        i_type    = 'RAW'
        i_text    = main_text
        i_subject = 'Test Created By BCS_EXAMPLE_7' ).      "#EC NOTEXT

*     add the spread sheet as attachment to document object
      document->add_attachment(
        i_attachment_type    = 'xls'                        "#EC NOTEXT
        i_attachment_subject = 'ExampleSpreadSheet'         "#EC NOTEXT
        i_attachment_size    = size
        i_att_content_hex    = binary_content ).

*     add document object to send request
      send_request->set_document( document ).

*     --------- add recipient (e-mail address) -----------------------
*     create recipient object
      recipient = cl_cam_address_bcs=>create_internet_address( mailto ).

*     add recipient object to send request
      send_request->add_recipient( recipient ).

*     ---------- send document ---------------------------------------
      sent_to_all = send_request->send( i_with_error_screen = 'X' ).

      commit work.

      if sent_to_all is initial.
        message i500(sbcoms) with mailto.
      else.
        message s022(so).
      endif.

*   ------------ exception handling ----------------------------------
*   replace this rudimentary exception handling with your own one !!!
    catch cx_bcs into bcs_exception.
      message i865(so) with bcs_exception->error_type.
  endtry.

Regards

Raj

Edited by: Rajasekhar Dinavahi on Feb 28, 2012 11:31 AM