0% found this document useful (1 vote)
2K views3 pages

SAP ABAP Embed An Image To Body of An Email

This document provides code to insert an image into the body of an email generated from SAP. The code first locates the image file on a server accessible via the internet. It then builds the email body using HTML tags, embedding an <img> tag that references the image file location to display the image in the email. The code samples call SAP functions to send the email without opening a dialog.

Uploaded by

Emil S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views3 pages

SAP ABAP Embed An Image To Body of An Email

This document provides code to insert an image into the body of an email generated from SAP. The code first locates the image file on a server accessible via the internet. It then builds the email body using HTML tags, embedding an <img> tag that references the image file location to display the image in the email. The code samples call SAP functions to send the email without opening a dialog.

Uploaded by

Emil S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SAP ABAP embed an image to body of an email

There have been requirements to insert a picture (company logo, product images, etc.) in mails
generated from SAP.

Following code helps to insert images in messages. Here, we are assuming that we are successful in
sending a text based mail via code. All you really need to do is a little HTML.

First, the picture should be located on a server which can be hit threw the internet (if this mail is to go
outside your network). Next, use HTML to build your mail body.
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>Holla</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><img src = "C:\upload_to_itab.jpg"></img>'.
append mailtxt.
mailtxt = '</body>'.
append mailtxt.
mailtxt = '</html>'.
append mailtxt.

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

mailrec-receiver = '[email protected]'.
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.

You might also like