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: 

Send Mail

Former Member
0 Kudos

I am using the following coding to send mail to user's workplace, when the program is executed, the user will popup to notify the new message arrived. But it can't work once the user log in. How can i also popup to notify when the user login. Thanks!

Besides, I would like to know how to send external mail. thanks!

MOVE: SY-UNAME TO RECEIVER-RECEIVER,

'X' TO RECEIVER-EXPRESS,

'B' TO RECEIVER-REC_TYPE.

APPEND RECEIVER.

  • Header

WRITE 'New Customer waiting for credit assignment' TO DOC_DATA-OBJ_DESCR.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_DATA

  • put_in_outbox = 'X'

IMPORTING

NEW_OBJECT_ID = OBJECT_ID

TABLES

OBJECT_CONTENT = OBJCONT

RECEIVERS = RECEIVER

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.

4 REPLIES 4

Former Member
0 Kudos

REPORT zsendemail .

PARAMETERS: psubject(40) type c default u2018Hellou2019,

p_email(40) type c default

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

Former Member
0 Kudos

for external mail use bewlo code

reclist-receiver = mail id .

reclist-rec_type = 'U'.

APPEND reclist.

Former Member
0 Kudos

Hi ,

try using this

FUNCTION z_ess_send_mail.

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(SUBJECT) TYPE STRING OPTIONAL

*" VALUE(PERNR) TYPE PRELP-PERNR

*" TABLES

*" IT_MESSAGE STRUCTURE SOLISTI1

*" EXCEPTIONS

*" MAIL_NOT_SENT

*"----


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

  • WORK AREA DECLARATIONS.

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

DATA: wa_p0105 TYPE p0105,

wa_packing_list TYPE sopcklsti1,

wa_receivers TYPE somlreci1.

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

  • INTERNAL TABLE DECLARATIONS.

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

DATA: "internal table for Description of Imported Object Components

it_packing_list TYPE STANDARD TABLE OF sopcklsti1 INITIAL SIZE 0 ,

"internal table for Recipient List

it_receivers TYPE STANDARD TABLE OF somlreci1 INITIAL SIZE 0 ,

"internal table for getting the userid.

it_p0105 TYPE STANDARD TABLE OF p0105.

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

  • VARIABLE DECLARATIONS.

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

DATA: lv_sent_all(1) TYPE c,

lv_error TYPE sy-subrc,

lv_email(40) TYPE c,

lv_doc_data TYPE sodocchgi1,

lv_sender_address TYPE soextreci1-receiver VALUE

"senders mail id

lv_sender_address_type TYPE soextreci1-adr_typ VALUE 'INT'.

DATA: new_object_id TYPE sofolenti1-object_id.

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

    • FUNCTION MODULE TO FETCH THE DATA FROM INFOTYPE 0105

CALL FUNCTION 'HR_READ_INFOTYPE'

EXPORTING

  • tclas = 'A'

pernr = pernr

infty = '0105'

  • begda = ' '

  • endda = ' '

  • BYPASS_BUFFER = ' '

  • LEGACY_MODE = ' '

  • IMPORTING

  • SUBRC =

TABLES

infty_tab = it_p0105

EXCEPTIONS

infty_not_found = 1

OTHERS = 2

.

" Sorting by begda and reading the latest user id .

SORT it_p0105 BY begda DESCENDING.

READ TABLE it_p0105 INTO wa_p0105 WITH KEY subty = '0010'.

IF wa_p0105-usrid_long NE ' '.

lv_email = wa_p0105-usrid_long. "Variable for storing lastest user id.

ELSE.

" error message .

MESSAGE i000(zhr_errmsg).

EXIT.

ENDIF.

CLEAR wa_p0105.

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

  • Send email message.

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

  • Fill the document data.

lv_doc_data-priority = '1'.

  • Populate the subject/generic message attributes

lv_doc_data-obj_langu = sy-langu.

lv_doc_data-obj_name = 'SAPRPT'.

lv_doc_data-obj_descr = subject.

lv_doc_data-sensitivty = 'F'.

  • Describe the body of the message

