Send a mail via ABAP program

Hello Experts,
I want to send mail via ABAP program with the following requirements :
1. Recipient is OUTLOOK email -id
2. Sender address has to be an external email-id
3. Send mail as CC and BCC also to other email-id.
Is there any function module which can satisfy all the above requirements.
Regards,
Mansi.

hi,
this code will definately help you just go through it:
firstly  exported the data to memory using the FM LIST_FROM_MEMORY.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc 0.
MESSAGE e000(su) WITH text-001.
ENDIF.
then i converted it into ASCII using LIST_TO_ASCI,
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_xlstab
listobject = t_listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE e003(yuksdbfzs).
ENDIF.
This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with
cl_abap_char_utilities=>horizontal_tab.
Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
This will create an excel attachment.
Sample code for formatting the data for the attachment in excel format.
u2022     Format the data for excel file download
LOOP AT t_xlstab INTO wa_xlstab .
DESCRIBE TABLE t_xlstab LINES lw_cnt.
CLEAR lw_sytabix.
lw_sytabix = sy-tabix.
u2022     If not new line then replace '|' by tabs
IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY t_xlstab FROM wa_xlstab .
CLEAR wa_xlstab.
wa_xlstab = cl_abap_char_utilities=>newline.
IF lw_cnt NE 0 .
lw_sytabix = lw_sytabix + 1.
u2022     Insert new line for the excel data
INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
lw_cnt = lw_cnt - 1.
ENDIF.
CLEAR wa_xlstab.
ENDIF.
ENDLOOP.
Sample code for creating attachment and sending mail:
FORM send_mail .
u2022     Define the attachment format
lw_doc_type = 'XLS'.
u2022     Create the document which is to be sent
lwa_doc_chng-obj_name = 'List'.
lwa_doc_chng-obj_descr = w_subject. "Subject
lwa_doc_chng-obj_langu = sy-langu.
u2022     Fill the document data and get size of message
LOOP AT t_message.
lt_objtxt = t_message-line.
APPEND lt_objtxt.
ENDLOOP.
DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE lt_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'F'.
ELSE.
lwa_doc_chng-doc_size = 0.
ENDIF.
u2022     Fill Packing List For the body of e-mail
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.
u2022     Create the attachment (the list itself)
DESCRIBE TABLE t_xlstab LINES lw_tab_lines.
u2022     Fill the fields of the packing_list for creating the attachment:
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = lw_doc_type.
lt_packing_list-obj_name = 'Attach'.
lt_packing_list-obj_descr = w_docdesc.
lt_packing_list-doc_size = lw_tab_lines * 255.
APPEND lt_packing_list.
u2022     Fill the mail recipient list
lt_reclist-rec_type = 'U'.
LOOP AT t_recipient_list.
lt_reclist-receiver = t_recipient_list-address.
APPEND lt_reclist.
ENDLOOP.
u2022     Finally send E-Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = lw_sent_to_all
TABLES
packing_list = lt_packing_list
object_header = lt_objhead
contents_bin = t_xlstab
contents_txt = lt_objtxt
receivers = lt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
Hope it will help you
regards
Rahul sharma

