Attaching Pdf file and sending mail
Schumacher, Margaret
mschumacher at teleflexmedical.com
Wed Jul 30 17:00:55 EDT 2008
You might be able to use the following ... I use it after a smart form
call where the control parameter getotf was specified.
form send_email using ps_job_info type ssfcrescl
ps_nast type nast
ps_recip type zrb_ad3display.
data: l_len_in like sood-objlen,
l_subject like sodocchgi1-obj_descr,
lt_mess_bod like solisti1 occurs 0 with header line,
lt_mess_att like solisti1 occurs 0 with header line,
lt_tline type table of tline with header line,
l_attachment_desc type so_obj_nam,
l_attachment_name type so_obj_des,
wa_buffer type string, "To convert from 132 to 255
l_error type sy-subrc,
l_address like usaddress,
l_address_string type adr6-smtp_addr,
lt_otf type itcoo occurs 0 with header line.
* Convert the OTF output to a PDF format for sending
lt_otf[] = ps_job_info-otfdata[].
call function 'CONVERT_OTF'
exporting
format = 'PDF'
max_linewidth = 132
importing
bin_filesize = l_len_in
tables
otf = lt_otf
lines = lt_tline
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
loop at lt_tline.
translate lt_tline using '~'.
concatenate wa_buffer lt_tline into wa_buffer.
endloop.
translate wa_buffer using '~'.
do.
lt_mess_att = wa_buffer.
append lt_mess_att.
shift wa_buffer left by 255 places.
if wa_buffer is initial.
exit.
endif.
enddo.
* Default subject matter
concatenate 'Object-'(001) ps_nast-objky into l_subject.
l_attachment_desc = ps_nast-objky.
refresh lt_mess_bod.
concatenate 'See Attachment from SAP ('(002)
sy-sysid '/' sy-mandt ')' into lt_mess_bod.
translate lt_mess_bod using '~ '. append lt_mess_bod.
* Send file by email as .PDF
perform send_file_as_email_attachment
tables lt_mess_bod
lt_mess_att
using ps_recip-smtp_addr
l_subject
'PDF'
l_attachment_name
l_attachment_desc
changing l_error.
endform. "send_email
form send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
changing p_error.
data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type so_obj_nam ,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_receivers like somlreci1 occurs 0 with header line,
t_attachment like solisti1 occurs 0 with header line,
t_object_header like solisti1 occurs 0 with header line,
w_cnt type i,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'saprpt'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
clear w_doc_data.
read table it_attach index w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + strlen( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'saprpt'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
clear t_attachment.
refresh t_attachment.
t_attachment[] = it_attach[].
* Describe the body of the message
clear t_packing_list.
refresh t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_message lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
describe table t_attachment lines t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
append t_packing_list.
* Add the recipients email address
clear t_receivers.
refresh t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
append t_receivers.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = w_doc_data
put_in_outbox = 'X'
commit_work = 'X'
importing
sent_to_all = w_sent_all
tables
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
* Populate zerror return code
ld_error = sy-subrc.
endform. "send_file_as_email_attachment
Regards
Margaret Schumacher
________________________________
From: muralitharan.c at tcs.com [mailto:muralitharan.c at tcs.com]
Sent: Tuesday, July 29, 2008 3:45 AM
To: sap-wug at mit.edu
Subject: Attaching Pdf file and sending mail
Hi All,
I'm creating a workflow for purchase request, when this workflow
triggered i have wrritten a rule to create a smartform and it'll be
convert into pdf file.
Now i need to attach this file dynamically without downloading to local
system it should attach with work item and then this particular work
item need to send as mail to approver or particular user.
I request you to give me details about this.
Advance thanks!
Regards,
Muralitharan C
Tata Consultancy Services
Mailto: muralitharan.c at tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/sap-wug/attachments/20080730/07ca14ae/attachment.htm
More information about the SAP-WUG
mailing list