CLEAR it_packing_list.

REFRESH it_packing_list.

wa_packing_list-transf_bin = space.

wa_packing_list-head_start = 1.

wa_packing_list-head_num = 0.

wa_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES wa_packing_list-body_num.

wa_packing_list-doc_type = 'RAW'.

APPEND wa_packing_list TO it_packing_list.

CLEAR wa_packing_list.

  • Add the recipients email address

CLEAR it_receivers.

REFRESH it_receivers.

wa_receivers-receiver = lv_email.

wa_receivers-rec_id = lv_email."changes

wa_receivers-rec_type = 'U'.

wa_receivers-com_type = 'INT'.

wa_receivers-notif_del = 'X'.

wa_receivers-notif_ndel = 'X'.

APPEND wa_receivers TO it_receivers.

CLEAR wa_receivers.

****Function module for sending document

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = lv_doc_data

put_in_outbox = 'X'

sender_address = lv_sender_address

sender_address_type = lv_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = lv_sent_all

new_object_id = new_object_id

  • SENDER_ID =

TABLES

packing_list = it_packing_list

  • OBJECT_HEADER =

  • CONTENTS_BIN =

contents_txt = it_message

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

lv_error = sy-subrc.

  • Get it_receivers return code

LOOP AT it_receivers INTO wa_receivers.

ENDLOOP.

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

**initiate mail execution

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

WAIT UP TO 2 SECONDS.

IF lv_error EQ 0.

MESSAGE i002(zhr_errmsg).

ELSE.

MESSAGE i003(zhr_errmsg).

ENDIF.

ENDFUNCTION.

this would definitely help u

Edited by: Amit Saini on Dec 9, 2008 10:18 AM

Former Member
0 Kudos
  • Mail Contents

refresh objtxt[].

objtxt = space.

APPEND objtxt.

objtxt = 'Dear Sir/Madam,'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

CLEAR : sub.

CONCATENATE 'Sub: Dispatch Details - Invoice Number :' invno '.' INTO sub SEPARATED BY space.

objtxt = sub.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

objtxt = 'Note: Please cover insurance on all risks in case INCO TERMS as "EXW, FCA, FOB, CFR"'.

APPEND objtxt.

objtxt = 'in the subject consignment.'.

APPEND objtxt.

  • Determining the Email Ids of Mail Receivers

PERFORM fetch_mailids.

objtxt = 'Copy to :'.

APPEND objtxt.

LOOP AT reclist.

objtxt = reclist-receiver.

APPEND objtxt.

ENDLOOP.

objtxt = space.

APPEND objtxt.

objtxt = '<This is system generated message>.'.

APPEND objtxt.

objtxt = space.

APPEND objtxt.

  • Mail Body of message over.

DESCRIBE TABLE objtxt[] LINES v_lines_txt.

CONCATENATE 'Inv.' invno INTO sub SEPARATED BY space.

doc_chng-obj_name = sub.

doc_chng-expiry_dat = sy-datum + 10.

  • Mail Subject

refresh objpack[].

CONCATENATE 'Pricol Dispatch - Invoice' invno '- Reg.' INTO sub SEPARATED BY space.

doc_chng-obj_descr = sub.

doc_chng-sensitivty = 'F'.

doc_chng-doc_size = v_lines_txt * 255.

objpack-transf_bin = ' '.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = v_lines_txt.

objpack-doc_type = 'RAW'.

APPEND objpack.

*PDF Attachment

DESCRIBE TABLE so_ali[] LINES lineno.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-doc_size = lineno * 255 .

objpack-body_num = lineno.

objpack-doc_type = 'PDF'.

objpack-obj_name = 'INVOICE'.

objpack-obj_descr = 'Invoice'.

objpack-obj_langu = 'E'.

APPEND objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = objpack

contents_txt = objtxt[]

contents_bin = so_ali[]

*contents_hex = so_ali[]

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

IF sy-subrc = 0.

SUBMIT RSCONN01 WITH MODE = 'INT'.

ENDIF.