Application Development and Automation 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: 
Read only

about send mail

Former Member
0 Likes
1,482

Hi All,

I want to send mail by abap code. and call the function SO_DOCUMENT_SEND_API1.

But I can only send mail to the sap user.

And i can't send mail to the address such as '[email protected]'

So should I make some connection between the address and sap server?

1 ACCEPTED SOLUTION
Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
1,427

Hi

Alternately you can use the below peace of code:

form email_mat_master .

data: l_id type string.

loop at s_email.

g_email = s_email-low.

l_id = syst-sysid.

concatenate k_sap l_id k_ucb into g_sender.

call function 'EFG_GEN_SEND_EMAIL' exporting

i_title = 'KPI Report - Status'(046)

i_sender = g_sender

i_recipient = g_email

i_flg_commit = k_x

i_flg_send_immediately = k_x

tables

i_tab_lines = it_tab_soli

exceptions

not_qualified = 1

failed = 2

others = 3.

if sy-subrc <> 0.

write:/ sy-subrc.

endif.

if s_email-low ne space.

g_flag_email = 1.

endif.

endloop.

endform. " email_mat_master

Here for g_sender. you can define your own Email Address otherthan SAP.

Regards,

Sreeram

Hi All,

I want to send mail by abap code. and call the function SO_DOCUMENT_SEND_API1.

But I can only send mail to the sap user.

And i can't send mail to the address such as '[email protected]'

So should I make some connection between the address and sap server?

13 REPLIES 13
Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
1,428

Hi

Alternately you can use the below peace of code:

form email_mat_master .

data: l_id type string.

loop at s_email.

g_email = s_email-low.

l_id = syst-sysid.

concatenate k_sap l_id k_ucb into g_sender.

call function 'EFG_GEN_SEND_EMAIL' exporting

i_title = 'KPI Report - Status'(046)

i_sender = g_sender

i_recipient = g_email

i_flg_commit = k_x

i_flg_send_immediately = k_x

tables

i_tab_lines = it_tab_soli

exceptions

not_qualified = 1

failed = 2

others = 3.

if sy-subrc <> 0.

write:/ sy-subrc.

endif.

if s_email-low ne space.

g_flag_email = 1.

endif.

endloop.

endform. " email_mat_master

Here for g_sender. you can define your own Email Address otherthan SAP.

Regards,

Sreeram

Read only

Former Member
0 Likes
1,427

Hi Andrea,

You need to do some customization on SAP side.

Regards,

Younus

<b>Reward Helpful Answers:-)</b>

Read only

0 Likes
1,427

what customization should i do?

thanks,

Read only

Former Member
0 Likes
1,427

hi,

make the receiver-type = 'U' "instead of B (SAP USER) " tis is for internet address..

and give receiver name = '[email protected]',...

*Reciptents Mail Id

l_wa_recieve-receiver = '[email protected]'

l_wa_recieve-rec_type = 'U'.

APPEND l_wa_recieve TO l_it_recieve.

CLEAR l_wa_recieve.

and pass this table to receiver parameter

  • see this

P Private distribution list

C Shared distribution list

O SAPoffice user

B SAP user

U Internet address

X X.400 address

R SAP user in another SAP System

**88

rewards if useful

regards,

nazeer

Message was edited by:

nazeer shaik

Message was edited by:

nazeer shaik

Read only

0 Likes
1,427

I already tried, but it is not ok.

thank you,

Read only

0 Likes
1,427

Hi

Use this code and let me know if u face any issues.

I can help you out.

<b>call function 'EFG_GEN_SEND_EMAIL' exporting

i_title = 'KPI Report - Status'(046)

i_sender = g_sender

i_recipient = g_email

i_flg_commit = k_x

i_flg_send_immediately = k_x

tables

i_tab_lines = it_tab_soli

exceptions

not_qualified = 1

failed = 2

others = 3.

if sy-subrc <> 0.

write:/ sy-subrc.

endif.

if s_email-low ne space.

g_flag_email = 1.

endif.

endloop.

endform. " email_mat_master

Here for g_sender. you can define your own Email Address otherthan SAP</b>

Regards,

Sree

Read only

0 Likes
1,427

hi,

did you give 'U' instead of 'B" for receiver type.

see my above post.

If still not getting..

use this FM code.. I have use this FM and job success for me..

*Local work area

DATA : l_wa_content TYPE solisti1,

l_wa_document TYPE sodocchgi1,

l_wa_recieve TYPE somlreci1.

*Local internal table

DATA : l_it_content TYPE STANDARD TABLE OF solisti1,

l_it_recieve TYPE STANDARD TABLE OF somlreci1.

*Reciptents Mail Id

l_wa_recieve-receiver = l_v_smtpadr.

l_wa_recieve-rec_type = 'U'.

l_wa_recieve-com_type = 'SOTR'.

APPEND l_wa_recieve TO l_it_recieve.

CLEAR l_wa_recieve.

*Body of mail

CLEAR l_wa_content.

l_wa_content-line = 'Dear Customer,'.

APPEND l_wa_content TO l_it_content.

*Heading of the mail

l_wa_document-obj_name = 'test mail'.

l_wa_document-obj_langu = sy-langu.

l_wa_document-sensitivty = 'O'.

l_wa_document-priority = '1'.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = l_wa_document

document_type = 'RAW'

