How to send Java Mail with EXCEL attachment?
I tried the following:
ByteArrayDataSource bs = new ByteArrayDataSource (is, "application/excel");
as my datasource (all other apis are fine)
But when I send this message with this datasource as attachment,I get a ParseException with the VM complaining about malformed headers.
Please help
Exactly when do you get the ParseException, and what's the message
with the exception?
BTW, "application/excel" is not the correct MIME type for Microsoft Office
Excel files. The correct MIME type is "application/vnd.ms-excel".
http://www.iana.org/assignments/media-types/application/vnd.ms-excel
Similar Messages
-
How to send a mail with PDF attachment
Hello
Good Day!
We have a requirement to send the mail with pdf attachment. Pdf file will be remain same for all mails and it will be placed at server. We are on R12.4 and below is the database information :
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Thanks a ton for your anticipated help!
Thanks
GauravThe word URGENT is considered as rude in this forum.. Nobody here is getting paid for the ansers they are giving..
Just have a look at These threads.Those will help you. -
How to send Java mail with attachment?
Could you please provide the sample codes using the javax.mail api for sending an email with an attachment?
this is code
zareen abbas
<html><body><center>
<FORM ACTION="/servlet/Attach" method="post">
<!--I didn,t used this ENCTYPE-->
<!--ENCTYPE="multipart/form-data" -->
<table border=0 bgcolor background="#00000">
<tr><td><font size=4> <b>From: </b> </font> </td>
<td><input type=text name=from size=40></td></tr>
<tr><td><font size=4> <b>To : </b> </font> </td>
<td><input type=text name=to size=40> </td></tr>
<tr><td><font size=4> <b>CC : </b> </font> </td>
<td><input type=text name=cc size=40> </td></tr>
<tr><td><font size=4> <b>BCC : </b> </font> </td>
<td><input type=text name=bcc size=40> </td></tr>
<tr><td><font size=4> <b>Subject : </b> </font> </td>
<td><input type=text name=subject size=40> </td></tr>
<tr><td><font size=4> <b>Body : </b> </font> </td>
<td><textarea name=body rows=15 cols=40> </textarea> </td></tr>
</table>
<p>Select a file:<input type=file name=attach>
<input type=submit value="send">
<input type=reset name=reset1
value="Clear"></Form></center></body></html>
here the servlet code
File file = new File(filename);
if (file.exists())
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(text);
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
message.setContent(mp);
else
message.setText(text);
Transport.send(message); -
How to send e-mail with an attachment from remote database server.???
Hi All,
I have tried the simple mail sending and with the attachment using UTL_SMTP. But the problem is , it is sending the mail with attachment of the file name i give, it takes and creates that file and sends as attachment not from the actual file location. I am trying to attach the file which i stored in remote database server.
The following code I tried. But not worked for attachment
DECLARE
v_From VARCHAR2(80) := '[email protected]';
v_Recipient VARCHAR2(80) := '[email protected]';
v_Subject VARCHAR2(80) := 'test subject';
v_Mail_Host VARCHAR2(30) := 'pop3.somedomain.com';
v_Mail_Conn utl_smtp.Connection;
crlf VARCHAR2(2) := chr(13)||chr(10);
BEGIN
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Data(v_Mail_Conn,
'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
'From: ' || v_From || crlf ||
'Subject: '|| v_Subject || crlf ||
'To: ' || v_Recipient || crlf ||
'MIME-Version: 1.0'|| crlf || -- Use MIME mail standard
'Content-Type: multipart/mixed;'|| crlf ||
' boundary="-----SECBOUND"'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'Content-Type: text/html;'|| crlf ||
'Content-Transfer_Encoding: 7bit'|| crlf ||
crlf ||
'some message text'|| crlf || -- Message body
'more message text'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'Content-Type: text/html;'|| crlf ||
' name="Fund Authorization report"'|| crlf ||
'Content-Transfer_Encoding: 8bit'|| crlf ||
'Content-Disposition: attachment;'|| crlf ||
' filename="/usr/tmp/Test.html"'|| crlf ||
crlf ||
'HTML Attachment'|| crlf || -- Content of attachment
crlf ||
'-------SECBOUND--' -- End MIME mail
utl_smtp.Quit(v_mail_conn);
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
END;How can I attach a file which is stored in database server and send it in a mail.
Please someone help me in this.
Thanks,
Alaka.Try this code
Regards Salim.
CREATE OR REPLACE TRIGGER EmailOnServerErr AFTER SERVERERROR ON DATABASE
DECLARE
mail_conn UTL_SMTP.connection;
crlf VARCHAR2(2) := chr(13)||chr(10);
msg VARCHAR2(32760);
sid_name VARCHAR2(16);
bdump_dest VARCHAR2(128);
smtp_relay VARCHAR2(32) := 'MyMailRelay';
recipient_address VARCHAR2(64) := '[email protected]';
sender_address VARCHAR2(64) := '[email protected]';
mail_port NUMBER := 25;
log_file_handle UTL_FILE.FILE_TYPE;
log_file_dir VARCHAR2(256) := 'ERR_LOG_DIR';
log_file_name VARCHAR2(256) := 'OracleErrors.log';
maxlinesize NUMBER := 32767;
session_rec sys.v_$session%ROWTYPE;
audit_rec sys.dba_audit_trail%ROWTYPE;
auditing BOOLEAN;
LinesOfSQL BINARY_INTEGER;
offending_sql DBMS_STANDARD.ora_name_list_t;
CURSOR bdump_cur IS
SELECT TRIM(value)
FROM v$parameter
WHERE name = 'background_dump_dest'
CURSOR sid_cur IS
SELECT TRIM(instance_name)
FROM v$instance
CURSOR session_cur IS
SELECT s.*
FROM v$session s
WHERE s.sid = dbms_support.mysid
CURSOR audit_trail_cur(AUDSID IN NUMBER) IS
SELECT *
FROM dba_audit_trail
WHERE sessionid = AUDSID
BEGIN
IF (USER = 'SYSTEM' OR USER = 'SYS') THEN
-- Ignore this error
NULL;
ELSIF IS_SERVERERROR (1034) THEN
-- Ignore this error
NULL;
ELSE
-- get the sid
OPEN sid_cur;
FETCH sid_cur INTO sid_name;
CLOSE sid_cur;
-- get the location of the alert log
OPEN bdump_cur;
FETCH bdump_cur INTO bdump_dest;
CLOSE bdump_cur;
-- get the session information
OPEN session_cur;
FETCH session_cur INTO session_rec;
CLOSE session_cur;
-- get the audit_trail information if it exists
OPEN audit_trail_cur(session_rec.audsid);
FETCH audit_trail_cur INTO audit_rec;
auditing := audit_trail_cur%FOUND;
CLOSE audit_trail_cur;
IF session_rec.program = 'MyProgram.exe' THEN
NULL; -- ignore actions from MyProgram - that's where I do maintenance
ELSE
-- compose the message
msg := 'Subject: Oracle error '||' on '||sid_name||crlf;
msg := msg||'To: '||recipient_address||crlf;
msg := msg||'For more information see the alert log file located at:'||crlf;
msg := msg||bdump_dest||'/alert_'||sid_name||'.log'||crlf;
msg := msg||'or the error log file: $'||log_file_dir||'/'||log_file_name||crlf;
msg := msg||'Error Time='||TO_CHAR(SYSDATE,'DD-Mon-YYYY HH24:MI:SS')||crlf;
msg := msg||DBMS_UTILITY.FORMAT_CALL_STACK||crlf;
LinesOfSQL := sql_txt(offending_sql);
msg := msg||'Offending SQL is:'||crlf;
FOR loop_counter IN offending_sql.FIRST..offending_sql.LAST
LOOP
msg := msg||offending_sql(loop_counter);
END LOOP;
msg := msg||crlf||'----- PL/SQL Error Stack -----'||crlf;
msg := msg||DBMS_UTILITY.FORMAT_ERROR_STACK||crlf;
msg := msg||'V$SESSION.SADDR=' ||session_rec.saddr ||crlf;
msg := msg||'V$SESSION.SID=' ||session_rec.sid ||crlf;
msg := msg||'V$SESSION.SERIAL#=' ||session_rec.serial# ||crlf;
msg := msg||'V$SESSION.AUDSID=' ||session_rec.audsid ||crlf;
msg := msg||'V$SESSION.PADDR=' ||session_rec.paddr ||crlf;
msg := msg||'V$SESSION.USER#=' ||session_rec.user# ||crlf;
msg := msg||'V$SESSION.USERNAME='||session_rec.username||crlf;
msg := msg||'V$SESSION.COMMAND=' ||session_rec.command ||crlf;
msg := msg||'V$SESSION.OWNERID=' ||session_rec.ownerid ||crlf;
msg := msg||'V$SESSION.TADDR=' ||NVL(session_rec.taddr ,'Null')||crlf;
msg := msg||'V$SESSION.LOCKWAIT='||NVL(session_rec.lockwait,'Null')||crlf;
msg := msg||'V$SESSION.STATUS=' ||NVL(session_rec.status ,'Null')||crlf;
msg := msg||'V$SESSION.SERVER=' ||NVL(session_rec.server ,'Null')||crlf;
msg := msg||'V$SESSION.SCHEMA#=' ||session_rec.schema#||crlf;
msg := msg||'V$SESSION.SCHEMANAME=' ||NVL(session_rec.schemaname,'Null')||crlf;
msg := msg||'V$SESSION.OSUSER=' ||NVL(session_rec.osuser ,'Null')||crlf;
msg := msg||'V$SESSION.PROCESS=' ||NVL(session_rec.process ,'Null')||crlf;
msg := msg||'V$SESSION.MACHINE=' ||NVL(session_rec.machine ,'Null')||crlf;
msg := msg||'V$SESSION.TERMINAL=' ||NVL(session_rec.terminal ,'Null')||crlf;
msg := msg||'V$SESSION.PROGRAM=' ||NVL(session_rec.program ,'Null')||crlf;
msg := msg||'V$SESSION.TYPE=' ||NVL(session_rec.type ,'Null')||crlf;
msg := msg||'V$SESSION.SQL_ADDRESS=' ||session_rec.sql_address ||crlf;
msg := msg||'V$SESSION.SQL_HASH_VALUE=' ||NVL(TO_CHAR(session_rec.sql_hash_value) ,'Null')||crlf;
msg := msg||'V$SESSION.PREV_SQL_ADDR=' ||session_rec.prev_sql_addr||crlf;
msg := msg||'V$SESSION.PREV_HASH_VALUE='||NVL(TO_CHAR(session_rec.prev_hash_value),'Null')||crlf;
msg := msg||'V$SESSION.MODULE=' ||NVL(session_rec.module ,'Null')||crlf;
msg := msg||'V$SESSION.MODULE_HASH='||NVL(TO_CHAR(session_rec.module_hash),'Null')||crlf;
msg := msg||'V$SESSION.ACTION=' ||NVL(session_rec.action ,'Null')||crlf;
msg := msg||'V$SESSION.ACTION_HASH='||NVL(TO_CHAR(session_rec.action_hash),'Null')||crlf;
msg := msg||'V$SESSION.CLIENT_INFO='||NVL(session_rec.client_info ,'Null')||crlf;
msg := msg||'V$SESSION.FIXED_TABLE_SEQUENCE='||NVL(TO_CHAR(session_rec.fixed_table_sequence),'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_OBJ#=' ||NVL(TO_CHAR(session_rec.row_wait_obj#) ,'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_FILE#=' ||NVL(TO_CHAR(session_rec.row_wait_file#) ,'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_BLOCK#='||NVL(TO_CHAR(session_rec.row_wait_block#),'Null')||crlf;
msg := msg||'V$SESSION.ROW_WAIT_ROW#=' ||NVL(TO_CHAR(session_rec.row_wait_row#) ,'Null')||crlf;
msg := msg||'V$SESSION.LOGON_TIME=' ||NVL(TO_CHAR(session_rec.logon_time,'DD-Mon-YYYY HH24:MI:SS'),'Null')||crlf;
msg := msg||'V$SESSION.LAST_CALL_ET=' ||NVL(TO_CHAR(session_rec.last_call_et) ,'Null')||crlf;
msg := msg||'V$SESSION.PDML_ENABLED=' ||NVL(session_rec.pdml_enabled ,'Null')||crlf;
msg := msg||'V$SESSION.FAILOVER_TYPE=' ||NVL(session_rec.failover_type ,'Null')||crlf;
msg := msg||'V$SESSION.FAILOVER_METHOD='||NVL(session_rec.failover_method,'Null')||crlf;
msg := msg||'V$SESSION.FAILED_OVER=' ||NVL(session_rec.failed_over ,'Null')||crlf;
msg := msg||'V$SESSION.RESOURCE_CONSUMER_GROUP='||NVL(session_rec.resource_consumer_group,'Null')||crlf;
msg := msg||'V$SESSION.PDML_STATUS=' ||NVL(session_rec.pdml_status ,'Null')||crlf;
msg := msg||'V$SESSION.PDDL_STATUS=' ||NVL(session_rec.pddl_status ,'Null')||crlf;
msg := msg||'V$SESSION.PQ_STATUS=' ||NVL(session_rec.pq_status ,'Null')||crlf;
IF auditing THEN
msg := msg||'DBA_AUDIT_TRAIL.OS_USERNAME=' ||NVL(audit_rec.os_username,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.USERNAME=' ||NVL(audit_rec.username ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.USERHOST=' ||NVL(audit_rec.userhost ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.TERMINAL=' ||NVL(audit_rec.terminal ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.TIMESTAMP=' ||TO_CHAR(audit_rec.timestamp,'DD-Mon-YYYY HH24:MI:SS')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.OWNER=' ||NVL(audit_rec.owner ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.OBJ_NAME=' ||NVL(audit_rec.obj_name ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ACTION=' ||audit_rec.action ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ACTION_NAME=' ||NVL(audit_rec.action_name ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.NEW_OWNER=' ||NVL(audit_rec.new_owner ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.NEW_NAME=' ||NVL(audit_rec.new_name ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.OBJ_PRIVILEGE='||NVL(audit_rec.obj_privilege ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.SYS_PRIVILEGE='||NVL(audit_rec.sys_privilege ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ADMIN_OPTION=' ||NVL(audit_rec.admin_option ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.GRANTEE=' ||NVL(audit_rec.grantee ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.AUDIT_OPTION=' ||NVL(audit_rec.audit_option ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.SES_ACTIONS=' ||NVL(audit_rec.ses_actions ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_TIME=' ||NVL(TO_CHAR(audit_rec.logoff_time) ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_LREAD=' ||NVL(TO_CHAR(audit_rec.logoff_lread) ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_PREAD=' ||NVL(TO_CHAR(audit_rec.logoff_pread) ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_LWRITE='||NVL(TO_CHAR(audit_rec.logoff_lwrite),'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.LOGOFF_DLOCK=' ||NVL(audit_rec.logoff_dlock ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.COMMENT_TEXT=' ||NVL(audit_rec.comment_text ,'Null')||crlf;
msg := msg||'DBA_AUDIT_TRAIL.SESSIONID=' ||audit_rec.sessionid ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.ENTRYID=' ||audit_rec.entryid ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.STATEMENTID=' ||audit_rec.statementid ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.RETURNCODE=' ||audit_rec.returncode ||crlf;
msg := msg||'DBA_AUDIT_TRAIL.PRIV_USED=' ||NVL(audit_rec.priv_used,'Null')||crlf;
END IF;
msg := msg||'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-'||crlf||crlf;
-- write the message to the error log file
log_file_handle := UTL_FILE.FOPEN (log_file_dir, log_file_name, 'A',maxlinesize);
UTL_FILE.PUT_LINE(log_file_handle,msg);
UTL_FILE.FCLOSE(log_file_handle);
-- send the message by Email
mail_conn := UTL_SMTP.open_connection(smtp_relay, mail_port);
UTL_SMTP.HELO(mail_conn, smtp_relay);
UTL_SMTP.MAIL(mail_conn, sender_address);
UTL_SMTP.RCPT(mail_conn, recipient_address);
UTL_SMTP.DATA(mail_conn, msg);
UTL_SMTP.QUIT(mail_conn);
END IF; -- client_program = MyProgram.exe
END IF;
END;
/ -
Issue in sending e mails with Excel attachment
Hi,
I am facing an issue with one function module - SO_DOCUMENT_SEND_API1. We were using this for sending mails to diff destination with excel sheet attachment contains sales data. This system has been migrated from 4.5B to ECC 5. Now this process is not working like the old one and the excel attachment is not properly formatted. All the data is being written into one cell of excel sheet and it seems only one line is present in output and is corrupted.
Can you please let me know what might be the issue here, any alternate option available or something to be modified in new version with this function module?
Thanks in advance,
UllasHi Ullas,
check this once.
REPORT ZLAXMI_ALVMAIL4 .
TABLES: EKKO.
PARAMETERS: P_EMAIL TYPE SOMLRECI1-RECEIVER
DEFAULT '[email protected]'.
TYPES: BEGIN OF T_EKPO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
AEDAT TYPE EKPO-AEDAT,
MATNR TYPE EKPO-MATNR,
END OF T_EKPO.
DATA: IT_EKPO TYPE STANDARD TABLE OF T_EKPO INITIAL SIZE 0,
WA_EKPO TYPE T_EKPO.
TYPES: BEGIN OF T_CHAREKPO,
EBELN(10) TYPE C,
EBELP(5) TYPE C,
AEDAT(8) TYPE C,
MATNR(18) TYPE C,
END OF T_CHAREKPO.
DATA: WA_CHAREKPO TYPE T_CHAREKPO.
DATA: IT_MESSAGE TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: IT_ATTACH TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
WITH HEADER LINE.
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_CNT TYPE I,
W_SENT_ALL(1) TYPE C,
W_DOC_DATA LIKE SODOCCHGI1,
GD_ERROR TYPE SY-SUBRC,
GD_RECIEVER TYPE SY-SUBRC.
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM DATA_RETRIEVAL.
Populate table with detaisl to be entered into .xls file
PERFORM BUILD_XLS_DATA_TABLE.
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
PERFORM POPULATE_EMAIL_MESSAGE_BODY.
Send file by email as .xls speadsheet
PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
TABLES IT_MESSAGE
IT_ATTACH
USING P_EMAIL
'Example .xls documnet attachment'
'XLS'
'filename'
CHANGING GD_ERROR
GD_RECIEVER.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM DATA_RETRIEVAL.
SELECT EBELN EBELP AEDAT MATNR
UP TO 10 ROWS
FROM EKPO
INTO TABLE IT_EKPO.
ENDFORM. " DATA_RETRIEVAL
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM BUILD_XLS_DATA_TABLE.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
CONSTANTS:
CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO IT_ATTACH SEPARATED BY CON_TAB.
CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.
APPEND IT_ATTACH.
LOOP AT IT_EKPO INTO WA_CHAREKPO.
CONCATENATE WA_CHAREKPO-EBELN WA_CHAREKPO-EBELP
WA_CHAREKPO-AEDAT WA_CHAREKPO-MATNR
INTO IT_ATTACH SEPARATED BY CON_TAB.
CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.
APPEND IT_ATTACH.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& 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_FORMAT TYPE SO_OBJ_TP ,
LD_ATTDESCRIPTION TYPE SO_OBJ_NAM ,
LD_ATTFILENAME TYPE SO_OBJ_DES ,
LD_SENDER_ADDRESS LIKE SOEXTRECI1-RECEIVER,
LD_SENDER_ADDRESS_TYPE LIKE SOEXTRECI1-ADR_TYP,
LD_RECEIVER LIKE SY-SUBRC.
LD_EMAIL = P_EMAIL.
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-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.
T_RECEIVERS-RECEIVER = LD_EMAIL.
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COM_TYPE = 'INT'.
T_RECEIVERS-NOTIF_DEL = 'X'.
T_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND T_RECEIVERS.
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.
*& 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
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
FORM POPULATE_EMAIL_MESSAGE_BODY.
REFRESH IT_MESSAGE.
IT_MESSAGE = 'Please find attached a list test ekpo records'.
APPEND IT_MESSAGE.
ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
Regards,
Laxmi. -
Excel 2007 Problems while sending E-Mail with Excel Attachment
Hello all,
i wrote a small WD application for uploading a file and sending this file
vie e-mail to some recipients.
I'm using class "cl_document_bcs". No problem with ".doc", ".pdf", also no problem
with ".xls" files generated by old Excel version. But when generating an .xls document with
Excel 2007, the attached file is not readable (just non usable signs).
For attaching the .xls file i use:
TRY.
lr_attachment = cl_document_bcs=>create_document(
i_type = lv_filetype " --> 'XLS'
i_subject = 'excel document'
i_hex = lt_file_solix
CATCH cx_document_bcs .
ENDTRY.
Are there any restrictions regarding Excel 2007?
The data element of i_type is just char3, so XLSX
wouldn't be possible.hello Christopher Linke ,
if you Programatically generation a excel file and you have 2007 version you can use OLE automation to save file as .xls i.e. a 2003 work book ..
if you have a excel file ready and you just want to send it across the you will have to convert the xlsx to xls and then send it you can do this as well using OLE automation
(in 2007 in SAVE AS option you can save it excel 97 2003 workbook)
Edited by: Anup Deshmukh on Mar 3, 2010 3:38 PM -
Sending external mail with excel attachment from SAP
Hi All,
I am trying to send a external mail from SAP. Mail is getting posted correctly with attachment having type excel. If attach file has more than 1 records then in mail it is coming in a single lines. it is not getting wrap.
e.g. my attach internal table has records like LINE1
LINE2
LINE3
output in attach excel file is : LINE1 LINE2 LINE3
in attach file it should come line by line.
source code of my function module is as follows :
FUNCTION ZXI_SEND_MAIL_WITH_ATTACHMENT.
""Local Interface:
*" IMPORTING
*" REFERENCE(SUBJECT) TYPE SO_OBJ_DES OPTIONAL
*" REFERENCE(ATTACH_NAME1) TYPE SOOD-OBJDES
*" REFERENCE(EXT1) TYPE SOODK-OBJTP
*" REFERENCE(MAIL_ID) TYPE ADR6-SMTP_ADDR
*" TABLES
*" IT_CONTENT TYPE SOLI_TAB OPTIONAL
*" IT_ATTACH TYPE SOLI_TAB OPTIONAL
DATA: send_request TYPE REF TO cl_bcs.
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO cl_sapuser_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: exception_info TYPE REF TO if_os_exception_info,
bcs_exception TYPE REF TO cx_document_bcs.
DATA i_attachment_size TYPE sood-objlen.
Creates persistent send request
send_request = cl_bcs=>create_persistent( ).
TRY.
*****Create txt mail document**************************
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_content[]
i_subject = subject ).
**************Creates Attachment 1***********************
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = ext1
i_attachment_subject = attach_name1
i_att_content_text = it_attach[].
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.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = mail_id ).
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'U'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
**********Trigger e-mails immediately****************************
send_request->set_send_immediately( 'X' ).
CALL METHOD send_request->send( ).
COMMIT WORK.
CATCH cx_document_bcs INTO bcs_exception.
ENDTRY.
ENDFUNCTION.
please suggest me a solution and thanks in advance.
Thanks&Regards,
SachinSee the sample code for sending attachment as Mail
Mailing with Attachment by ABAP Coding
Refer this link:
Mail with attachment.
FORM send_list_to_basis .
DATA: w_path LIKE rlgrap OCCURS 0 WITH HEADER LINE,
lt_index TYPE sy-tabix,
doc_type(3) TYPE c,
descr LIKE it_objpack_basis-obj_descr,
temp_data LIKE w_path,
temp1 TYPE string,
tab_lines TYPE i,
langu(15) TYPE c,
expirydate TYPE so_obj_edt,
L_FILE1(100).
CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.
W_PATH-FILENAME = L_FILE1.
APPEND w_path.
CLEAR w_path.
wa_doc_chng-obj_descr = 'User List not logged on for 180 days'.
wa_doc_chng-obj_langu = 'E'.
wa_doc_chng-obj_expdat = sy-datum.
CLEAR w_subject.
CONCATENATE 'Please find attached document with list of users'
'not logged on for 180 days for client' sy-mandt
INTO w_subject SEPARATED BY space.
it_objtxt_basis-line = w_subject.
APPEND it_objtxt_basis.
CLEAR it_objtxt_basis.
it_objtxt_basis-line = text-004.
APPEND it_objtxt_basis.
CLEAR it_objtxt_basis.
CLEAR w_tab_line.
DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.
READ TABLE it_objtxt_basis INDEX w_tab_line INTO l_cline.
wa_doc_chng-doc_size =
( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).
CLEAR it_objpack_basis-transf_bin.
it_objpack_basis-head_start = 1.
it_objpack_basis-head_num = 0.
it_objpack_basis-body_start = 1.
it_objpack_basis-body_num = w_tab_line.
it_objpack_basis-doc_type = 'RAW'.
APPEND it_objpack_basis.
CLEAR it_objpack_basis.
LOOP AT w_path.
temp1 = w_path.
descr = w_path.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = descr
lang = 'E'
IMPORTING
rstring = descr.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
delimiter = '\'
string = descr
IMPORTING
head = descr
tail = temp_data.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = descr
lang = 'E'
IMPORTING
rstring = descr.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
delimiter = '.'
string = descr
IMPORTING
head = temp_data
tail = doc_type.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = temp1
filetype = 'BIN'
header_length = 0
read_by_line = 'X'
replacement = '#'
TABLES
data_tab = it_upload.
DESCRIBE TABLE it_upload LINES tab_lines.
DESCRIBE TABLE it_objbin_basis LINES lt_index.
lt_index = lt_index + 1.
LOOP AT it_upload.
wa_objbin_basis-line = it_upload-line.
APPEND wa_objbin_basis TO it_objbin_basis.
CLEAR wa_objbin_basis.
ENDLOOP.
it_objpack_basis-transf_bin = 'X'.
it_objpack_basis-head_start = 0.
it_objpack_basis-head_num = 0.
it_objpack_basis-body_start = lt_index.
it_objpack_basis-body_num = tab_lines.
it_objpack_basis-doc_type = doc_type.
it_objpack_basis-obj_descr = descr.
it_objpack_basis-doc_size = tab_lines * 255.
APPEND it_objpack_basis.
CLEAR it_objpack_basis.
ENDLOOP.
it_reclist_basis-receiver = '[email protected]'.
it_reclist_basis-rec_type = 'U'.
APPEND it_reclist_basis.
CLEAR it_reclist_basis.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack_basis
contents_txt = it_objtxt_basis
contents_bin = it_objbin_basis
receivers = it_reclist_basis
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc EQ 0.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.
ENDFORM. " send_list_to_basis
Reward points if useful
Regards
Anji -
Problem with EXCEL format while sending a mail with excel attachment
Hi,
I'm trying to send a report through mail as an excel attchment. But though I get all the details in the attachmnet format in excel is not proper. It's in a very hapazard way. I tried putting control break statements after each record then also though there is slight betterment it's not ok. If I send the same thing as a pdf attachment it's perfect. May I know what else i need to do for excel.....? I tried compressing and then sending no luck......
I'm in version 4.6c.....
Thanks in advance....Hi,
Just check out this..
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
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_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'XLS'
'filename'
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
class cl_abap_char_utilities definition load.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY space.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY space.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& 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_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
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-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.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
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.
*& 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
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'This mail is scheduled automatically and excel file is
attached for your reference'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
Regards,
Sriram.
PS: Reward Points if it is useful. -
Error in Sending Mail with excel attachment
Hi All,
While sending a mail with excel attachment it is getting successfully send but when i am opening the excel it gives a popup saying "The file is not in recognizable format", and when i click OK the data is getting displayed.
So anybody has any idea of how to remove the popup??
I am using SO_NEW_DOCUMENT_ATT_SEND_API1 FM for sending the mail.
Can anybody help me regarding this.
Thanks
SalishHi,
I was facing the issue when I did not populate the parameters packing_list, object_header,contents_bin, contents_txt of the FM
SO_NEW_DOCUMENT_ATT_SEND_API1 properly.
Also the possible cause could be the configuration in SCOT, not very sure about this. Check with the BASIS guy.
Regards,
Sagar -
Problem in excel format while sending mail with excel attachment.
Hi Gurus ,
I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1.
I am able to send a mail with excel attachment with a piece of code which I got from SDN itself.
But the problem is when I am trying to open the attachment, <b>A pop up comes which says that it is not in recognizable format. Would you like to open it?
and several other lines of caution.</b>
When i choose to open it, i get the correct data in one excel sheet. Certain vertical lines of the excel sheet is missing. <b>But no data is missing. </b>
I am attaching the code below. Can any one please tell me where is the problem in this code ?
Thanx in advance
types: begin of t_mara,
matnr type mara-matnr,
matkl type mara-matkl,
mtart type mara-mtart,
meins type mara-meins,
end of t_mara.
data: gt_mara type table of t_mara,
wa_mara like line of gt_mara,
it_packing_list type table of SOPCKLSTI1,
wa_packing_list like line of it_packing_list,
it_receivers type table of SOMLRECI1,
wa_receivers like line of it_receivers,
it_mailbody type table of SOLISTI1,
wa_mailbody like line of it_mailbody,
it_attachment type table of SOLISTI1,
wa_attachment like line of it_attachment.
data: la_doc type SODOCCHGI1.
constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
* get material
select matnr matkl mtart meins
into table gt_mara
from mara
up to 25 rows.
* Populate the subject/generic message attributes
la_doc-obj_langu = sy-langu.
la_doc-obj_descr = 'Material Details' . "Mail Header
la_doc-sensitivty = 'F'.
la_doc-doc_size = 1.
* Add the recipients email address
CLEAR wa_receivers.
REFRESH it_receivers.
wa_receivers-receiver = 'PCSDEVL'.
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.
* Mail Body
CLEAR wa_mailbody.
REFRESH it_mailbody.
wa_mailbody-line = 'Please find the attachment'.
APPEND wa_mailbody to it_mailbody.
* Mail attachmwnt
CLEAR wa_attachment.
REFRESH it_attachment.
CONCATENATE 'MATNR' 'MATKL' 'MTART' 'MEINS'
INTO wa_attachment SEPARATED BY con_tab.
CONCATENATE con_cret wa_attachment INTO wa_attachment.
APPEND wa_attachment to it_attachment.
LOOP AT gt_mara INTO wa_mara.
CONCATENATE wa_mara-matnr wa_mara-matkl
wa_mara-mtart wa_mara-meins
INTO wa_attachment SEPARATED BY con_tab.
CONCATENATE con_cret wa_attachment INTO wa_attachment.
APPEND wa_attachment to it_attachment.
ENDLOOP.
* Describe the body of the message
CLEAR wa_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.
wa_packing_list-body_num = 1.
wa_packing_list-doc_type = 'RAW'.
APPEND wa_packing_list to it_packing_list.
* Create attachment notification
wa_packing_list-transf_bin = 'X'.
wa_packing_list-head_start = 1.
wa_packing_list-head_num = 1.
wa_packing_list-body_start = 1.
DESCRIBE TABLE it_attachment LINES wa_packing_list-body_num.
wa_packing_list-doc_type = 'XLS'. " To word attachment change this as 'DOC'
wa_packing_list-obj_descr = ' '.
concatenate wa_packing_list-doc_type 'file' into wa_packing_list-OBJ_DESCR
separated by space.
wa_packing_list-doc_size = wa_packing_list-body_num * 255.
APPEND wa_packing_list to it_packing_list.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = la_doc
PUT_IN_OUTBOX = 'X'
* SENDER_ADDRESS = SY-UNAME
* SENDER_ADDRESS_TYPE = 'B'
COMMIT_WORK = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
* SENDER_ID =
tables
packing_list = it_packing_list
* OBJECT_HEADER =
CONTENTS_BIN = it_attachment
CONTENTS_TXT = it_mailbody
* 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
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.REPORT Zex5 LINE-SIZE 255 LINE-COUNT 255 .
class CL_ABAP_CHAR_UTILITIES definition load. "-->
TABLES : vbap.
SELECT-OPTIONS: s_vbeln FOR vbap-vbeln.
DATA : BEGIN OF itab OCCURS 1,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
END OF itab.
parameters : p_email like somlreci1-receiver
DATA: tlines type i.
DATA: itmessage LIKE solisti1 OCCURS 1 WITH HEADER LINE. "Ok
DATA: itattach LIKE solisti1 OCCURS 2 WITH HEADER LINE. "Ok
DATA: itpacklist LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
DATA: itreclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
data: itattachment like solisti1 OCCURS 2 WITH HEADER LINE.
start-of-selection.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE itab
WHERE vbeln IN s_vbeln.
**Make the internal table data to be compatible in excel format .
PERFORM BUILD_XLS_FORMAT.
**Populate message of body text.
clear itmessage.
refresh itmessage.
itmessage = 'Please find attached Excel file'.
append itmessage.
PERFORM send_mail_as_xls_attachment tables itmessage
itattach
using p_email 'Excel Attachment' 'TXT' " 'XLS'
using p_email 'TEXT Attachment' 'TXT' " 'XLS'
'TestFileName'
'SalesOrders' .
*& Form BUILD_XLS_FORMAT
text
--> p1 text
<-- p2 text
form BUILD_XLS_FORMAT.
previosuly we were using for unicode ..now replaced
**Declare constants for the spacing .
*Constants : con1 type x value '0D',
con2 type x value '09'.
Constants : con1 type c
value CL_ABAP_CHAR_UTILITIES=>CR_LF,
con2 type c
value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
**For the Header descriptions.
Concatenate 'SalesORdNo'
'Item'
'Materialno' into itattach separated by con2.
Concatenate con1 itattach into itattach.
Append itattach.
**Now align the items in the itab as above .
Loop at Itab.
concatenate itab-vbeln
itab-posnr
itab-matnr into itattach separated by con2.
concatenate con1 itattach into itattach .
Append itattach.
endloop.
endform. " BUILD_XLS_FORMAT
*& Form send_mail_as_xls_attachment
text
-->P_ITMESSAGE text
-->P_ITATTACH text
-->P_P_EMAIL text
-->P_0116 text
-->P_0117 text
-->P_0118 text
-->P_0119 text
form send_mail_as_xls_attachment tables p_itmessage
p_itattach
using p_email
p_mtitle
p_format
p_filename
p_attdescription.
Data : xdocdata like sodocchgi1,
xcnt type i.
*Fill the document data.
xdocdata-doc_size = 1.
*Populate the subject/generic message attributes.
xdocdata-obj_name = 'SAPRPT'.
xdocdata-obj_langu = sy-langu.
xdocdata-obj_descr = p_mtitle.
*Fill the document data and fetch size of attachment.
clear xdocdata.
read table itattach index xcnt.
xdocdata-doc_size = ( xcnt - 1 ) * 255 + strlen( itattach ).
xdocdata-doc_size = ( xcnt - 1 ) * 255.
xdocdata-obj_name = 'SAPRPT'.
xdocdata-obj_langu = sy-langu.
xdocdata-obj_descr = p_mtitle.
clear itattachment. refresh itattachment.
itattachment[] = p_itattach[].
*Describe the body of the message.
clear itpacklist. refresh itpacklist.
itpacklist-transf_bin = 'X'.
itpacklist-head_start = '1'.
itpacklist-head_num = '0'.
itpacklist-body_start = '1'.
describe table itattachment lines itpacklist-body_num .
itpacklist-doc_type = 'TXT'.
itpacklist-doc_type = 'XLS'.
append itpacklist.
*Create attachment notification.
itpacklist-transf_bin = 'X'.
itpacklist-head_start = '1'.
itpacklist-head_num = '1'.
itpacklist-body_start = '1'.
describe table itattachment lines itpacklist-body_num .
itpacklist-doc_type = p_format.
itpacklist-obj_name = p_filename.
itpacklist-obj_descr = p_attdescription.
itpacklist-doc_size = itpacklist-body_num * 255 .
append itpacklist.
*FIll the receivers list.
Clear itreclist. refresh itreclist.
itreclist-receiver = p_email.
itreclist-rec_type = 'U'.
itreclist-com_type = 'INT'.
itreclist-notif_del = 'X'.
itreclist-notif_ndel = 'X'.
*itreclist-notif_read = 'X'.
append itreclist.
*CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = xdocdata
PUT_IN_OUTBOX = 'X'
commit_work = 'X'
SENDER_ADDRESS = SY-UNAME
tables
packing_list = itpacklist
CONTENTS_BIN = itattachment
CONTENTS_TXT = itmessage
receivers = itreclist
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.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = xdocdata
PUT_IN_OUTBOX = 'X'
TABLES
packing_list = itpacklist
CONTENTS_BIN = itattachment
CONTENTS_TXT = itmessage
receivers = itreclist
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_as_xls_attachment
Just execute the above code and let me know.
What is the sap version u r using .
Vijay -
Sending mail with excel attachment-improper format
Dear experts,
I am sending a mail to outlook with an excel attachment. The mail is sent with attachment and the data, but all in one cell.
I am using SO_NEW_DOCUMENT_ATT_SEND_API1. What parameters do i need to manipulate to have data in different columns of excel? I am using "packing_list" table of FM. But dont know the exact parameters to be passed. Can anyone help with the same please?
Best regards and thanks!
Sumit Nene.Hello Sumit,
I am using same function module to send mail with excel attachment.
Below I am attaching my own code for your reference.
Data which u want to add in excel file is maintain in IT_OBJBIN i.e. document information.
CLEAR :IMESSAGE,IT_OBJBIN,IT_OBJPACK,IT_RECLIST.
REFRESH: IMESSAGE[ ] , IT_OBJBIN[ ] , IT_OBJPACK[ ] , IT_RECLIST[ ].
" populate the text for body of the mail
CLEAR WA_IMESSAGE.
CONCATENATE 'Board : ' P_BOARD ':' 'Please find the excel attached for the list of Material whose routing is created' INTO WA_IMESSAGE-LINE.
APPEND WA_IMESSAGE TO IMESSAGE.
"document information
W_DOC_CHNG-OBJ_NAME = 'Excel'.
IF NOT P_BOARD IS INITIAL.
CONCATENATE 'Board : ' P_BOARD ':' 'List Of Routing Materials' INTO W_DOC_CHNG-OBJ_DESCR.
ELSE.
CONCATENATE 'List Of' ' Routing Materials' INTO W_DOC_CHNG-OBJ_DESCR.
ENDIF.
W_DOC_CHNG-SENSITIVTY = 'F'. " ->Functional object
" displaying material , plant in the excel
CONCATENATE 'BOARD NO : ' P_BOARD INTO WA_OBJBIN.
APPEND WA_OBJBIN TO IT_OBJBIN.
CONCATENATE 'MATERIAL' 'PLANT' 'DESCRIPTION' INTO WA_OBJBIN SEPARATED BY C_TAB.
CONCATENATE C_RET WA_OBJBIN INTO WA_OBJBIN.
APPEND WA_OBJBIN TO IT_OBJBIN.
CLEAR : WA_OBJBIN.
LOOP AT IT_DOWNLOAD INTO WA_DOWNLOAD. "It_orders is the internal table to be transferred to excel
CONCATENATE WA_DOWNLOAD-MATNR WA_DOWNLOAD-WERKS WA_DOWNLOAD-DESC INTO WA_OBJBIN SEPARATED BY C_TAB.
CONCATENATE C_RET WA_OBJBIN INTO WA_OBJBIN.
APPEND WA_OBJBIN TO IT_OBJBIN.
ENDLOOP.
DESCRIBE TABLE IT_OBJBIN LINES V_LINES_BIN. " no of lines for excel data
" pack the data as RAW
CLEAR WA_IT_OBJPACK-TRANSF_BIN. "Obj. to be transported not in binary form
WA_IT_OBJPACK-HEAD_START = 1. "Start line of object header in transport packet
WA_IT_OBJPACK-HEAD_NUM = 0. "Number of lines of an object header in object packet
WA_IT_OBJPACK-BODY_START = 1. "Start line of object contents in an object packet
WA_IT_OBJPACK-BODY_NUM = MESSAGE_LINES. "Number of lines of the mail body
WA_IT_OBJPACK-DOC_TYPE = 'RAW'.
APPEND WA_IT_OBJPACK TO IT_OBJPACK.
" pack the data as excel
WA_IT_OBJPACK-TRANSF_BIN = 'X'.
WA_IT_OBJPACK-HEAD_START = 1.
WA_IT_OBJPACK-HEAD_NUM = 1.
WA_IT_OBJPACK-BODY_START = 1.
WA_IT_OBJPACK-BODY_NUM = V_LINES_BIN. "no of lines of it_orders to give no of unprocessed orders
WA_IT_OBJPACK-DOC_TYPE = 'XLS'. " -> excel fomat
WA_IT_OBJPACK-OBJ_NAME = 'EXCEL ATTACHMENT'.
" attachment name
IF NOT P_BOARD IS INITIAL.
CONCATENATE P_BOARD '.XLS' INTO WA_IT_OBJPACK-OBJ_DESCR.
ELSE.
CONCATENATE 'LIST' '.XLS' INTO WA_IT_OBJPACK-OBJ_DESCR.
ENDIF.
WA_IT_OBJPACK-DOC_SIZE = V_LINES_BIN * 255.
APPEND WA_IT_OBJPACK TO IT_OBJPACK.
" creating email id
DATA: STR1 TYPE STRING,
STR2 TYPE STRING,
STR3 TYPE STRING,
ITAB TYPE TABLE OF STRING.
DATA : WA_I LIKE LINE OF ITAB.
SPLIT P_EMAIL AT ',' INTO: TABLE ITAB.
e-mail receivers.
CLEAR WA_IT_RECLIST.
LOOP AT ITAB INTO WA_I.
WA_IT_RECLIST-RECEIVER = WA_I.
WA_IT_RECLIST-RECEIVER = V_MAILADDR.
WA_IT_RECLIST-EXPRESS = 'X'.
WA_IT_RECLIST-REC_TYPE = 'U'. "-> Internet address
APPEND WA_IT_RECLIST TO IT_RECLIST.
CLEAR WA_IT_RECLIST.
ENDLOOP.
" sending mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = W_DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
PACKING_LIST = IT_OBJPACK
OBJECT_HEADER =
CONTENTS_BIN = IT_OBJBIN
CONTENTS_TXT = IMESSAGE
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
RECEIVERS = IT_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
COMMIT WORK.
IF SY-SUBRC = 0.
MESSAGE I001 WITH 'Routing is Created for Board' P_BOARD 'and Mail send on e-mail id :' P_EMAIL.
ENDIF. -
Java mail with Dynamic attachment?
Hi :-)
How to send the mails with dynamically created attachements..
The attachments may be a Excel file created dynamically according to the user inputs on the webpage. Is there any way to send those attachments to the receipients with out storing those attachements anywhere(server)?
Give me some tips to take my next step...
Thanx in advance
Krishnakumar S
(+919847706611)You should take a look at Sun's JavaMail site. It has quite a bit of info on JavaMail, located here: http://java.sun.com/products/javamail/.
See the FAQ here: http://java.sun.com/products/javamail/FAQ.html, it has questions dealing with attachments.
There is a tutorial here that covers sending and receiving attachments: http://java.sun.com/developer/onlineTraining/JavaMail/index.html. Specific section on attachments is located here: http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailAttachments -
How to send HTML mail with images multipart/related message
Hi,
Could any body tell me how to send HTML mail with images in "multipart/related" message,if any body can give the code ,it would be helpful.
ThanksHi,
Could any body tell me how to send HTML mail with
ith images in "multipart/related" message,if any body
can give the code ,it would be helpful.
ThanksHi!
Refer to
http://developer.java.sun.com/developer/onlineTraining/JavaMail/index.html
I've found it very helpful.
Look at the last part for a code showing how to send HTML mail!
Regards -
How to send an email with an attachment to the customers email address.
Hi friends,
How to send an email with an attachment to the customers email address.
the attachment will be in doc format.
Having an Header
the data which i am sending must be in a TABLE format
with 5 columns.
and each column must have a column heading
Please guide me.
Thanks in Advance,
Ganesh.*& Report ZEMAIL_ATTACH *
*& Example of sending external email via SAPCONNECT *
REPORT ZEMAIL_ATTACH .
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver .
*Here get the values of mail from the table adn6 for the customer address.
TYPES: BEGIN OF t_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
wa_ekpo TYPE t_ekpo.
TYPES: BEGIN OF t_charekpo,
ebeln(10) TYPE c,
ebelp(5) TYPE c,
aedat(8) TYPE c,
matnr(18) TYPE c,
END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
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_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
*START_OF_SELECTION
START-OF-SELECTION.
Retrieve sample data from table ekpo
PERFORM data_retrieval.
Populate table with detaisl to be entered into .xls file
PERFORM build_xls_data_table.
*END-OF-SELECTION
END-OF-SELECTION.
Populate message body text
perform populate_email_message_body.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_message
it_attach
using p_email
'Example .xls documnet attachment'
'DOC'
'filename'
changing gd_error
gd_reciever.
Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM initiate_mail_execute_program.
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
SELECT ebeln ebelp aedat matnr
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekpo.
ENDFORM. " DATA_RETRIEVAL
*& Form BUILD_XLS_DATA_TABLE
Build data table for .xls document
FORM build_xls_data_table.
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>CR_LF.
CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
LOOP AT it_ekpo INTO wa_charekpo.
CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
wa_charekpo-aedat wa_charekpo-matnr
INTO it_attach SEPARATED BY con_tab.
CONCATENATE con_cret it_attach INTO it_attach.
APPEND it_attach.
ENDLOOP.
ENDFORM. " BUILD_XLS_DATA_TABLE
*& 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_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
ld_email = p_email.
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-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.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
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.
*& 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
*& Form POPULATE_EMAIL_MESSAGE_BODY
Populate message body text
form populate_email_message_body.
REFRESH it_message.
it_message = 'Please find attached a list test ekpo records'.
APPEND it_message.
endform. " POPULATE_EMAIL_MESSAGE_BODY
regards,
venkat. -
How to send automatic mail and put attache file on batch file ?
how to send automatic mail and put attache file on batch file ?
START MAILTO:[email protected]?SUBJECT=PHONE%CALL^&BODY=TestingHi,
Do you want to use a batch file to create new email message (including recipients, subject and email body) with attachments? If so, I'd recommend you post your question in the Scripting Guys forum for further assistance:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
Please feel free to let me know if I've misunderstood something.
Regards,
Steve Fan
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs.
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected]
Maybe you are looking for
-
Variable substitution using attribute
hi, i want to use an attribute of an elemnet in variable substitution. i know how to use element in variable substitution and i know that i can use message header attributes in variable substitution, but if i create an element with an attribute how d
-
BOE-XI 3.1 Client Tools (SP4) Error
BOE-XI 3.1 Client Tools (SP3) are installed OK on a Workstation... Business View Manager = 12.3.0.601 Designer = 12.3.0.601 WebIntelligence Rich Client = 12.3.0.601 I have downloaded the "SBOP Enterprise Client Tools XI 3.1 ServicePack 4" files from
-
Using console program from java swing
Can anyone please tell me if the following is possible and how to do it. I want to create a gui for mencoder and so for example i will be wanting toexecute mencoder from the swing app to find out the the auto crop values so i can visually display the
-
When viewing my mailboxes "125" now appears on the "Sent" folder line
When viewing my mailboxes I now have the number "125" that appears to the right of my screen on the same line as my "SENT" folder. Has anyone ever had this?
-
Error "401 Unauthorized" calling wshandler service
Greetings, On a 620 system I'm trying to complete a webservice workitem via the wshandler service using CL_SWF_IFS_WS_EXPORT=>LAUNCH_CALLBACK. It fails with cx_swf_ws_http_exception after getting a response 401 - "Unauthorized". WF_HANDCUST is setup,