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: 

Email with attachement

Former Member
0 Kudos
130

Hi all,

I am having a HTML file in the C drive i want to send that file as an attachment with an mail to a set of people. I tried with 'SO_NEW_DOCUMENT_ATT_SEND_API1' but i am not able to get the input parameters. Kindly let me know the correct input patrameters or any other function module.

my file is in c:\sample.html.

I am not able to fill the PACKING_LIST parameter.

regards,

Bala

6 REPLIES 6

VijayasekarK
Active Participant
0 Kudos
83

Hi ,

Refer the below mentioned code ...which i have used in one of my program.

-


Source Code -


LOOP AT t_out_itab.

*// Begin

REFRESH : t_buffer , plist , reclist.

clear : tsp01,lfa1,adr6,l_spool_id.

*// End

SELECT SINGLE msgv1 INTO l_msgv1

FROM cmfp

WHERE aplid EQ 'WFMC' AND

nr EQ t_out_itab-cmfpnr AND

msgty EQ 'W' AND

msgnr EQ '320'.

CONDENSE l_msgv1.

*// Sending Mail to Vendor and User - PO as an Attachment *//

l_spool_id = l_msgv1.

l_docdata-obj_name = 'Purchase Order'.

l_docdata-obj_descr = 'Purchase Order'.

SELECT SINGLE * FROM tsp01 WHERE rqident = l_spool_id.

IF sy-subrc EQ 0.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = l_spool_id

IMPORTING

real_type = l_otf

TABLES

buffer = t_buffer.

CALL FUNCTION 'CONVERT_ITF_TO_ASCII'

TABLES

itf_lines = t_buffer.

REFRESH plist.

plist-transf_bin = 'X'.

plist-head_start = 0.

plist-head_num = 0.

plist-body_start = 1.

DESCRIBE TABLE t_buffer LINES plist-body_num.

plist-doc_type = 'OTF'.

APPEND plist.

SELECT SINGLE * FROM lfa1 WHERE lifnr EQ t_out_itab-lifnr.

SELECT SINGLE * FROM adr6 WHERE addrnumber EQ lfa1-adrnr.

reclist-receiver = adr6-smtp_addr.

reclist-rec_type = 'U'.

APPEND reclist.

*// Getting User Email Address

l_username = t_out_itab-usnam.

CALL FUNCTION 'BAPI_USER_GET_DETAIL'

EXPORTING

username = l_username

TABLES

return = t_return

addsmtp = t_user_smtp.

reclist-receiver = t_user_smtp-e_mail.

reclist-rec_type = 'U'.

APPEND reclist.

*// Sending Mail

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = l_docdata

put_in_outbox = 'X'

sender_address = space

sender_address_type = space

commit_work = 'X'

TABLES

packing_list = plist

contents_bin = t_buffer

receivers = reclist.

COMMIT WORK.

ENDIF.

ENDLOOP.

-


End of Source Code -


Regards,

Vijay

andreas_mann3
Active Contributor
0 Kudos
83

Hi,

have a look:

-/people/thomas.jung3/blog/2004/09/07/sending-e-mail-from-abap--version-46d-and-lower--api-interface

and

Andreas

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
83

Here is an example of sending an HTML email.



report zrich_0002.

data: maildata   like sodocchgi1.
data: mailtxt    like solisti1 occurs 10 with header line.
data: mailrec    like somlrec90 occurs 0  with header line.

start-of-selection.

  clear:    maildata, mailtxt,  mailrec.
  refresh:  mailtxt, mailrec.

  perform build_text_message.
  perform build_receivers.
  perform send_mail_nodialog..

