Send Email through abapprograming

hi
actualy i have a document and i want to send it to sombody inbox through email in sap-abap.
i need step by step creation of  email through abap

hi,
check this program, this program upload the file in 'BIN' binary form from presentation server into internal table and convert data in word formate and send as a mail to our inbox
Code
REPORT  ztest_upload_worddata.
PROGRAM         : ztest_upload_worddata                        *
PROGRAM TITLE   : SALES ORDER REPORT                                *
AREA            : SD                                                *
AUTHOR          :                                        *
CREATED ON      : 08/04/2008                                        *
OBJECT TYPE     : abap object Report
DESCRIPTION     :  This report describes how to send a mail in "WORD
                   DOCUMENT" by uploading file from  PRESENTATION
                   SERVER using GUI-UPLOAD.
*Tables                                                                *
TABLES: vbak.
Internal-tables                                                     *
DATA: BEGIN OF it_vbak OCCURS 0,
        vbeln TYPE vbeln,
        erdat TYPE erdat,
        ernam TYPE ernam,
       END OF it_vbak.
*DATA: it_vbak TYPE TABLE OF st_vbak WITH HEADER LINE.
     Variables                                                       *
DATA: p_filename_str TYPE string.
PARAMETERS: p_mail TYPE ad_smtpadr OBLIGATORY DEFAULT
'enter concernd email here in single cotts'
*CLASS-DEFINITIONS                                                    *
DATA: send_request       TYPE REF TO cl_bcs.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: exception_info     TYPE REF TO if_os_exception_info,
       l_uname           TYPE           salrtdrcpt,
       l_bcs_exception   TYPE REF TO    cx_document_bcs,
       l_send_exception  TYPE REF TO    cx_send_req_bcs,
       l_addr_exception  TYPE REF TO    cx_address_bcs,
      bcs_exception      TYPE REF TO cx_bcs.
INTERNAL TABLES                                                      *
DATA: l_mailtext TYPE soli_tab.
DATA: l_mailhex  TYPE solix_tab.
DATA: iaddsmtp   TYPE bapiadsmtp OCCURS 0 WITH HEADER LINE.
DATA: ireturn    TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
VARIABLES                                                            *
DATA: mail_line  LIKE LINE OF l_mailtext.
DATA: mailx_line LIKE LINE OF l_mailhex.
DATA: bapiadsmtp         TYPE bapiadsmtp.
DATA: l_lines TYPE  i.
CONSTANTS                                                            *
*CONSTANTS:
intelli_domain(20) TYPE c VALUE '@intelligroup.com'.
*CLASS cl_cam_address_bcs DEFINITION LOAD.
*CLASS cl_abap_char_utilities DEFINITION LOAD.
Constants----
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 'BMP'. " doc Extension.
CLASS cl_cam_address_bcs DEFINITION LOAD.
CLASS cl_abap_char_utilities DEFINITION LOAD.
*DATA: CONTROL_PARAMETERS TYPE SSFCTRLOP,
     OUTPUT_OPTIONS     TYPE SSFCOMPOP,
     JOB_OUTPUT_INFO    TYPE SSFCRESCL,
     JOB_OUTPUT_OPTIONS TYPE SSFCRESOP,
DATA: string_data        TYPE xstring,
       file_size          TYPE i,
       lines              TYPE TABLE OF  tline .
                  selection-screen                                *
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  PARAMETERS: p_filnam TYPE ibipparms-path.
SELECTION-SCREEN : END OF BLOCK b1.
at selection-screen on value-request                                 *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filnam.
PERFORM fareeda.
*LOOP AT it_xstring into ls_xstring.
*concatenate imp_xstring ls_xstring into imp_xstring.
*ENDLOOP.
*&      Form  f4_help_p_filnam
      text
-->  p1        text
<--  p2        text
FORM fareeda .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
   program_name        = syst-cprog
   dynpro_number       = syst-dynnr
  FIELD_NAME          = ' '
IMPORTING
   file_name           = p_filnam
ENDFORM.
                START-OF-SELECTION
START-OF-SELECTION.
  Start-of-selection                                                 *
p_filename_str = p_filnam.
data: begin of it_bin occurs 0,
      data(1028) type x,
      end of it_bin.
*data : it_xstring type table of xstring,
      ls_xstring like xstring,
data:       imp_xstring type xstring.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = p_filename_str
   filetype                      = 'BIN'
  HAS_FIELD_SEPARATOR           = 'X'
  HEADER_LENGTH                 = 0
IMPORTING
   filelength                    = l_lines
  header                        = string_data
  TABLES
    data_tab                      = it_bin