put_in_outbox = 'X'

commit_work = 'X'

TABLES

object_content = l_it_content

receivers = l_it_recieve

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.

dont forget to reward if useful

regards,

nazeer

Message was edited by:

nazeer shaik

Read only

0 Likes
1,427

Since now I am maintenaning the other's code.I don't want to make big changes.

Thank you very much,

Read only

0 Likes
1,427

hi,

If still you are not getting mails,

then go to Tcode SOST and check whether you mail is in waiting or failed..

If in waiting then wait for some more time..

If failed contact your basis group and request them to make a communication as sending mail communication failed ..

rewards if useful

regards,

nazeer

Read only

0 Likes
1,427

Here is the code. I think the define of receiver is the same to you.

FORM send_mail .

  • Internal Table declarations

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

i_tline TYPE TABLE OF tline WITH HEADER LINE,

i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,

i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_objbin LIKE solix OCCURS 0 WITH HEADER LINE,

i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

w_objhead TYPE soli_tab,

w_ctrlop TYPE ssfctrlop,

w_compop TYPE ssfcompop,

w_return TYPE ssfcrescl,

w_doc_chng TYPE sodocchgi1,

w_data TYPE sodocchgi1,

w_buffer TYPE string, "To convert from 132 to 255

  • Variables declarations

v_form_name TYPE rs38l_fnam,

v_len_in LIKE sood-objlen,

v_len_out LIKE sood-objlen,

v_len_outn TYPE i,

v_lines_txt TYPE i,

v_lines_bin TYPE i,

bin_file TYPE xstring,

num TYPE i,

xnum TYPE i.

CLEAR w_alv.

i_otf[] = g_job_output-otfdata[].

CLEAR g_job_output.

  • convert pdf

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

bin_file = bin_file

TABLES

otf = i_otf

lines = i_tline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

num = 0.

xnum = XSTRLEN( bin_file ).

WHILE num < xnum.

i_objbin-line = bin_file+num.

APPEND i_objbin.

num = num + 255.

ENDWHILE.

DESCRIBE TABLE i_objbin LINES v_lines_bin.

i_objtxt = 'Dear Supplier,'.

APPEND i_objtxt.

i_objtxt = space.

APPEND i_objtxt.

i_objtxt = 'See attached TTE payment notifications.' &

'Please do not reply to this address.'.

APPEND i_objtxt.

i_objtxt = space.

APPEND i_objtxt.

i_objtxt = 'If you have any questions please ' &

'call your TTE A/P contact'.

APPEND i_objtxt.

i_objtxt = space.

APPEND i_objtxt.

i_objtxt = 'Best regards,'.

APPEND i_objtxt.

i_objtxt = 'TTE Technologies.'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

  • Obj. to be transported not in binary form

CLEAR i_objpack-transf_bin.

  • Start line of object header in transport packet

i_objpack-head_start = 1.

  • Number of lines of an object header in object packet

i_objpack-head_num = 0.

  • Start line of object contents in an object packet

i_objpack-body_start = 1.

  • Number of lines of the object contents in an object packet

i_objpack-body_num = v_lines_txt.

  • Code for document class

i_objpack-doc_type = 'RAW'.

APPEND i_objpack.

  • Packing as PDF.

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 1.

i_objpack-body_start = 1.

i_objpack-body_num = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'Smartform'.

CONCATENATE w_regup-belnr '.pdf'

INTO i_objpack-obj_descr.

i_objpack-doc_size = v_lines_bin * 255.

APPEND i_objpack.

  • Document information.

w_doc_chng-obj_name = 'Advice'.

w_doc_chng-expiry_dat = sy-datum + 10.

w_doc_chng-obj_descr = 'Outbound Remittance Advice'.

w_doc_chng-sensitivty = 'F'. "Functional object

w_doc_chng-doc_size = v_lines_txt * 255.

  • e-mail receivers.

CLEAR i_reclist.

SELECT SINGLE a~smtp_addr INTO i_reclist-receiver

FROM adr6 AS a

JOIN lfa1 AS l

ON aaddrnumber = ladrnr

WHERE l~lifnr = w_reguh-lifnr.

IF sy-subrc NE 0.

w_alv-icon = '@0A@'.

w_alv-belnr = w_regup-belnr.

w_alv-lifnr = w_reguh-lifnr.

w_alv-text = 'Please maintain vendor address firstly!'.

APPEND w_alv TO i_alv.

EXIT.

ENDIF.

i_reclist-express = 'X'.

i_reclist-rec_type = 'U'. "Internet address

APPEND i_reclist.

  • Sending mail.

DATA: outbox TYPE sonv-flag VALUE 'X'.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_chng

put_in_outbox = outbox

TABLES

packing_list = i_objpack

object_header = w_objhead

contents_hex = i_objbin

contents_txt = i_objtxt

receivers = i_reclist

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.

ENDFORM. " send_mail

Read only

0 Likes
1,427

I go to SOST and check my mail. But I didn't find the mail.

And I can see it in the Outbox of Business Workplace.

Thanks,

Read only

0 Likes
1,427

If the mail does not exists in SOST means its has been sent..

regards,

nazeer.

Read only

Former Member
0 Likes
1,427

Hi,

Check the following link:

http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm

Hope this helps.

Reward if helpful/

Regards,

Sipra