Class CL_BCS sending email
Hello,
I am using the below code for sending a email with PDF attachment using CL_BCS, once i get the email i am also getting 2 other emails saying your email delivered and your email read, is there a way for not getting those delivered and read emails,
TRY.
SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
LP_PDF_SIZE = XSTRLEN( STRING ).
PDF_CONTENT = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX(
IP_XSTRING = STRING ).
CATCH CX_BCS INTO BCS_EXCEPTION.
RETURN-TYPE = 'E'.
RETURN-MESSAGE = BCS_EXCEPTION->ERROR_TYPE.
APPEND RETURN.
EXIT.
ENDTRY.
DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = 'RAW'
I_TEXT = L_BODY
i_hex = pdf_content
i_length = lp_pdf_size
I_SUBJECT = 'test' ).
CALL METHOD DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = L_EXTENSION
I_ATTACHMENT_SUBJECT = 'test''
I_ATTACHMENT_SIZE = LP_PDF_SIZE
I_ATT_CONTENT_HEX = PDF_CONTENT.
SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
I_ADDRESS_STRING = 'emailid'' ).
SEND_REQUEST->ADD_RECIPIENT( I_RECIPIENT = RECIPIENT
I_EXPRESS = ' '
I_COPY = ' '
I_BLIND_COPY = ' '
I_NO_FORWARD = ' ' ).
SENT_TO_ALL = SEND_REQUEST->SEND(
I_WITH_ERROR_SCREEN = 'X' ).
COMMIT WORK AND WAIT.
Transaction SCOT -> Settings -> Confirmation of receipt -> Set 'SAPConnect does not expect confirmation'
Similar Messages
-
BPEL 11g fault policy action java class not sending email
Hi All,
I am trying to attach fault policy to my bpel process. The fault conditions are working fine but the email part from the action class is not able to send email. The code execute properly , i can't see any error message in the log but I cant access the email in my inbox.
I am able to send email from using email bpel activity and also test work flow notification from em console.
I have used both the java options for sending email like javax.mail and oracle.sdp.messaging .
JAVA CODE FOR EMAIL javax.mail
public String handleFault(IFaultRecoveryContext iFaultRecoveryContext){
//Print Fault Meta Data to Console
System.out.println("****************Fault Metadata********************************");
System.out.println("Fault policy id: " + iFaultRecoveryContext.getPolicyId());
System.out.println("Fault type: " + iFaultRecoveryContext.getType());
System.out.println("Partnerlink: " + iFaultRecoveryContext.getReferenceName());
System.out.println("Port type: " + iFaultRecoveryContext.getPortType());
System.out.println("**************************************************************");
//print all properties defined in the fault-policy file
System.out.println("Properties Set for the Fault");
//Print Fault Details to Console if it exists
System.out.println("****************Fault Details********************************");
// if(iFaultRecoveryContext instanceof BPELFaultRecoveryContextImpl)
BPELFaultRecoveryContextImpl bpelCtx = (BPELFaultRecoveryContextImpl)iFaultRecoveryContext;
System.out.println("Fault: " + bpelCtx.getFault());
System.out.println("Activity: " + bpelCtx.getActivityName());
System.out.println("Composite Instance: " + bpelCtx.getCompositeInstanceId());
System.out.println("Composite Name: " + bpelCtx.getCompositeName());
System.out.println("***********************************************************");
try {
bpelCtx.addAuditTrailEntry("Sending Email...");
Map props = iFaultRecoveryContext.getProperties();
if (props != null && props.size() > 0) {
setFrom(getParameterValue((ArrayList)props.get("from")));
setTo(getParameterValue((ArrayList)props.get("to")));
setSubject(getParameterValue((ArrayList)props.get("subject")) + bpelCtx.getTitle());
setText(getParameterValue((ArrayList)props.get("text")) + "\n" + "BPEL Process Instance: " + bpelCtx.getInstanceId() + " needs intervention to recover from a technical exception: " + bpelCtx.getFault().getMessage() + ".\n" + "Check the Activities tab in the BPEL Management Console in order to resolve the error as soon as possible.\n" + "This message was automatically generated, please do not reply to it.");
setHost(getParameterValue((ArrayList)props.get("host")));
setPort(getParameterValue((ArrayList)props.get("port")));
bpelCtx.addAuditTrailEntry("to Email getFrom..."+getFrom());
bpelCtx.addAuditTrailEntry("to Email getTo..."+getTo());
bpelCtx.addAuditTrailEntry("to Email getText..."+getText());
bpelCtx.addAuditTrailEntry("to Email getHost..."+getHost());
bpelCtx.addAuditTrailEntry("to Email getPort..."+getPort());
Session mailSession = Session.getDefaultInstance(properties);
Message simpleMessage = new MimeMessage(mailSession);
bpelCtx.addAuditTrailEntry("to Email toAddresses2...");
InternetAddress fromAddress = new InternetAddress(from);
bpelCtx.addAuditTrailEntry("to Email fromAddress..."+fromAddress);
simpleMessage.setFrom(fromAddress);
String[] toAddresses = to.split(";");
if (toAddresses != null && toAddresses.length > 0)
bpelCtx.addAuditTrailEntry("to Email toAddresses3...");
InternetAddress[] toInternetAddresses =new InternetAddress[toAddresses.length];
for (int i = 0; i < toAddresses.length; i++)
bpelCtx.addAuditTrailEntry("to Email toAddresses4444..."+ toAddresses);
toInternetAddresses[i] = new InternetAddress(toAddresses[i]);
bpelCtx.addAuditTrailEntry("to Email toInternetAddresses..."+ toInternetAddresses[i]);
simpleMessage.setRecipients(RecipientType.TO,toInternetAddresses);
simpleMessage.setSubject(subject);
simpleMessage.setText(text);
Transport.send(simpleMessage);
bpelCtx.addAuditTrailEntry("After Email...");
} catch (Exception e) {
bpelCtx.addAuditTrailEntry("fault Message:" + e.getMessage());
//Custom Code to Log Fault to File/DB/JMS or send Emails etc.
return "Manual";
private String getParameterValue(ArrayList parameterList) {
String value = null;
if (parameterList != null && parameterList.size() > 0)
value = (String)parameterList.get(0);
return value;
JAVA CODE FOR EMAIL oracle.sdp.messaging
private void sendMail(IFaultRecoveryContext iFaultRecoveryContext) {
BPELFaultRecoveryContextImpl bpelCtx = (BPELFaultRecoveryContextImpl)iFaultRecoveryContext;
bpelCtx.addAuditTrailEntry("In sendMail...");
Map<String, Object> params = new HashMap<String, Object>();
// params.put(key, value); // if optional parameters need to be specified.
MessagingClient messagingClient;
try {
bpelCtx.addAuditTrailEntry("In sendMail111...");
messagingClient =
MessagingClientFactory.createMessagingClient(params);
Message newMessage = MessagingFactory.createMessage();
// newMessage.setContent(createEventPayload(iFaultRecoveryContext),"text/plain");
newMessage.setContent("Component Name :"+bpelCtx.getComponentName()+ "\n Instacne Id :"+bpelCtx.getComponentInstanceId()+
"\n Composite Instance Id :"+bpelCtx.getCompositeInstanceId()+ "\n Composite Name :" bpelCtx.getCompositeName()
"\n Activity name :"+bpelCtx.getActivityName() + "\n Activity Id :" bpelCtx.getActivityId() "\n ECID :" bpelCtx.getECID()
"\n Reference Name :"+bpelCtx.getReferenceName()+ "\n Title :" bpelCtx.getTitle()
"\n Fault :" + bpelCtx.getFault()+ "\n Port Name :"+bpelCtx.getPortType(), "text/plain");
bpelCtx.addAuditTrailEntry("In sendMail222...");
Address sender = MessagingFactory.createAddress(getFrom());
bpelCtx.addAuditTrailEntry("In sendMail sender..."+sender.toString());
bpelCtx.addAuditTrailEntry("from Email..."+getFrom());
String recipientsStr[] = to.split(";");
bpelCtx.addAuditTrailEntry("to Email..."+getTo());
bpelCtx.addAuditTrailEntry("In sendMail333...");
Address[] recipients = MessagingFactory.createAddress(recipientsStr);
bpelCtx.addAuditTrailEntry("In sendMail444...");
newMessage.addSender(sender);
messagingClient.registerAccessPoint(MessagingFactory.createAccessPoint(sender));
newMessage.addAllRecipients(recipients);
bpelCtx.addAuditTrailEntry("In sendMail5555...");
newMessage.getMessageInfo().setSession(MessageSessionType.INBOUND_SESSION);
newMessage.setSubject(getSubject());
bpelCtx.addAuditTrailEntry("Subject..."+getSubject());
String messageId = "";
bpelCtx.addAuditTrailEntry("In sendMail666...");
synchronized (this) {
bpelCtx.addAuditTrailEntry("In sendMail777...");
messageId = messagingClient.send(newMessage);
bpelCtx.addAuditTrailEntry("In sendMail888...");
Status[] statuses = messagingClient.getStatus(messageId);
bpelCtx.addAuditTrailEntry("In sendMail999...");
} catch (MessagingException e) {
bpelCtx.addAuditTrailEntry("inside exception email fault Message:" + e.getMessage());
//e.printStackTrace();
MESSAGES FROM SOA SERVER OUT LOG after test the bpel process:
===========================================
****************Fault?Metadata********************************
Fault?policy?id:?SimpleFaultPolicy
Fault?type:?bpel
Partnerlink:?Service1
Port?type:?{http://kacst.edu.sa/process/nstip/coPINotifyProcess}kacst_process_nstipCoPIMotifyProcess
Properties?Set?for?the?Fault
****************Fault?Details********************************
Fault:?com.oracle.bpel.client.BPELFault: faultName: {{http://schemas.oracle.com/bpel/extension}remoteFault}
messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage}
parts: {{
summary=<summary>Message Router for nstip/nstip_Pro_CoPiNotificationProcess!1.0*soa_084da522-a825-4aa6-9d1c-ca1d50b4595b is not able to process messages. The composite state is set to "off". The composite can be turned "on" by using the administrative consoles.</summary>
,detail=<detail><exception>Message Router for nstip/nstip_Pro_CoPiNotificationProcess!1.0*soa_084da522-a825-4aa6-9d1c-ca1d50b4595b is not able to process messages. The composite state is set to "off". The composite can be turned "on" by using the administrative consoles.</exception>
</detail>
,code=<code>env:Server</code>}
Activity:?Invoke1
Composite?Instance:?740332
Composite?Name:?TestBPELFaultPolicy
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
220 taisirsit.kacst.edu.sa ESMTP Sendmail 8.14.4+Sun/8.14.4; Fri, 12 Oct 2012 13:00:45 +0300 (AST)
DEBUG SMTP: connected to host "localhost", port: 25
EHLO taisirsit.kacst.edu.sa
250-taisirsit.kacst.edu.sa Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "EXPN", arg ""
DEBUG SMTP: Found extension "VERB", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "DELIVERBY", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 2.1.0 <[email protected]>... Sender ok
RCPT TO:<[email protected]>
250 2.1.5 <[email protected]>... Recipient ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 Enter mail, end with "." on a line by itself
From: [email protected]
To: [email protected]
Message-ID: <[email protected].sa>
Subject: SOA EXCEPTIONInstance #890381 of BPELProcess1
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Testing Email From Fault
BPEL Process Instance: 890381 needs intervention to recover from a technical exception: faultName: {{http://schemas.oracle.com/bpel/extension}remoteFault}
messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage}
parts: {{
summary=<summary>Message Router for nstip/nstip_Pro_CoPiNotificationProcess!1.0*soa_084da522-a825-4aa6-9d1c-ca1d50b4595b is not able to process messages. The composite state is set to "off". The composite can be turned "on" by using the administrative consoles.</summary>
,detail=<detail><exception>Message Router for nstip/nstip_Pro_CoPiNotificationProcess!1.0*soa_084da522-a825-4aa6-9d1c-ca1d50b4595b is not able to process messages. The composite state is set to "off". The composite can be turned "on" by using the administrative consoles.</exception>
</detail>
,code=<code>env:Server</code>}
Check the Activities tab in the BPEL Management Console in order to resolve the error as soon as possible.
This message was automatically generated, please do not reply to it.
250 2.0.0 q9CA0j30012424 Message accepted for delivery
QUIT
221 2.0.0 taisirsit.kacst.edu.sa closing connection
Details from Instance of BPEL PROCESS :
Started invocation of operation "process" on partner "Service1".
Oct 12, 2012 10:00:45 AM [FAULT RECOVERY] Invoked handleBPELFault on custom java action class "com.kacst.fault.CustomFaultHandler".
Oct 12, 2012 10:00:45 AM Sending Email...
Oct 12, 2012 10:00:45 AM to Email [email protected]
Oct 12, 2012 10:00:45 AM to Email [email protected]
Oct 12, 2012 10:00:45 AM to Email getText...Testing Email From Fault BPEL Process Instance: 890381 needs intervention to recover from a technical exception: faultName: {{http://schemas.oracle.com/bpel/extension}remoteFault} messageType: {{http://schemas.oracle.com/bpel/extension}RuntimeFaultMessage} parts: {{ summary=<summary>Message Router for nstip/nstip_Pro_CoPiNotificationProcess!1.0*soa_084da522-a825-4aa6-9d1c-ca1d50b4595b is not able to process messages. The composite state is set to "off". The composite can be turned "on" by using the administrative consoles.</summary> ,detail=<detail><exception>Message Router for nstip/nstip_Pro_CoPiNotificationProcess!1.0*soa_084da522-a825-4aa6-9d1c-ca1d50b4595b is not able to process messages. The composite state is set to "off". The composite can be turned "on" by using the administrative consoles.</exception> </detail> ,code=<code>env:Server</code>} . Check the Activities tab in the BPEL Management Console in order to resolve the error as soon as possible. This message was automatically generated, please do not reply to it.
Oct 12, 2012 10:00:45 AM to Email getHost...smtp.kacst.edu.sa
Oct 12, 2012 10:00:45 AM to Email getPort...25
Oct 12, 2012 10:00:45 AM to Email toAddresses2...
Oct 12, 2012 10:00:45 AM to Email [email protected]
Oct 12, 2012 10:00:45 AM to Email toAddresses3...
Oct 12, 2012 10:00:45 AM to Email [email protected]
Oct 12, 2012 10:00:45 AM to Email [email protected]
Oct 12, 2012 10:00:45 AM After Email...
Oct 12, 2012 10:00:45 AM [FAULT RECOVERY] Marked Invoke activity as "pending manual recovery".
Oct 12, 2012 10:00:45 AM Faulted while invoking operation "process" on provider "Service1".
Please suggest.
ThanksHi,
I got the solution. our email server is sending email to the mail accounts those are in the same domain but for different domains its not able to send the email.
you can try with the email those are created on the same email server.
Thanks
Tuku -
Issue with classes to send email
Hi guyz,
My requirement is to send smartform as an email as attachment in pdf format , I done it using function module SO_NEW_DOCUMENT_ATT_SEND_API1 , but the problem of using that is I cannot change senders email id. so now I chose the option to use classes , I have a code to send email with data in the email body, I also need to add smartform as an attachment in pdf format to email.How to get this...please advise...
Thanks in advance
Regards
Edited by: BrightSide on Jan 7, 2010 10:45 AMafter CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
CALL METHOD l_email->set_subject
EXPORTING
subject = v_subject.
* Set the message
CALL METHOD l_email->set_message
EXPORTING
text = i_content
type = zcl_email_message=>doc_type_text.
CALL METHOD l_email->add_attachment
EXPORTING
contents_bin = i_attach_raw
name = lv_name
type = 'BIN'.
CALL METHOD l_email->add_to
EXPORTING
address = i_rec. " fill i_rec with email id's u want to send the email.
* Send the e-mail.
CALL METHOD l_email->send
EXPORTING
commit_work = space
EXCEPTIONS
send_error = 1
OTHERS = 2. -
Sending email using CL_BCS in the background with subject line 255 chars
Hello Gurus,
Following is the sample code,. When I run in the foreground, I am getting the mail, with proper subject line. However my output medium type is '5-'External Send#. When I am trying to run this in my output program, it is resulting in dump.
When I keep 'COMMIT WORK', I am getting a dump saying tText * Invalid COMMIT WORK in an update function module.*
When I remove this 'COMMIT WORK', I am still getting the error, saying Screen output without connection to user. (The current ABAP program "SAPLSTXC" statements could not be executed.)
Hoping for a quick solution.
Regards,
Shaheen
REPORT Z_CL_BCS_TEST.
* Trying classes
DATA: send_request TYPE REF TO cl_bcs.
DATA: li_main_text TYPE bcsy_text,
lw_main_text LIKE LINE OF li_main_text.
DATA: document TYPE REF TO cl_document_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: sender TYPE REF TO if_sender_bcs.
DATA: l_mtitle LIKE sodocchgi1-obj_descr.
DATA: sent_to_all TYPE os_boolean.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA: lv_sub TYPE string.
TRY.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document---------------
* Email title
l_mtitle = 'attachment'.
lv_sub = 'Email Title : I want to try for a subject which is more than 50 chars. will this work?'.
CALL METHOD send_request->set_message_subject
EXPORTING
ip_subject = lv_sub.
* Fill the body of the mail
REFRESH li_main_text.
lw_main_text = 'This is test email'.
APPEND lw_main_text TO li_main_text.
CLEAR: lw_main_text.
lw_main_text = 'Regards'.
APPEND lw_main_text TO li_main_text.
CLEAR: lw_main_text.
* Create Email Object
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = li_main_text
i_subject = l_mtitle ).
* Add document object to send request
send_request->set_document( document ).
* add recipient (e-mail address)
recipient =
cl_cam_address_bcs=>create_internet_address(
'Shaheen.Taori at solvay.com' ). " changed the email id purposefully
* Add recipient object to send request
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'X'.
* ---------- send document ---------------------------------------
* sent_to_all = send_request->SEND_WITHOUT_DIALOG( I_WITH_ERROR_SCREEN = ' ').
CALL METHOD send_request->SEND_WITHOUT_DIALOG.
* EXPORTING
* e_sent_to_all = 'X'.
* IF sent_to_all IS INITIAL.
* MESSAGE 'Erorr while sending email ' TYPE 'E'.
* EXIT.
* ENDIF.
COMMIT WORK.
* exception handling
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.Try using method SEND instead of SEND_WITHOUT_DIALOG.
Also try calling method SET_SEND_IMMEDIATELY before calling method SEND.
Use below code lines,
send_request->set_send_immediately( i_send_immediately = 'X' ).
sent_to_all = send_request->send( i_with_error_screen = 'X' ). " Instead of CALL METHOD send_request->SEND_WITHOUT_DIALOG. -
Use of CL_BCS to send email in user exit
Hi,
I need some help from experts in this forum.
I use CL_BCS to send email if a certain condition is met inside a customer exit.
This exit is called before a confirmation dialog pop up asking whether we want to save or cancel.
I did not put commit work statement in this exit since it will commit all database update even though the transaction can still be canceled. Email will also be sent if the transaction is save. Hence, I'm relying on commit statement that come from the transaction itself.
However, this logic has create one problem for me.
If user hit cancel in the confirmation dialog that pop up after the exit is called, no commit will be executed. Hence, no email will be sent.
The problem is when the user change the data and re-save the data, there will be 2 email sent. One email come from the save action from the user and the other come from previous email that was not sent before due to no commit statement executed.
Is there any way to prevent this to happen? Please help.
PS: Points will be rewarded for those with helpful answer
Message was edited by:
Abraham BukitHi,
May be you use commit this way.
Create a custom function moudle , with you CL_BCS class codes and with comitt work inside and call the function in your userexit like
call function 'Y_CL_BCS_TRIGGER' " << Your function module name
starting new task yscchdr-docno
exporting
xxxxx = xxxxx
aRs -
CLASS cl_bcs Query for sender mail id
Hi,
I am using class cl_bcs.but, i am facing problem for sender mail-id. I want to append mail-id directly to sernder mail-id without using user mail attribute.
Is there ne way from which i can append mail-id as sender mail id??
thanx in advance,
Sameeryou can do that.
check this code sample.
DATA: sender TYPE REF TO if_sender_bcs.
CLEAR sender .
sender = cl_cam_address_bcs=>create_internet_address( '[email protected]' ).
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
and check this code sample for complete code.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5931ff64-0a01-0010-2bb7-ff2f9a6165a0
Regards
Raja -
Classes and methods to send email to SAP inbox
Hi,
I want an appropriate class and method to send emails to SAP Inbox.
My objective is that i convert spool to PDF and send it to SAP inbox as an attachment.
I've used 'CONVERT_ABAPSPOOLJOB_2_PDF' and 'SX_TABLE_LINE_WIDTH_CHANGE' to generate PDF attachment.
I tried Function modules 'SO_DOCUMENT_SEND_API1'/'SO_NEW_DOCUMENT_ATT_SEND_API1' to send email.
It was working fine till now (for last 4 months). Now the Basis team has run some patches due to which the PDFs are getting damaged.
Now the FMs 'SO_DOCUMENT_SEND_API1'/'SO_NEW_DOCUMENT_ATT_SEND_API1' seems to be useless.
So i tried some methods in classes cl_document_bcs and cl_bcs. These are working fine for Internet mails but not SAP mails.
Please suggest me some Classes and methods to send the PDF atachments to SAP inbox.to have all SAP inbox messages into lotus notes inbox you have to sync the same with the use of connectors rather than resending them
check out this link
http://www-128.ibm.com/developerworks/lotus/library/lei-sap/
for outlook its done using MAPI
http://www.sapgenie.com/faq/exchange.htm
Regards
Raja -
Email Dynamic Form as Attachment using class cl_bcs?
Hi Experts
I really hope that you can help me.
I have a dynamic form embedded in my view and I need to email this form as an attachment to a list of participants.
I already use the class cl_bcs for sending email, but how do I retrieve the form parameters (on button click within WD ABAP) and then convert them to the correct format so that they can be included in the cl_bcs class for sending?
Thanks in advance
I'll award points to helpful answers.
Anton KruseHI,
To send mail with PDF attachement,
U have to specify the emporting and exporting parameters for the Interactive Form in the SFP transaction.
Then add the below coding,
*Send mail in PDF format
Funtion module to get the generated FM name
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = lc_formname
IMPORTING
e_funcname = lv_fmname.
CATCH cx_fp_api_repository. "#EC NO_HANDLER
CATCH cx_fp_api_usage. "#EC NO_HANDLER
CATCH cx_fp_api_internal. "#EC NO_HANDLER
ENDTRY.
ls_param-nodialog = 'X'." suppress printer dialog popup
ls_param-getpdf = 'X'." launch print preview
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = ls_param
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
Do Nothing
ENDIF.
ls_fp_doc-langu = lc_sprsl.
ls_fp_doc-country = lc_country.
ls_fp_doc-fillable = 'X'.
Mail Format /1BCDWB/SM00000091
CALL FUNCTION lv_fmname
EXPORTING
/1bcdwb/docparams = ls_fp_doc
empno = ls_emp_det-empno
empname = ls_emp_det-empname
state = ls_emp_det-state
location = ls_emp_det-location
organisation = ls_emp_det-organisation
position = ls_emp_det-position
mailid = ls_emp_det-mailid
actual_date = ls_emp_det-actual_date
likely_date = ls_emp_det-likely_date
resig_date = ls_emp_det-resig_date
generic_det = lt_generic
bond_det = lt_bond
IMPORTING
/1bcdwb/formoutput = ls_formout
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
*do nothing.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
Do Nothing
ENDIF.
*Function call to get the xstring value.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = ls_formout-pdf
TABLES
binary_tab = lt_att_content_hex."PDF file from function module
lv_bodytext_row-line = lc_subject.
APPEND lv_bodytext_row TO lt_bodytext.
APPEND ' ' TO lt_bodytext.
lv_bodytext_row-line = text-001.
APPEND lv_bodytext_row TO lt_bodytext.
APPEND ' ' TO lt_bodytext.
DESCRIBE TABLE lt_bodytext LINES lv_num_rows.
lv_num_rows = lv_num_rows * 255.
MOVE lv_num_rows TO lv_textlength.
TRY.
lv_attdoctype = lc_pdf.
lv_atttitle = text-000.
lc_document = cl_document_bcs=>create_document(
i_type = lc_raw
i_text = lt_bodytext
i_length = lv_textlength
i_subject = lv_subject ).
lc_document->add_attachment( EXPORTING
i_attachment_type = lv_attdoctype
i_attachment_subject = lv_atttitle
i_attachment_language = sy-langu
i_att_content_hex = lt_att_content_hex ). This will attach ur PDF to mail
Create persistent send request
lv_send_request = cl_bcs=>create_persistent( ).
Add document to send request
lv_send_request->set_document( lc_document ).
lv_sender = cl_sapuser_bcs=>create( sy-uname ).
Add sender
CALL METHOD lv_send_request->set_sender
EXPORTING
i_sender = lv_sender.
CLEAR : ls_smtp_addr.
READ TABLE lt_mailid INTO ls_mailid WITH KEY pernr = ls_0001-pernr.
IF sy-subrc = 0.
ls_smtp_addr = ls_mailid-usrid_long.
ENDIF.
Create recipient.
lv_recipient = cl_cam_address_bcs=>create_internet_address(
ls_smtp_addr ).
Add recipient with its respective attributes to send request
lv_send_request->add_recipient( EXPORTING
i_recipient = lv_recipient
Set send immediately
lv_send_request->set_send_immediately( 'X' ).
Send document
lv_send_request->send( ).
CATCH cx_root INTO lv_oref. "#EC NO_HANDLER
ENDTRY.
Hope this ll help u!!
Thanks,
Divya.S -
Sending Email using cl_bcs from a badi implementation
Hi,
I have written my code to send Email, inside AFTER_SAVE method of BADI Implementation of DOCUMENT_MAIN01.
Now this method of cl_bcs requires COMMIT WORK for the mail to be sent. And inside BADI implementation, we cannot write a COMMIT statement.
What is a workaround for this? While going through few other posts, I came across remote enabled FMs.
Is that the only way? Can I use some additions like STARTING NEW TASK etc. Following is the call used in case of cl_bcs:
CALL METHOD G_REF_SEND_REQUEST->SEND(
EXPORTING
I_WITH_ERROR_SCREEN = 'X'
RECEIVING
RESULT = G_SENT_TO_ALL ).
I also tried using SO_NEW_DOCUMENT_SEND_API1 STARTING NEW TASK and it works fine. But the subject length is a constraint their.
Please suggest.
Thanks in advance.Hi friend.
*& Report ZTEST_273068_EMAIL_CL_BCS
REPORT ZTEST_273068_EMAIL_CL_BCS.
CONSTANTS:
gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS',
gc_raw TYPE char03 VALUE 'RAW'.
DATA:
gv_mlrec TYPE so_obj_nam,
gv_sent_to_all TYPE os_boolean,
gv_email TYPE adr6-smtp_addr,
gv_subject TYPE so_obj_des,
gv_text TYPE bcsy_text,
gr_send_request TYPE REF TO cl_bcs,
gr_bcs_exception TYPE REF TO cx_bcs,
gr_recipient TYPE REF TO if_recipient_bcs,
gr_sender TYPE REF TO cl_sapuser_bcs,
gr_document TYPE REF TO cl_document_bcs.
TRY.
"Create send request
gr_send_request = cl_bcs=>create_persistent( ).
"Email FROM...
gr_sender = cl_sapuser_bcs=>create( sy-uname ).
"Add sender to send request
CALL METHOD gr_send_request->set_sender
EXPORTING
i_sender = gr_sender.
"Email TO...
gv_email = '[email protected]'.
gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
"Add recipient to send request
CALL METHOD gr_send_request->add_recipient
EXPORTING
i_recipient = gr_recipient
i_express = 'X'.
"Email BODY
APPEND 'Hello world! My first ABAP email!' TO gv_text.
gr_document = cl_document_bcs=>create_document(
i_type = gc_raw
i_text = gv_text
i_length = '12'
i_subject = gc_subject ).
"Add document to send request
CALL METHOD gr_send_request->set_document( gr_document ).
"Send email
CALL METHOD gr_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = gv_sent_to_all ).
IF gv_sent_to_all = 'X'.
WRITE 'Email sent!'.
ENDIF.
"Commit to send email
COMMIT WORK.
"Exception handling
CATCH cx_bcs INTO gr_bcs_exception.
WRITE:
'Error!',
'Error type:',
gr_bcs_exception->error_type.
ENDTRY.
Just Execute it.
Regards,
Thrimu -
How to send a mail to sapuser using class cl_bcs
Hi to all experts,
i have send a mail to local sap user using the class cl_bcs .in the function module we gave reciever type as "B" to send to the local sapuser how to do this in this class cl_bcs.got it
we have to use rml address
recipient = cl_cam_address_bcs=>create_rml_address(
i_syst = sy-sysid
i_client = sy-mandt
i_username = sy-uname ). -
Send Method of Class Cl_BCS throwing exception
Hi Expert,
In a background job program ,we are triggering e-mail by using method SEND of Class CL_BCS.
It is working perfectly fine in quality system, but it is throwing an exception in production system and as result our background job is getting cancelled.
Could you please tell me what could be possible reason for this?
Code:
---------- send document ---------------------------------------
sent_to_all = send_request->send(
i_with_error_screen = 'X' ).
IF sent_to_all = 'X'.
message i022(so).
ENDIF.
* ---------- explicit 'commit work' is mandatory! ----------------
COMMIT WORK.
Thanks,
GirdhariHi,
I'd code that as follows:
data: lx_bcs type ref to cl_bcx .
try .
catch cx_bcs into lx_bcs.
cl_message_helper=>set_msg_vars_for_if_msg( lx_bcs ) .
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endtry .
However, the text would reveal more info only if the IDs are OTHERS or OS_ERROR, I believe... (at least on 702)
cheers,
Janis
Message was edited by: Jānis B
Or simply what Matthew wrote, of course. -
Send email ids from Class to Workflwo container
Hi All,
I have a workflow for sending emails, but i want to fetch these emails from a aztable.
For this purpose i have created a method in the ABAP aclass and written the code to fetch the emails ids .
In thw workflow i have created an activity step where i am calling this method. Now i want to pass the emails ids from the class to the task->workflow containers.
Please provide with the steps to achieve the same.
RadhikaHello,
Create a method in the BO which executes this method of the class (or) Write the same code present in the class method in the BOs method. Guess this would be a better option.
Pass the sending emails as an export parameter from the method. Create a task referring to this BO method and get the mail addresses into the task container and then to the workflow container. Once the entries are present in the container, you can use them in the sendmail step.
Hope this will help.
Regards,
Samson -
Is it possible to send text file with class cl_bcs
Hi,
i want to send a text file with class
cl_bcs but i dont know it is possible or not?
Thanks.no, it isn´
-
i am having internal table contains values.
i want that output should be send as an email attachment to email id given in selection screen.
but chinese can't diaplay rightly in attachment.eg:'批次; ','日期,and so on,all can't display rightly! .
please help me its urgent.thank you
*& Report YPD00010A
*& DEVELOPER/DATE : SJDU / 12.06.2007
*& REPORT: display barcodes which can't be updated in the sta
*& of x_ray
REPORT YPD00010A no standard page heading
line-count 90
line-size 120 .
selection-screen begin of block sel with frame.
PARAMETERS:
PA_WERKS LIKE YP043D-WERKS OBLIGATORY DEFAULT '8000',
PA_MAIL like ys054-mailaddress MATCHCODE OBJECT ZMAILADDRESS,
PA_MAIL1 like ys054-mailaddress MATCHCODE OBJECT ZMAILADDRESS,
PA_ZBAT like YP043D-ZBAT OBLIGATORY MATCHCODE OBJECT ZZBAT. "File
selection-screen end of block sel.
DATA: BEGIN OF Line1,
ZBARCD LIKE yp043d-zbarcd,
END OF Line1.
DATA: ta_yp043d like Line1 occurs 0 with header line.
data: begin of TAB,
X(1) type x value '09',
end of tab,
C(10) type c.
class cl_abap_char_utilities definition load.
c+5(1) = cl_abap_char_utilities=>horizontal_tab.
DATA:
it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER
LINE,
it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER
LINE.
data: p_email TYPE somlreci1-receiver .
data: p_email2 TYPE somlreci1-receiver .
DATA: TP_MAIL(255) TYPE C.
DATA: TP_MAIL_MAIN(255) TYPE C.
DATA: TP_MAIL_TMP(255) TYPE C.
DATA:
t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_doc_data LIKE sodocchgi1,
w_cnt TYPE I,
w_sent_all(1) TYPE C,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA:COUNT1 TYPE I VALUE 0,
COUNT2 TYPE I VALUE 0.
INITIALIZATION.
clear: ta_yp043d, it_attach, it_message.
REFRESH: ta_yp043d, it_attach, it_message.
START-OF-SELECTION.
PERFORM GET_DATA.
IF PA_MAIL <> ' ' OR PA_MAIL1 <> ' '.
READ TABLE TA_YP043D INDEX 1.
IF SY-SUBRC = 0 .
pERFORM SEND_EMAIL.
ENDIF.
ENDIF.
END-OF-SELECTION.
PERFORM GET_WRITEDATA.
TOP-OF-PAGE.
PERFORM GET_HEADER.
END-OF-PAGE.
*& Form GET_HEADER *
*& To display the header *
FORM GET_HEADER.
data:
tp_header(120) type c.
TP_HEADER = '山东公司条码表'.
WRITE:4 '程序序号:',10 'YPD00010', 42 tp_header,
92 '日期:',102 SY-DATUM+0(4),
106 '年',
108 SY-DATUM+4(2),110 '月',112 SY-DATUM+6(2),114 '日',
/92 '时间 :',SY-TIMLO,
/3 '上传凭证:',18 PA_ZBAT, 92 '页码 :', SY-PAGNO.
ULINE.
ENDFORM.
*& Form GET_DATA
* text
* --> p1 text
* <-- p2 text
FORM GET_DATA .
DATA:TP_ZBARCD LIKE YP043-ZBARCD,
TP_ZBARCD1 LIKE YP043-ZBARCD,
TP_ZVALS LIKE YP043D-ZVALS.
SELECT ZBARCD INTO CORRESPONDING FIELDS OF TABLE ta_yp043d FROM YP043D
WHERE WERKS = PA_WERKS AND ZBAT = PA_ZBAT
AND ZUPDS = 'N' AND ZVALS = 'B' AND ZLVORM <> 'X'.
ENDFORM. " GET_DATA
*& Form GET_WRITEDATA
* text
* --> p1 text
* <-- p2 text
FORM GET_WRITEDATA .
WRITE: /'硫化未上传的条码有:'.
SKIP.
LOOP AT TA_YP043D.
WRITE:TA_YP043D-ZBARCD,' '.
ENDLOOP.
ENDFORM. " GET_WRITEDATA
*& Form SEND_EMAIL
* text
* --> p1 text
* <-- p2 text
FORM SEND_EMAIL.
READ TABLE TA_YP043D INDEX 1.
IF SY-SUBRC = 0 .
* Retrieve sample data from table ekpo
* PERFORM DATA_RETRIEVAL.
* Populate table with detaisl to be entered into .htm file
PERFORM BUILD_XLS_DATA_TABLE.
* Populate message body text
PERFORM POPULATE_EMAIL_MESSAGE_BODY.
* Send file by email attached as .htm file
PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
TABLES it_message
it_attach
USING p_email
'条码系统出库有问题的条码'
'HTML'
'WC_Document'
CHANGING gd_error
gd_reciever.
* Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
ENDIF.
ENDFORM. " SEND_EMAIL
*& Form BUILD_XLS_DATA_TABLE
* text
* --> p1 text
* <-- p2 text
FORM BUILD_XLS_DATA_TABLE .
CONCATENATE '<' 'HTML' '>' INTO it_attach .
APPEND it_attach.
CONCATENATE '<' 'HEAD' '>' INTO it_attach .
APPEND it_attach.
CONCATENATE
'<meta http-equiv=Content-Type content=' '"' 'text/html; charset= GB2312
''"' '>' INTO it_attach.
APPEND it_attach.
CONCATENATE '<' '/HEAD' '>' INTO it_attach .
APPEND it_attach.
CONCATENATE '<P style=''font-size:12.0PT''><B> 批次:' pa_zbat
'</B></P>' INTO it_attach SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>horizontal_tab.
APPEND it_attach.
CONCATENATE '<P style=''font-size:12.0pt''><B> 日期:' sy-datum
'</B></P>' INTO it_attach SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>horizontal_tab.
APPEND it_attach.
CONCATENATE '<P style=''font-size:12.0pt''><B>' '硫化未上传的条码有: '
'</B></P>' INTO it_attach SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>horizontal_tab.
APPEND it_attach.
*CONCATENATE '<P style=''font-size:12.0pt''><B>' ' ' ' </B></P>' INTO
*it_attach.
*APPEND it_attach.
LOOP AT TA_YP043D .
*CONCATENATE '< style=''font-size:12.0pt''><B> ' TAB-ZBARCD '</B>'
CONCATENATE '<B> ' TA_YP043D-ZBARCD ' </B>' INTO
it_attach .
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& Form POPULATE_EMAIL_MESSAGE_BODY
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_EMAIL_MESSAGE_BODY .
DATA: TP_TEST0(255) TYPE C,
TP_TEST3(255) TYPE C,
TP_TEST(255) TYPE C.
TP_TEST = '当轮胎进行X光机数据上传时,有些条码在硫化阶段不存在资料'.
TP_TEST0 = '请您查看并尽快解决.'.
CONCATENATE TP_TEST TP_TEST0 INTO TP_TEST3 SEPARATED BY ' , '.
APPEND '尊敬的先生/女士,' TO it_message.
APPEND ' ' TO it_message.
APPEND TP_TEST3 TO it_message.
APPEND '具体问题请查看附件.' TO it_message.
APPEND ' ' TO it_message.
APPEND '谢谢.' TO it_message.
APPEND ' ' TO it_message.
APPEND '来自,' TO it_message.
APPEND SY-UNAME TO it_message.
ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT *
*& Send email *
FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES pit_message
pit_attach
USING p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
CHANGING p_error
p_reciever.
DATA:
ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_email2 LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver value
'[email protected]',
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: TMP_MAIL(40) TYPE C.
DATA: MAIN_EMAIL(40) TYPE C.
DATA: TMP_POS TYPE I .
DATA: ADD_EMAIL(40) TYPE C.
DATA: L_POS TYPE I, R_POS TYPE I, MAIL_LEN TYPE I.
ld_email = p_email.
ld_email2 = p_email2.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = pit_attach[].
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
TP_MAIL_MAIN = PA_MAIL.
TP_MAIL = PA_MAIL1.
if sy-subrc = 0 .
t_receivers-receiver = TP_MAIL_MAIN.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
ENDIF.
*READ FROM TP_MAIL LIST
TP_MAIL_TMP = TP_MAIL .
WHILE SY-SUBRC = 0 .
SEARCH TP_MAIL_TMP FOR ', ' .
MAIL_LEN = STRLEN( TP_MAIL_TMP ) .
IF SY-SUBRC = 0 .
TMP_POS = sy-fdpos .
ADD_EMAIL = TP_MAIL_TMP+0(TMP_POS) .
R_POS = TMP_POS + 2 .
L_POS = MAIL_LEN - TMP_POS .
TP_MAIL_TMP = TP_MAIL_TMP+R_POS(L_POS) .
ELSE.
ADD_EMAIL = TP_MAIL_TMP .
ENDIF.
t_receivers-receiver = ADD_EMAIL.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
t_receivers-COPY = 'X' .
APPEND t_receivers.
ENDWHILE.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = 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.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM. " SEND_FILE_AS_EMAIL_ATTACHMENT
*& Form INITIATE_MAIL_EXECUTE_PROGRAM *
*& Instructs mail send program for SAPCONNECT to send email *
FORM INITIATE_MAIL_EXECUTE_PROGRAM.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM
Message was edited by:
shanjing du
Message was edited by:
shanjing duTry the following.
You may need to add language parameter to "CALL METHOD cl_document_bcs=>create_document", or perhaps replace it with a call to the ADD_ATTACHMENT method or some other method of this class - there are public methods for text, MIME, office documents.
==================
*& Report ZLOCAL_EMAIL_TEST
Test of ECC Send email using class CL_BCS
REPORT zlocal_email_test.
DATA:
l_obj TYPE REF TO cl_bcs,
l_recip TYPE REF TO if_recipient_bcs,
l_rec TYPE REF TO cl_cam_address_bcs,
sender TYPE REF TO if_sender_bcs,
note TYPE bcsy_text,
line TYPE soli,
l_address TYPE adr6-smtp_addr,
l_result TYPE os_boolean,
l_sub TYPE string,
text TYPE bcsy_text,
document TYPE REF TO cl_document_bcs.
parameters: p_email like ADR6-SMTP_ADDR visible length 70,
p_uname like sy-uname default sy-uname.
START-OF-SELECTION.
Create email instance
l_obj = cl_bcs=>create_persistent( ).
Build text of message
APPEND 'Hello World' TO text.
APPEND 'Hello World 2' TO text.
APPEND 'Hello World 3' TO text.
APPEND 'Hello World 4' TO text.
Create the email document
CALL METHOD cl_document_bcs=>create_document
EXPORTING
i_type = 'RAW'
i_subject = 'subject line'
I_LENGTH =
I_LANGUAGE = SPACE
I_IMPORTANCE =
I_SENSITIVITY =
i_text = text
I_HEX =
I_HEADER =
I_SENDER =
RECEIVING
result = document.
Add document to email object
CALL METHOD l_obj->set_document
EXPORTING
i_document = document.
Short form version
CALL METHOD l_obj->set_document( document ).
Build long subject line
CONCATENATE 'Long subject' sy-abcde 'with still more'
'Long subject' sy-abcde 'with still more'
'Long subject' sy-abcde 'with still more'
INTO l_sub SEPARATED BY space.
Add long subject to the email
CALL METHOD l_obj->set_message_subject
EXPORTING
ip_subject = l_sub.
Get recipient address in correct format
CALL METHOD cl_cam_address_bcs=>create_internet_address
EXPORTING
i_address_string = p_email
RECEIVING
result = l_rec.
Add recipient address to the email
CALL METHOD l_obj->add_recipient
EXPORTING
i_recipient = l_rec
i_express = 'X'.
Get Sender address in correct format
CALL METHOD cl_sapuser_bcs=>create
EXPORTING
i_user = p_uname
RECEIVING
result = sender.
Short form version of this method call
sender = cl_sapuser_bcs=>create( sy-uname ).
Add sender to the email
CALL METHOD l_obj->set_sender
EXPORTING
i_sender = sender.
Send the email
CALL METHOD l_obj->send
EXPORTING
I_WITH_ERROR_SCREEN = SPACE
RECEIVING
result = l_result.
Required commit work.
COMMIT WORK. -
Help in sending email with attachment
Hi Experts,
I have developed a code which takes a pc file and change gets its binary content. later I am using the email send from class CL_BCS to send the mail.Its working very fine when I am executing it my Id, however it fails when I am using it as a background step in the workflow.Can anyone pls tell the reason
Thanks
PapiyaHi Papiya,
GUI_UPLOAD doesn't work in background since it involves the presentation server. You can only use the Application server in Background.
Do the following instead.
1. Create a file in AL11 ( By using CG3Y / CF3Z Transaction )
2. You can find the file in AL11 home. (Application server)
3. Open this file in your code using OPEN DATASET, READ DATASET, and CLOSE DATASET.
This will resolve your problem hopefully.
Vijay
Maybe you are looking for
-
License deactivated after restored from backup
I restored 3 servers from backup after my storage crashed. after restoring them, i noticed that the productID is shows not activated. i am running my servers off vmware vsphere 5.5. backup software is storagecraft virtual server edition. my servers i
-
How can I to number the book with CS5? . Has anyone the same difficulty?
Hi friends, Could you help me?. I need to number a book with Indesing CS5. I mean, I have differents documents und I want to mix in a book. With the previus I can number all the book and that's ok, but with the new version CS5 I can't. I 've been fo
-
Function module to get the difference of dates ..
Hi , Can somebody pls help me with the function module to get the difference between two dates? I need to find the difference value and delete records if >1. Thanks in advance. Regds, Leeza.
-
Non-system disk after installing Windows
Hello everyone, I have a rMBP15 inch (late 2013) and am running 10.10 Beta 2. I tried installing Windows 7 via bootcamp but it keeps failing on me. After going through the Bootcamp Assistant (and assigning how much space I want to give the bootcamp p
-
Project: Interactive CD-ROM Programs: Adobe 9 or Flash We will be creating and designing an interactive CD-ROM. The original document will be a word document. After designing and formatting the text, we will end up having a 100 page document. The end