EXCEPTIONS
   file_open_error               = 1
   file_read_error               = 2
   no_batch                      = 3
   gui_refuse_filetransfer       = 4
   invalid_type                  = 5
   no_authority                  = 6
   unknown_error                 = 7
   bad_data_format               = 8
   header_not_allowed            = 9
   separator_not_allowed         = 10
   header_too_long               = 11
   unknown_dp_error              = 12
   access_denied                 = 13
   dp_out_of_memory              = 14
   disk_full                     = 15
   dp_timeout                    = 16
   OTHERS                        = 17
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length       = l_lines
  FIRST_LINE         = 0
  LAST_LINE          = 0
IMPORTING
   BUFFER             = imp_xstring
  TABLES
    binary_tab         = it_bin
EXCEPTIONS
  FAILED             = 1
  OTHERS             = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*--Using SOLIX Converting string data
  DATA: lt_solix TYPE solix_tab.
  DATA: LT_SOLI TYPE SOLI_TAB.
  DATA: docdata TYPE sood-objdes.
  DATA:  l_size  TYPE  sood-objlen.
  CALL METHOD cl_document_bcs=>xstring_to_solix
    EXPORTING
      ip_xstring = imp_xstring
    RECEIVING
      rt_solix   = lt_solix
  TRY.
*-- Create persistent send request
      send_request = cl_bcs=>create_persistent( ).
      DATA: first(1) TYPE c.
      CLEAR first.
      DATA: lt_text TYPE soli_tab.
      DATA: ls_text TYPE soli.
      ls_text-line = 'THIS IS TEST DATA'.
      APPEND ls_text TO lt_text.
      CLEAR ls_text.
      ls_text-line = 'THIS IS TEST DATA'.
      APPEND ls_text TO lt_text.
      CLEAR ls_text.
      document = cl_document_bcs=>create_document(
                          i_type    = 'txt'
                          i_text    = lt_text
                          i_subject = 'subject' ).
Preparing contents of attachment with Change Log
  PERFORM prepare_attachment.
DESCRIBE TABLE it_vbak LINES l_lines.
Size to multiplied by 2 for UNICODE enabled systems
     l_size = l_lines * 2 * 255.
REFRESH l_mailhex.
move l_lines to l_size  .
CALL METHOD document->add_attachment
        EXPORTING
          i_attachment_type    = c_ext
          i_attachment_subject = docdata
          i_attachment_size    = l_size
         i_att_content_text   = l_mailtext
          i_att_content_hex    = lt_solix.
         i_attachment_header  = LT_SOLI.
     CALL METHOD document->add_attachment
       EXPORTING
         i_attachment_type    = c_ext
         i_attachment_subject = docdata
         i_attachment_size    = l_size
         i_att_content_text   = l_mailtext
         i_att_content_hex    = lt_solix
         i_attachment_header  = l_mailtext.
*--Add document to send request
      CALL METHOD send_request->set_document( document ).
*-- Get sender object
      sender = cl_sapuser_bcs=>create( sy-uname ).