************************************************************************
*      Form  BUILD_TEXT_MESSAGE
************************************************************************
form build_text_message.


  maildata-obj_name = 'TEST'.
  maildata-obj_descr = 'Test Subject'.


  mailtxt  = '<html>'.
  append mailtxt.
  mailtxt  = '<head>'.
  append mailtxt.
  mailtxt  = '<title>Untitled Document</title>'.
  append mailtxt.
  mailtxt  = '<meta http-equiv="Content-Type" content="text/html;'.
  append mailtxt.
  mailtxt  = 'charset=iso-8859-1">'.
  append mailtxt.
  mailtxt  = '</head>'.
  append mailtxt.
  mailtxt  = '<body>'.
  append mailtxt.
  mailtxt  = '<div align="center"><em><font' .
  append mailtxt.
  mailtxt  = 'color="#0000FF" size="+7" face="Arial,'.
  append mailtxt.
  mailtxt  = 'Helvetica, sans-serif">THIS'.
  append mailtxt.
  mailtxt  = '  IS A TEST </font></em><font' .
  append mailtxt.
  mailtxt  = 'color="#0000FF" size="+7" face="Arial,'.
  append mailtxt.
  mailtxt  = 'Helvetica, sans-serif"></font>'.
  append mailtxt.
  mailtxt  = '</div>'.
  append mailtxt.
  mailtxt  = '</body>'.
  append mailtxt.
  mailtxt  = '</html>'.
  append mailtxt.

endform.

************************************************************************
*      Form  BUILD_RECEIVERS
************************************************************************
form build_receivers.

  mailrec-receiver = you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  append mailrec.

endform.

************************************************************************
*      Form  SEND_MAIL_NODIALOG
************************************************************************
form send_mail_nodialog.

  call function 'SO_NEW_DOCUMENT_SEND_API1'
       exporting
            document_data              = maildata
            document_type              = 'HTM'
            put_in_outbox              = 'X'
       tables
            object_header              = mailtxt
            object_content             = mailtxt
            receivers                  = mailrec
       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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

endform.

Regards,

Rich Heilman

Former Member
0 Kudos
83

The file is going to be downloaded when ever i am executing the program from a list

its not a hardcoded value.

Former Member
0 Kudos
83

Hi Bala,

check this out.

The following is the code to send an email.

This program extract does two things

1. Sends file contents as body of the mail

2. Sends a file as attachment.

Before going through the code, just check

the unix command for sending email, given below.

_____________________________________________

(cat 'filename containing the body of email' ; uuencode 'name of file to be attached' 'Name of attached file to be displayed in the email') | /bin/mailx -s "

Subject of the mail " 'To email address'

______________________________________________

Cat sends the file contents as body of email and uuencode sends the file as attachment

(cat content ; uuencode filename fname) | /bin/mailx -s "

'Subject of the mail' " 'To email address'

_____________________________________________

FORM mail_message USING username filename.

DATA: BEGIN OF file OCCURS 0,

line(250),

END OF file.

  • Attached file will be displayed in the mail as fname

  • filename is the file that will be send as attachment in the email.

DATA : filename(100) TYPE c VALUE '/data/logs/lfile.txt'

DATA : fname(25) VALUE 'Logfile.txt'.

DATA: parcom(300) TYPE c,

pbody1(50) VALUE

'Please find the log details as an attachment

(This is the body of email) '

  • Content contains the file which contains the body of the mail.

  • Username contains the email address to which the mail has to be sent.

DATA : content(50) VALUE '/usr/sap/tmp/body'.

DATA : username(50) VALUE 'susmitha.thomas@wipro.com'.

CLEAR parcom.

TRANSLATE username TO LOWER CASE.

TRANSLATE filename TO LOWER CASE.

  • Writing the body of the mail to the file

OPEN DATASET content FOR OUTPUT IN TEXT MODE.

TRANSFER pbody1 TO content.

CLOSE DATASET content.

CONCATENATE '(cat ' content '; uuencode ' filename fname ') |' '/bin/mailx -s "'

'Subject of the mail' '"' username

INTO parcom SEPARATED BY space.

*

REFRESH file.

CLEAR file.

  • Send The Message.

CALL 'SYSTEM' ID 'COMMAND' FIELD parcom

ID 'TAB' FIELD file-sys.

  • if sy-subrc = '0'.

  • write: / 'Mail message successfully sent'.

  • else.

  • write: / 'Mail message failed'.

  • endif.

ENDFORM.

Hope this helps u,

Regards,

Nagarajan.