Quantcast
Channel: SCN: Message List - ABAP Development
Viewing all articles
Browse latest Browse all 10425

Unable to send mail through sap to internal/external mail id's

$
0
0

Hello Gurus,

 

 

                       when i am trying to send mail through SAP ,  i am able to send mail  to sap inbox along with PDF attachment, but not to internal /external mail id's. SCOT is already configured from Basis side

                       

                       below is my code of the same program..

                          

                       pls suggest me any solution.

 

 

                          

data: fm_name type rs38l_fnam.

data: it_otf_final type itcoo occurs 0 with header line.

data: bin_filesize type i.

data: it_pdfdata type table of tline.

data: it_pdf type table of solisti1.

 

 

* MAIL RELATED DECLARATIONS

data : g_sent_to_all type sonv-flag,

g_tab_lines type i.

 

 

types: t_document_data type sodocchgi1,

t_packing_list type sopcklsti1,

t_attachment type solisti1,

t_body_msg type solisti1,

t_receivers type somlreci1,

t_pdf type tline.

 

 

data : w_document_data type t_document_data,

w_packing_list type t_packing_list,

w_attachment type t_attachment,

w_body_msg type t_body_msg,

w_receivers type t_receivers,

w_pdf type t_pdf.

 

 

data: customer type scustom,

bookings type ty_bookings,

connections type ty_connections.

data: var_a.

 

 

data : i_document_data type standard table of t_document_data,

i_packing_list type standard table of t_packing_list,

i_attachment type standard table of t_attachment,

i_body_msg type standard table of t_body_msg,

i_receivers type standard table of t_receivers,

i_pdf type standard table of t_pdf.

 

 

ssfctrlop-no_dialog = 'X'.

ssfctrlop-preview   = 'X'.

ssfctrlop-getotf    = 'X'.

ssfcompop-tddest    = 'LP01'.

 

 

 

    call function l_v_fm_name

      exporting

 

        control_parameters = ssfctrlop

        output_options = ssfcompop

 

        wa_header                  = wa_header

        v_tot                      = l_v_tot

        v_tot2                     = l_v_tot2

        i_v_name2                  = i_v_name2

        flag                       = flag

        user_settings              = space

 

      importing

      job_output_info              = it_otf_data

 

      tables

        i_mat_dtl                  = l_i_mat_dtl

        i_qty                      = l_i_qty

        i_amnt_dtl                 = l_i_amnt_dtl

        i_tax                      = l_i_tax

        i_ttxit                    = l_i_ttxit

        i_stxh                     = l_i_stxh

     exceptions

       formatting_error           = 1

       internal_error             = 2

       send_error                 = 3

       user_canceled              = 4

       others                     = 5

              .

    if sy-subrc <> 0.

      message id sy-msgid type sy-msgty number sy-msgno

              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    endif.

           

it_otf_final[] = it_otf_data-otfdata[].

 

* CONVERTING OTF DATA INTO PDF DATA

call function 'CONVERT_OTF'

exporting

format = 'PDF'

importing

bin_filesize = bin_filesize

tables

otf   = it_otf_final

lines = it_pdfdata[]

exceptions

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

others = 5.

* To send data as email attachment, we need to have a table of SOLISTI1.

* This table contains line size of 255 characters. Below function module

* does the trick of changing the table from X character sized lines into

* any given Y character sized lines.

call function 'SX_TABLE_LINE_WIDTH_CHANGE'

exporting

line_width_dst = '255'

tables

content_in = it_pdfdata[]

content_out = it_pdf[]

exceptions

err_line_width_src_too_long = 1

err_line_width_dst_too_long = 2

err_conv_failed = 3

others = 4.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

else.

 

 

* SUBJECT OF THE MAIL.

w_document_data-obj_name = 'MAIL_TO_HEAD'.

w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

 

 

* BODY OF THE MAIL

w_body_msg = 'This is body of mail msg.'.

append w_body_msg to i_body_msg.

clear w_body_msg.

 

 

* WRITE PACKING LIST FOR BODY

describe table i_body_msg lines g_tab_lines.

w_packing_list-head_start = 1.

w_packing_list-head_num = 0.

w_packing_list-body_start = 1.

w_packing_list-body_num = g_tab_lines.

w_packing_list-doc_type = 'RAW'.

append w_packing_list to i_packing_list.

clear w_packing_list.

 

 

* WRITE PACKING LIST FOR ATTACHMENT

w_packing_list-transf_bin = 'X'.

w_packing_list-head_start = 1.

w_packing_list-head_num = 1.

w_packing_list-body_start = 1.

 

 

describe table it_pdf lines w_packing_list-body_num.

w_packing_list-doc_type = 'PDF'.

w_packing_list-obj_descr = 'PDF Attachment'.

w_packing_list-obj_name = 'PDF_ATTACHMENT'.

 

 

w_packing_list-doc_size = w_packing_list-body_num * 255.

*w_packing_list-doc_size = w_packing_list-body_num * 500.

append w_packing_list to i_packing_list.

clear w_packing_list.

 

 

* FILL THE DOCUMENT DATA &GET SIZE OF ATTACHMENT

w_document_data-obj_langu = sy-langu.

read table it_pdf into w_pdf index g_tab_lines.

w_document_data-doc_size = ( g_tab_lines - 1 ) * 500 + strlen( w_attachment ).

 

 

* RECEIVERS LIST.

 

w_receivers-receiver = 'ABC@XYZ.COM'.

w_receivers-rec_type = 'U'. "Internet address

*w_receivers-com_type = 'INT'.

*w_receivers-notif_del = 'X'.

*w_receivers-notif_ndel = 'X'.

append w_receivers to i_receivers .

clear:w_receivers.

  

 

* SEND MAILS TO RECIPIENTS

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = w_document_data

put_in_outbox = 'X'

commit_work = 'X'

 

 

importing

sent_to_all = g_sent_to_all

tables

packing_list = i_packing_list

contents_bin = it_pdf

contents_txt = i_body_msg

receivers = i_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 .

*   wait UP TO 3 SECONDS.

   submit rsconn01 with mode = 'INT' and return.

*   commit work.

*MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.

endif.

endif.

 

             

                       


Viewing all articles
Browse latest Browse all 10425

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>