*--Add sender
         l_uname = sy-uname.
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.
      recipient = cl_cam_address_bcs=>create_internet_address( p_mail
*--Add recipient with its respective attributes to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient = recipient
          i_express    = 'U'
          i_copy       = 'X'
          i_blind_copy = ' '
          i_no_forward = 'X'.
*--set send immediately flag
      send_request->set_send_immediately( 'X' ).
*--Send document
      CALL METHOD send_request->send( ).
      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.
*&      Form  PREPARE_ATTACHMENT
FORM prepare_attachment.
FIELD-SYMBOLS: <lfs_table>,    " Internal table structure
                 <lfs_con>.      " 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 it_vbak 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 l_mailtext.
        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.
ENDFORM.                    " PREPARE_ATTACHMENT
Reward Ponts To All Helpfull Answers
Regards
Fareeeda

Similar Messages

  • Cannot send email through yahoo on iPad 4, apple.smtp.mail.yahoo not available as of December 1, 2012

    I am unable to send emails through yahoo on my ipad 4 wifi, just starting over the weekend. My 3 other non-yahoo email accounts are working fine on my ipad. When I try to send an email from the yahoo account, I receive the message that the connection to the outgoing mail server "apple.smtp.mail.yahoo" failed. I can send email through yahoo just fine on the web and on my computer through Thunderbird.

    Yahoo's been having persistently random issues for months. You can try just waiting it out, or delete and readd your yahoo account. When my accounts were affected I just used webmail to access my yahoo accounts until it cleared up.
    Chances are it's all on their end and really all you can do is wait it out.

  • Can't send email through my aol mail on my iPad 2 after updating to iOS 7

    I had to update m iPad because I was no longer able to work a lot of my apps because they kept telling me that there was an update that I had to do in order to even work my apps!  I was very reluctant to do it in the first place fearing that I would loose a lot of my pics, videos and or more!  Anyway so the other day I sat down and finally did it.  After updating my iPad 2 to the new operating system of iOS 7 now I cannot send emails through my aol mail on my iPad.  I tried putzing with the settings for smtp and to no avail nothing,  I then decided well maybe downloading the aol app would help but still not good enough because it takes up so much room that I had to delete some apps just to get it.  I had since deleted the aol app and am still trying to figure out why I keep getting the message I am getting is incorrect] hen it gives me two options which are option 1) Settings and option 2) Cancel.  I am in need of assistance here because I can receive mail but cannot send it.  Oh and I am able to send mail through my other email addresses on my iPad mail including my me.com and iCloud.com as well as two others but am not able to send through aol.  I am loosing my patience with apple very quickly as one why did I have to update the system and why am I forced to update my apps which I feel is completely ridiculous in the first place.  Everything was fine until I had to do that and now I cannot keep my iPad on for more then an hour when the battery drains so quickly now because I guess it takes up so much unneeded space!  PLEASE HELP ME!
    <Email Edited by Host>

    Hello, PriestessJeanann. 
    Thank you for visiting Apple Support Communities.
    Here is an article I would recommend going through when experiencing issues with mail.  The usual fix would be to delete the email account in question and add this account via the preset AOL option.  I would also recommend checking with your email provider for security procedures such as two-step verification as this could cause this issue.
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Cheers,
    Jason H.

  • TS3276 I receive a pop up from ICal saying the server does not recognize me user name and password.  This started yesterday.  I have no problems with receiving or sending emails through Mail

    I receive a pop-up from ICal saying the server does not recognize my user name and password for my me.com email address.  This started yesterday and occurs about every 5 minutes or so.  There are no problems with receiving or sending email through Mail.  I did change me email password several days ago but have no problems sending/receiving since then.

    I fixed the problem.  I opened Preferences in ICal and entered my new password.  No more pop-ups

  • HT1694 Can't send emails through Hotmail account

    This just started.  I can receive emails, but can't send emails through Hotmail account. iPhone says I need to check my settings (password).  I have correct password in settings.  Any help?

    Hello reedstrom,
    Sorry to hear you are not able to send emails from your Hotmail account.  Sending emails is a very important feature of the iPhone, and the fourth section in the following tutorial has steps for checking your Outgoing Mail Server settings. 
    Setting up Mail
    http://www.apple.com/support/iphone/assistant/mail/#section_4
    I hope this helps!
    Best,
    Sheila M.

  • Unable to send email through sky

    Hi, unable to send emails through sky as it says the password is incorrect on the settings page

    Hello David.ball,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Log in to your email provider's website to ensure that the account is active and the password is correct.
    Restart your iOS device.
    Delete the affected email account from your device.
    Tap Settings > Mail, Contacts, Calendars.
    Choose the affected email account, then tap Delete Account.
    Add your account again.
    Have a nice day,
    Mario

  • 3G Sending emails through tiscali

    I have a Nokia Lumia 710 smartphone. Receiving and sending emails through Wifi
    through my Tiscali account settings is no problem. The problen arises when I use 3G
    service. Surfing and receiving emails is no probelm but sending emails is. I have tried
    changing smpt from smtp.tiscali.co.uk:25:0 to smtp.o2.co.uk:25:0 (I'm payg with
    O2) and this can work but more often than not a message comes up asking for
    username and password for smpt.o2.co.uk. Trying my tiscali username and password
    is not accepted and then I have to delete the tiscali email account and start
    again. Very frustrating. I have been through O2 Guru and they supplied some APN settings but this has not solved the problem.

    Have you tried using the Network Setup app? If not download it from Marketplace if available and try running. 

  • TS3899 I can recieve emails but cannot send emails through my iPad for my Comcast email account. I believe I have all setting aligned properly. Anyone else have this problem?

    I can recieve emails but cannot send emails through my iPad for my Comcast email account. I believe I have all setting aligned properly. Anyone else have this problem?

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
     Cheers, Tom

  • I can't send emails through Yahoo using Firefox. Already contacted Yahoo and they don't know why it's happening.

    I can't send emails through Yahoo using Firefox. Already contacted Yahoo and they don't know why it's happening.
    == This happened ==
    Every time Firefox opened
    == a month agao

    I also cannot send email through Yahoo using Firefox 3.6.8. I can receive emails and surf the web just fine. I have also contacted Yahoo and have gotten no where.

  • Send email through Yahoo mail or Gmail with Java

    I have a java email program that can take a mail host name , port number and then send an email, but I don't want to use the mail host at work, I wonder if I can send email through my Yahoo Mail or Gmail account with Java, do they have any Java API that my program can log me in and send emails ? Any sample code available ? Thanks.
    Frank

    Thanks for reminding me, I did some search on "Yahoo" and "Gmail". For Yahoo someone posted some code that didn't work, for gmail, there seems to be a solution for sending email from command line. I wonder if I can send full fledged email : with CC, BCC, Attachment, Html email with images inside ...
    I've done it with a local mail host, but how to do it with Yahoo or Gmail ?
    Frank
    Have you read the JavaMail FAQ? Search for "Yahoo" and "Gmail".

  • Send email through applet

    Hello!
    Can anyone give me simple code of applet where i can send email through the form... and jar files or anything i have to import...
    Thank you very much

    Depends on how you want to handle it.
    If you want to send an email from the User's email program, you can execute a simple http request to "mailto:[email protected]" from within the applet by calling
    Applet.getAppletContext().showDocument("mailto:[email protected]")This will cause an email window to pop up using the user's email client.
    However, if you want to send email from within your program directly then you get into an area that is a little more complicated.
    First you would be using the javax.mail API. http://java.sun.com/products/javamail
    The problem you would have with this is that as an Applet you can only connect back to the server from which you came. So that server MUST have an SMTP process running on it. Otherwise you cannot send mail out since an Applet is not allowed to contact any other server other than it's own.
    If that security restriction is not a problem, then the example code at http://developer.java.sun.com/developer/onlineTraining/JavaMail/ should do everything you need.

  • Can't Send Email through Outlook using blackberry as a modem

    I am using my blaclberry 8900 as a modem and cannot send emails through outlook. I have called t-mobile and they say that it cannot be done. However I could do it with my Nokia. Any suggestions?

    Outlook folder permissions are Outlook issues, try the Microsoft Outlook Forums.

  • Can't send email through Apple mail

    I suddenly am not able to send email through Apple mail on my MacBookPro.  ipad and iphone still working.  I can also send email through att online.  My email is @att.net, and the message says "The server cannot be contacted on port 465".  (That is the proper port)

    Hi,
    Here are some suggestions,
    1. Try downloading another free email client to see if it works from there, just to eliminate other possibilities.
    2. Try removing the account in mail settings, and adding it again with the correct settings.
    Let me know what you find!
    Nolan

  • Want to send email through web server tomcat 5.5

    hi
    i want a send email through java programme using tomcat web server

    So do it.
    What's your question?
    Did you read the JavaMail FAQ and all the
    other wonderful documentation on the JavaMail
    web site?

  • Outlook 2010 address book prompt out hen trusted program try to send email through Outlook 2010

    Dear all,
      My program will send email through Outlook 2010(in cache mode). Sometime it may prompt the address book out and pend here, and we need to manually click "OK" to let the program run again. Although we re-write the program in
    Java and send by JavaMail now, but we are interested why the address book will prompt out.
      There are no pattern that we can guess the reason. Different recipient, different subject/content/have attachment or not can casue the address book prompt. But same email with same content/everythings may not cause prompt before and/or after.
      We try to change to offline address book and need manual sync, problem still occur.
      Just for interest~
    Cyrus
    [Sorry that MSDN not allow me to upload the cap screen :( ]

    Firstly, there is no such thing as a "trusted program" to Outlook. It only trusts COM addins, all other applications will cause a security prompt unless you have an up-to-date anti-virus app installed (if you can control the client environment).
    See http://www.outlookcode.com/article.aspx?id=52 for the list of your options. Essentially it is either installing an antivirus product or using a library such as
    Redemption (accessible from Java) or a utility such as
    ExpressClickYes.
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

Maybe you are looking for

  • Unable to Delete Database or Application

    I am trying to completly remove an Application, however when I right click and select Delete from within the Admin console, nothing happens. No errors - it just doesn't do anything. When I try to start the application, (I don't want to start it, but

  • Key Command for Snapping

    I've found that turning off "snapping" at certain times is just as useful as turning it on are at others. Sure would be useful if there was a key command for toggling this feature on and off. Anyone know if there is such a command? If not, perhaps Ap

  • My book will not up load when I try to buy it. Can the book be too long?

    my book will not up load when I try to buy it. Can the book be too long?

  • Release Version 2.0 NOW

    Don't know why Apple is delaying the release of version 2.0 for the 1st generation phones. What difference can this possibly make to wait to the last minute?? Can you imagine the chaos with everyone updating their old phones and bringing the 3G phone

  • Please recommend digital format for importing video into iMovie.

    I have iMovie '09 and am considering a purchase of a new digital camcorder. I want to easily inport video into IMovie for editing and burning DVD's for use on our home player and for importing into Facebook, email, etc. Can you recommend the best dig