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

Function module for sending EMAIL with TEXT

Former Member
0 Likes
1,050

Hi ,

I have a requirement to send e-mail with text and receipient in CC and TO along with SUBJECT.

I will be thankful if anybody can get me a sampl eocde for the same.

Thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
940

Hi,

Refer this FM

CALL FUNCTION 'Z_SMTP_SENDMAIL'

EXPORTING

msg_header = gs_msg_head

  • FROM_STR = '.'

  • I_COMMIT = 'X'

TABLES

zmsg_text = gt_msg_txt

zcc_array = gt_cc_array

  • ZBCC_ARRAY =

  • zto_array =

EXCEPTIONS

smtp_error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

4 REPLIES 4
Read only

Former Member
0 Likes
940

Hi,

Have u checked with SO_NEW_DOCUMENT_SEND_API1.

Regards,

Neelima.

Read only

Former Member
0 Likes
941

Hi,

Refer this FM

CALL FUNCTION 'Z_SMTP_SENDMAIL'

EXPORTING

msg_header = gs_msg_head

  • FROM_STR = '.'

  • I_COMMIT = 'X'

TABLES

zmsg_text = gt_msg_txt

zcc_array = gt_cc_array

  • ZBCC_ARRAY =

  • zto_array =

EXCEPTIONS

smtp_error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Read only

Former Member
0 Likes
940

HI Sanu,

Please Find the Sample Code Below.

PARAMETERS: psubject(40) type c default u2018Hellou2019,

p_email(40) type c default 'give the email address here' .

data: it_packing_list like sopcklsti1 occurs 0 with header line,

it_contents like solisti1 occurs 0 with header line,

it_receivers like somlreci1 occurs 0 with header line,

it_attachment like solisti1 occurs 0 with header line,

gd_cnt type i,

gd_sent_all(1) type c,

gd_doc_data like sodocchgi1,

gd_error type sy-subrc.

data: it_message type standard table of SOLISTI1 initial size 0

with header line.

***********************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

Perform populate_message_table.

*Send email message, although is not sent from SAP until mail send

*program has been executed(rsconn01)

PERFORM send_email_message.

*Instructs mail send program for SAPCONNECT to send email(rsconn01)

perform initiate_mail_execute_program.

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

*& Form POPULATE_MESSAGE_TABLE

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

  • Adds text to email text table

u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-

form populate_message_table.

Append u2018Email line 1u2032 to it_message.

Append u2018Email line 2u2032 to it_message.

Append u2018Email line 3u2032 to it_message.

Append u2018Email line 4u2032 to it_message.

endform. u201D POPULATE_MESSAGE_TABLE

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

*& Form SEND_EMAIL_MESSAGE

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

  • Send email message

u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-

form send_email_message.

  • Fill the document data.

gd_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = u2018SAPRPTu2019.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = u2018Fu2019.

  • Describe the body of the message

clear it_packing_list.

refresh it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

describe table it_message lines it_packing_list-body_num.

it_packing_list-doc_type = u2018RAWu2019.

append it_packing_list.

  • Add the recipients email address

clear it_receivers.

refresh it_receivers.

it_receivers-receiver = p_email.

it_receivers-rec_type = u2018Uu2019.

it_receivers-com_type = u2018INTu2019.

it_receivers-notif_del = u2018Xu2019.

it_receivers-notif_ndel = u2018Xu2019.

append it_receivers.

  • Call the FM to post the message to SAPMAIL

call function u2018SO_NEW_DOCUMENT_ATT_SEND_API1u2032

exporting

document_data = gd_doc_data

put_in_outbox = u2018Xu2019

importing

sent_to_all = gd_sent_all

tables

packing_list = it_packing_list

contents_txt = it_message

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

  • Store function module return code

gd_error = sy-subrc.

  • Get it_receivers return code

loop at it_receivers.

endloop.

endform. u201D SEND_EMAIL_MESSAGE

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014

  • Instructs mail send program for SAPCONNECT to send email.

u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-

form initiate_mail_execute_program.

wait up to 2 seconds.

if gd_error eq 0.

submit rsconn01 with mode = u2018INTu2019

with output = u2018Xu2019

and return.

endif.

endform. u201D INITIATE_MAIL_EXECUTE_PROGRAM

Hope this will be Helpful

Thanks

Kalyan

Read only

Former Member
0 Likes
940

Hi,

just use this FM

SO_NEW_DOCUMENT_SEND_API1 - Sends emails with texts.

Regards

Kiran