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 HTML Mails using SO_DOCUMENT_SEND_API1

Former Member
0 Kudos
1,994

Dear all,

we were using SO_DOCUMENT_SEND_API1 to send plain text e-mail replies to participants of an incentive program. Now the customer wants to send HTML mails. Customer has provided HTML templates for the mails, and the text always is the same, only slight changes in regard to the particpants number occur. Has anybody ever performed sending HTML formated mails without using SmartForms?

Thanks for your help!

Kind Regards

Chris

1 ACCEPTED SOLUTION

Former Member
0 Kudos
390

u can check this and try the same with ur FM

http://www.sapgenie.com/abap/code/abap20.htm

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
390

Sure.. here is a sample program.



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

0 Kudos
390

Its really just as easy as putting the HTML code in the MailTxt internal table and setting the document type as "HTM". That's it.

<b>document_type              = 'HTM'</b>

We've create some very good looking emails doing it this way. With logos and tables.

Welcome to SDN! Please remember to award points for helpful answers and mark your post as solved when solved completely. Thanks.

Regards,

Rich Heilman

Former Member
0 Kudos
391

u can check this and try the same with ur FM

http://www.sapgenie.com/abap/code/abap20.htm

0 Kudos
390

Please remember to award points for helpful answers and mark your post as solved when solved completely. Thanks.

Regards,

Rich Heilman

0 Kudos
390

Rich Can we send attachment by usin this FM OR do we have any other FM for that purpose . My SAP Version is 4.7