Similar Messages

  • How to extract data from BPC InfoCube via ABAP program?

    Hi experts!!
    I tried to extract data from a BPC InfoCube via ABAP program, but I did'n have succeed.
    I used the function 'RSDRI_INFOPROV_READ' to extract data from standard InfoCubes such as '0COPC_C07' and it run OK! However, when I change the InfoCube name to '/CPMB/WAIX8NE' (BPC InfoCube), everything goes wrong...
    Is there any difference between extracting data from BPC and standard InfoCubes?
    Thank you all!

    Moderator message - Welcome to SCN.
    But please do not cross and duplicate post.
    Thread locked.
    Rob

  • Can't send e-mails via Mail with a Gmail e-mail address using Sky internet

    Can anyone help? My brother has an iBook G4 Mac OS X 4.1 and is trying to send e-mails via Mail with a Googlemail e-mail account. He is using Sky for his broadband. I assume it has something to do with his outgoing smtp e-mail Preferences in Mail, but for the life of me I can't figure it out. He can receive e-mails OK, its just that when he tries to send he gets the 'server can't send error'. Any ideas?

    Here's my gMail IMAP SMTP settings...
    smtp.gmail.com
    Port 25
    Authentication: Password
    SSL
    Sky may require another port to pass through...
    IMAP is port 143
    IMAP-SSL is port 993
    POP is port 110
    POP-SSL is port 995
    SMTP and SMTP-SSL is on ports 25, 587 and 465. Port 587 has to be SSL, and port 465 is enforced TLS-wrapped and is generally used by Outlook users.

  • Steps involved to send a mail in abap.

    hi experts,
                can anyone help me with the process involved in  sending a mail to a specific email id obtained form database.
    it will be helpful if u can provide me with the material or the code.
    thanks in advance,
    abhilash.

    Hi,
    Please visit the links for sending a mail in ABAP:
    1. http://www.sap-img.com/fu016.htm
    2. http://www.sap-basis-abap.com/abap011.htm
    May this helps you.
    Regards.
    Deepak Sharma.

  • I am unable to Send E-mail via Default mail app in my iphone. IOS7, i have account of icloud, Gmail, Microsoft all the account are well added, i can recieve e-mails but the massage i send is never sent

    I am unable to Send E-mail via Default mail app in my iphone. IOS7, i have account of icloud, Gmail, Microsoft all the account are well added, i can recieve e-mails but the massage i send is never sent

    Turns out this was a simple set up error for me, although i'd set up mobile me to sync my e mails I had never set up my outgoing message server. Therefore, if I received a message from me.com I could reply no problem, however if the message came from aol.com I couldn't reply.

  • When trying to send E-mail via AOL i get the message "rejected by the server because it does not allow relaying" I have checked settings as per answers to similar question

    When trying to send E-mail via AOL i get the message "rejected by the server because it does not allow relaying" I have checked settings as per answers to similar question

    From which account does the email not send?  When sending from an account, the iPad will first try to use the aoutgoing server for that account.  If it can't it will try the other accounts listed.in the setting on the iPad for that account.  It soulds like the server for the account is not working and that the alternate server is resjecting the messag since it did not originate ffrom the account associated with that server,  That is to prevent sending spam.

  • Set Sender of Mail from Abap

    Hi,
    I use SO_NEW_DOCUMENT_SEND_API1 function module to send a mail from abap code.
    But I want to set the sender. Can I realize it?
    Regards
    Angela

    Refer this thread -
    Fill "sender id" in SO_NEW_DOCUMENT_SEND_API1
    Regards,
    Amit

  • Failed to send E-mail via microsoft OutLook

    Hi All,
    Does anybody knows why this message appears when I tried to send an email via out look, using the button email on the B1 menu bar.  i have selected the user name and the email address correctly, i have ticked the option send emiail using microsoft outlook.  then the following error message appeared
    "BO2069: Failed to send e-mail via Microsoft Out look"
    the connection was established between outlook and b1 using the logon function in outlook integration addon.
    thanks
    SV Reddy

    Dear,
    If my last answer could not solve your issue, please refer to the informaiotn below:
    The reported issue occurs due to the fact that outlook can only send attachments from the Business One attachments folder.
    This issue has been fixed in 2005A SP01 PL41. Please refer to the note 1116389. As a solution we would suggest to upgrade to the latest patch level.
    Until you upgrade to latest patch of 2005A SP 01 you can use the following workaround:
    - Manually copy all attachments to the B1 attachment path before sending this mail. If you create a shortcut to your attachments folder in a convenient location (perhaps the desktop) this can be done very quickly. (Browse to your document, right click and select copy, press the Windows Key+D to go to your desktop, double
    click the shortcut, then paste into the attachments folder.)
    Alternatively, you could either:
    - Change the B1 attachment path to your attachment files path.
    or
    - Uncheck 'Send E-mail via MS Outlook', and send this message. Nowthese attachments will be copied to the Business One attachment path.
    Then send this message again, with 'Send E-mail via MS Outlook' checked.
    Further we would suggest to apply following steps:
    -upgrade your MS Office 2003 application to the current SP. (SP3)
    -verify that the sender's e-mail address defined for the sender in SAP Business One is valid.
    -Set up the correct smtp server in SBO Mailer / General Setting /Mail Settings (you should check with a "Test connection" button)
    Wish the information could solve your issue.
    Regards
    Apple

  • Unable to write and send e-mails via MSN, please help ASAP.

    Since a few days ago, using mozilla, I am unable to write and send e-mails via MSN.
    == This happened ==
    Every time Firefox opened
    == About 3 days ago.

    Also, and although possibly not related to your problem, I have to remind you that the version of Firefox you are using at the moment has been discontinued and is no longer supported. On top of this, it has known unpatched bugs and security problems. I urge you to update to the latest version of Firefox, for maximum security, stability, performance and usability. You can get it for free, as always, at [http://www.getfirefox.com getfirefox.com].

  • TS3899 My iphone has had problems sending e-mail via my 1&1 e-mail account

    My iphone has had problems sending e-mail via my 1&1 e-mail account for the last two days.  I get a 'recipient rejected by the server' message.  I have not changed any settings.  If I change the from address to i-cloud the e-mails go.  Advice please.

    i think you need to contact your email provider - that sounds like an issue on their end and nothing to do with your phone.

  • Issues sending iCloud mail via Mac Mail client

    I'm running OS X Yosemite and use the Mac Mail client to handle mail for my iCloud (mac.com), wish.edu, Gmail, and Outlook accounts.  All work fine and always have... until a few weeks ago.  I came to figure out that while sending email through my iCloud account will show up as a sent email in the sent folder (on my MacBook Pro as well as the web interface and IOS devices) the messages do not get received on the other end.  No error messages.  No returns.  Everything looks normal on my end but the emails never get delivered.
    I logged out of iCloud and logged back in.  I checks the outgoing server info and passwords. I restarted (a lot).  When I run tests, emails sent from the Mac Mail client on my laptop don't get there.  They do get received when sent via the iCloud web interface as well as from my iPhone and iPad.  I even downloaded PostBox and set it up with the exact same settings as Mac Mail, and it sends the iCloud mail just fine.
    This is driving me nuts.  I love Mac Mail, and have used it for years.  I don;t want to have to abandon it for this.  Help?

    Hi All,
        I have a requirement where i have to send the Pdf format of the billing document as a mail to the customer. And my client wants to send the mail via outlook so that they can modify the body content for each mail. Right now i have achieved the functionality of sending the mail with Pdf attachment form SAP.
    Can anyone please help me by providing some information about how to send mail from SAP via Outlook.
    Thanks!
    Praveenkumar T.

  • Sending e-mail from ABAP

    We need to send email to an external adress from ABAP. Does anybody know a function module or method to do this, maybe even with sample coding?
    Best regards
       Dirk

    There are some weblogs here:
    4.6x and lower:
    /people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface
    6.10 and higher:
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

  • Send few attachment at one mail via Abap

    Hi.
    How can send few attachments in one mail threw Abap?
    I know how to send files but how can I attach few files in one mail ?
    Thanks all,
    Rebeka

    Hi,
    Tthe following piece of logic is required to send multiple attachments in one mail.
    Loop
    * Creating the entry for the compressed attachment
            IF gv_count = 1.
              gi_objpack-head_start = 1.
              gi_objpack-head_num   = 1.
              gi_objpack-body_start = 1.
              DESCRIBE TABLE gi_objbin LINES gv_no_lines.
              gi_objpack-body_num   = gv_no_lines.
              gi_objpack-doc_size   = gv_no_lines * 255.
              gi_objpack-transf_bin = gc_x.
              gi_objpack-doc_type   = gc_pdf.
              gi_objpack-obj_name   = text-037.
              CONCATENATE text-038 gw_doc_id-object_id(10)
              INTO gi_objpack-obj_descr.
              APPEND gi_objpack.
            ELSEIF gv_count > 1.
              gi_objpack-head_start = gv_no_lines + 1.
              gi_objpack-head_num   = gv_no_lines + 1.
              gi_objpack-body_start = gv_no_lines + 1.
              DESCRIBE TABLE gi_upload LINES gv_no_lines.
              gi_objpack-body_num   = gv_no_lines.
              gi_objpack-doc_size   = gv_no_lines * 255.
              gi_objpack-transf_bin = gc_x.
              gi_objpack-doc_type   = gc_pdf.
              gi_objpack-obj_name   = text-037.
              CONCATENATE text-038 gw_doc_id-object_id(10)
              INTO gi_objpack-obj_descr.
              APPEND gi_objpack.
              DESCRIBE TABLE gi_objbin LINES gv_no_lines.
            ENDIF.
      Endloop.
    Each record in gi_objpack is an attachment, say suppose 3 records are there, then it means 3 attachments.
    gi_objbin is the attachment content, here it is a PDF File.
    Hope u know about this FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' and remaining details to pass to this FM.
    Thanks,
    Srilakshmi.

  • How to send SMS by using ABAP program

    HI Gurus,
    I need to notify the vendor through sms when his goods are received. His details are stored in vendor master.
    My problem is that I am not able to find any function module for the same.
    Do any of you know how to send 'sms' to particular mobile number using ABAP.
    Are there any basis settings required for the same?
    Thanks and Regards,
    Saurabh

    Hi,
    Pls check the below links
    http://help.sap.com/saphelp_nw04/helpdata/en/58/97c43af280463ee10000000a114084/frameset.htm
    /people/ronen.fox/blog/2007/12/06/sending-sms-notification-via-business-workflow
    http://www.****************/Tutorials/Workflow/Workflow.htm
    You can use the FM: 'SO_DOCUMENT_SEND_API1' &
    'SO_DOCUMENT_SEND_API1_NEW'.
    to send the mail,sms etc.
    But you have to make some chamnges in the reciever table, jus go thru FM documnetaion once, you will fine the option for sending SMS thru either of this FM.
    Below is a sample code for sending e-mail.
    so, u can take help from this.
    data declarations
    DATA : v_sender TYPE soextreci1-receiver,
    v_doc TYPE sodocchgi1,
    it_paklist TYPE STANDARD TABLE OF sopcklsti1 ,
    wa_paklist TYPE sopcklsti1 ,
    it_obj_head TYPE STANDARD TABLE OF solisti1 ,
    it_obj_bin TYPE STANDARD TABLE OF solisti1 ,
    it_obj_txt TYPE STANDARD TABLE OF solisti1 ,
    it_obj_rcv TYPE STANDARD TABLE OF somlreci1 ,
    wa_obj_rcv TYPE somlreci1 ,
    v_desc(100).
    CONSTANTS: c_start(12) TYPE c VALUE '000000000000001',
    c_num(12) TYPE c VALUE '000000000000002',
    c_num1(12) TYPE c VALUE '000000000010030',
    c_raw(3) TYPE c VALUE 'RAW',
    c_test(4) TYPE c VALUE 'TEST',
    c_X(1) TYPE c VALUE 'X'.
    refresh internal tables
    REFRESH : it_paklist, it_obj_rcv.
    clear internal tables
    CLEAR : it_paklist, it_obj_rcv, v_sender.
    v_sender = sy-uname.
    fill internal table it_paklist
    wa_paklist-head_start = c_start.
    wa_paklist-head_num = c_num.
    wa_paklist-body_start = c_start.
    wa_paklist-body_num = c_num1.
    wa_paklist-obj_name = c_test .
    wa_paklist-doc_type = c_raw .
    wa_paklist-transf_bin = c_X .
    APPEND wa_paklist TO it_paklist.
    clear: wa_paklist.
    Data in the Header/subject Line
    v_desc = text-005 .
    v_doc-obj_name = c_objname .
    v_doc-obj_descr = v_desc.
    Mail text
    APPEND v_desc TO it_obj_txt.
    Preparing the receiver list
    wa_obj_rcv-rec_type = 'U'.
    wa_obj_rcv-rec_type = 'C'.
    v_dlist = 'SCE_TEST'.
    wa_obj_rcv-receiver = v_dlist. "Distribution list.
    wa_obj_rcv-receiver = Enter the mail id .
    APPEND wa_obj_rcv TO it_obj_rcv.
    Call the function module to send mail
    IF NOT it_obj_rcv[] IS INITIAL.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = v_doc
    sender_address = v_sender
    sender_address_type = 'B'
    put_in_outbox = 'X'
    commit_work = 'X'
    TABLES
    packing_list = it_paklist
    object_header = it_obj_head
    contents_bin = it_obj_bin
    contents_txt = it_obj_txt
    receivers = it_obj_rcv
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.
    IF sy-subrc NE 0.
    MESSAGE text-006 TYPE 'I' .
    ENDIF.
    ENDIF .

  • To post a mail from ABAP program

    dear friends
                  how to post a mail to SAP inbox of a particular user from ABAP program.

    get the spool no of the program
    we have standard program rstxpdf4  through that convert it to pdf
    and through f.m SO_NEW_DOCUMENT_ATT_SEND_API1 u can send mail.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       EXPORTING
         DOCUMENT_DATA                    = x_document_data
         PUT_IN_OUTBOX                    = 'X'
         COMMIT_WORK                      = 'X'
       TABLES
         PACKING_LIST                     = it_packing_list
         CONTENTS_BIN                     = it_contents_bin
         CONTENTS_TXT                     = it_contents_txt
         RECEIVERS                        = it_receivers
      EXCEPTIONS
        TOO_MANY_RECEIVERS               = 1
        DOCUMENT_NOT_SENT                = 2
        DOCUMENT_TYPE_NOT_EXIST          = 3
        OPERATION_NO_AUTHORIZATION       = 4
        PARAMETER_ERROR                  = 5
        X_ERROR                          = 6
        ENQUEUE_ERROR                    = 7
        OTHERS                           = 8 .
    IF SY-SUBRC <> 0.
       retcode = sy-subrc.
       perform protocol_update.
    else .

Maybe you are looking for