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

Mail sending problem

Former Member
0 Likes
1,155

**Perform Mail Sendings

PERFORM mail_sending.

***Perform Prepare Recipients

PERFORM add_recipient.

***Send the Mails to Recipients

PERFORM send_mail.

==================================

FORM mail_sending .

TRY.

  • Create persistent send request

send_request = cl_bcs=>create_persistent( ).

  • Create document

DESCRIBE TABLE t_MAILTEXT LINES num_rows.

num_rows = num_rows * 255.

MOVE num_rows TO textlength.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = t_MAILTEXT

i_length = textlength

i_subject = SUBJECT )

.

  • Add document to send request

CALL METHOD send_request->set_document( document ).

  • Get sender object

sender = cl_sapuser_bcs=>create( sy-uname ).

  • Add sender

CALL METHOD send_request->set_sender

EXPORTING

i_sender = sender.

CATCH cx_bcs INTO bcs_exception.

ENDTRY.

ENDFORM. " mail_sendin

===============================================

FORM add_recipient .

SELECT SINGLE * FROM PA0105 WHERE PERNR = P9090-PERNR .

TRY.

  • Create recipient

DATA: c_address TYPE adr6-smtp_addr.

MOVE PA0105-USRID_LONG TO c_address.

recipient = cl_cam_address_bcs=>create_internet_address(

c_address ).

  • Add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = ' '

i_copy = ' '

i_blind_copy = ' '.

CATCH cx_bcs INTO bcs_exception.

ENDTRY.

========================================================

FORM send_mail .

TRY.

  • Send document

CALL METHOD send_request->send( ).

COMMIT WORK.

CATCH cx_bcs INTO bcs_exception.

ENDTRY.

======================================================

this is the code which I am using for sending the mails .

I am able to see the mail in SOST transaction code . But in the sost the status is 'Still no entry in queue' , what may be the problem .

If any body has alternative code to send the amil please forwrd to 'raghavendra04@gmail.com' .

13 REPLIES 13
Read only

Former Member
0 Likes
1,110

Check this code it may help u.

FORM send_mail USING p_y16m_rcp_par STRUCTURE y16m_rcp_par.

  • Have a subject for the mail

g_s_document_data-obj_name = text-t02.

g_s_document_data-obj_descr = text-t03.

  • Fill receiver information

g_s_receivers-rec_type = p_y16m_rcp_par-rec_type.

g_s_receivers-rec_id = p_y16m_rcp_par-rec_id.

g_s_receivers-express = 'X'.

APPEND g_s_receivers TO g_t_receivers.

  • Call function to send mail

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = g_s_document_data

document_type = 'RAW'

  • PUT_IN_OUTBOX = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

  • OBJECT_HEADER =

object_content = g_t_object_content

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " SEND_MAIL

U have to maintain table p_y16m_rcp_par with email id.This just example u cna have different table also.

Regards

Read only

Former Member
0 Likes
1,110

Hi

You can also use SO_NEW_DOCUMENT_SEND_API1 which would be simple and if you need it with attachment use 'SO_NEW_DOCUMENT_att_SEND_API1'.

Regards,

Prashanth

Read only

0 Likes
1,110

hi,

sample code might look like this for FM :- SO_NEW_DOCUMENT_SEND_API1.

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

DATA g_s_object_content LIKE solisti1,

g_s_receivers LIKE somlreci1,

g_s_document_data LIKE sodocchgi1,

g_t_receivers LIKE somlreci1 OCCURS 1.

g_t_object_content LIKE solisti1 OCCURS 1.

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

PERFORM header_of_mail.

PERFORM body_of_mail.

PERFORM send_mail

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

FORM header_of_mail.

  • Get an empty line

MOVE space TO g_s_object_content+0(81).

APPEND g_s_object_content TO g_t_object_content.

  • Print partner number and description

CLEAR g_s_object_content.

MOVE text-t13 TO g_s_object_content. " WMS

MOVE sy-uline TO g_s_object_content+15(1).

MOVE g_f_wms_descr TO g_s_object_content+30.

APPEND g_s_object_content TO g_t_object_content.

ENDFORM

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

FORM send_mail USING p_y16m_rcp_par STRUCTURE y16m_rcp_par.

  • Have a subject for the mail

g_s_document_data-obj_name = text-t02.

g_s_document_data-obj_descr = text-t03.

  • Fill receiver information

CLEAR g_s_receivers.

REFRESH g_t_receivers.

g_s_receivers-rec_type = p_y16m_rcp_par-rec_type.

g_s_receivers-receiver = p_y16m_rcp_par-rec_id.

g_s_receivers-express = 'X'.

APPEND g_s_receivers TO g_t_receivers.

  • Call function to send mail

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = g_s_document_data

document_type = 'RAW'

  • PUT_IN_OUTBOX = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

  • OBJECT_HEADER =

object_content = g_t_object_content

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

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

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM.

Read only

Former Member
0 Likes
1,110

I WANT TO SEND MAIL TO OUTSIDE sap USER say xyz@yahoo.com . IF i USE THE FUNCTION MODULE WHAT ARE THE VALUES i SHOULD SUPLLY FOR RECIVER PARAMETER .,

I am picking the mail ID from PA0105 infotype .

Read only

0 Likes
1,110

after add receipient method call you need to call

call method send_request->set_send_immediately( 'X' ).

for complete code sample check out this link.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2...

Regards

Raja

Read only

0 Likes
1,110

I can help you in the OO method way of sending mail,

but if you want to know how to send the mail to external mail ids thru Function module,here is the link with the code.

check this once.

for internet ids: you should say,

RECTYP = 'U'.

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

Message was edited by: Srikanth Kidambi

Message was edited by: Srikanth Kidambi

Read only

0 Likes
1,110

HELLO SRIKANT

pLEASE HELP , HAVE A LOOK AT THE CODE WHICH i HAVE CODED AND LET ME KNOW IF ANY CORRECTION IS REQUIRED .

Read only

0 Likes
1,110

Did you read my post?

Raja

Read only

0 Likes
1,110

Dear Experts ,

I can see the sent mail in SOSt transaction but the mauil is not going to recipent . The mail is lying in the SOST with status 'Still no entry in queue' .

Read only

0 Likes
1,110

Yes Raja ,

I have read your post and done the modification in the program suggested by you .

Read only

0 Likes
1,110

Hello Raja , I have seen the Weblog posted by you and made all the modification .

Read only

0 Likes
1,110

then try out like this,

Goto SCOT transaction & click on the button 'START SEND PROCESS' which appears on application tool bar.

continue that step and then check in SOST ?

regards,

Srikanth

Read only

0 Likes
1,110

those mails are not coming to SCOT , but those can be seen in the SOST