Manipulating subject in mail using VBA
Hi,
I have the need for a VBA code for Outlook, that will take the subject line, identify a casenumber XXXX123456, and put [] on the casenumber. For example:
Subjectline: Printerproblems XXXX123456
Subjectline: Printerproblems [XXXX123456]
(The casenumber can be anywhere in the subject line.)
Dim strSubject As String
strSubject = Item.Subject
strSubject = Replace(strSubject, "XXXX", "[XXXX")
Item.Subject = strSubject
But I can not find a way to write the last ]. Maybe I am doing this wrong, or something smarter exist.
Please help.
Best regards,
Mr. T
Hi Mr.Thomas,
Based on my understanding, the suggestion using Regular Expressions is a very helpful. Have you fixed the issue now?
If you still have the issue about develop with Regular Expressions using VBA, I suggest that you reopen a new thread in
Visual Basic for Application forum.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Manipulating ShockwaveFlash in Excel Using VBA
I am trying to change various variables in an embedded shockwaveplayer but I cannot get the video to play through code. My code is below. Any help would be appreciated and thanks in advance.
Sub TestVideo()
On Error GoTo iErrors
Set appxl = Excel.Application
Set sht = appxl.ActiveSheet
Dim shFl As ShockwaveFlash
For Each obj In sht.OLEObjects
If InStr(obj.progID, "ShockwaveFlash") > 0 Then
Set shFl = obj.Object
shFl.LoadMovie 0, shFl.Movie 'http://www.youtube.com/watch?v=1YuH8IoqaAg&feature=feedrec_grec_index
Exit For
End If
Next
Exit Sub
iErrors:
Err.Clear
Resume Next
End Sub
Thanks againHi Mr.Thomas,
Based on my understanding, the suggestion using Regular Expressions is a very helpful. Have you fixed the issue now?
If you still have the issue about develop with Regular Expressions using VBA, I suggest that you reopen a new thread in
Visual Basic for Application forum.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
BAPI Access from Excel using VBA
Im writing an excel macro (VBA) to call a bapi that populates a spreadsheet.
The user will then do some manipulation of the data collected, and then it must be sent back to sap.
The Bapi in question is BAPI_GET_USER_DETAIL
*" IMPORTING
*" VALUE(USERNAME) LIKE BAPIBNAME-BAPIBNAME
*" EXPORTING
*" VALUE(LOGONDATA) LIKE BAPILOGOND STRUCTURE BAPILOGOND
*" VALUE(DEFAULTS) LIKE BAPIDEFAUL STRUCTURE BAPIDEFAUL
*" VALUE(ADDRESS) LIKE BAPIADDR3 STRUCTURE BAPIADDR3
*" VALUE(COMPANY) LIKE BAPIUSCOMP STRUCTURE BAPIUSCOMP
*" VALUE(SNC) LIKE BAPISNCU STRUCTURE BAPISNCU
*" VALUE(REF_USER) LIKE BAPIREFUS STRUCTURE BAPIREFUS
*" VALUE(ALIAS) LIKE BAPIALIAS STRUCTURE BAPIALIAS
*" TABLES
*" PARAMETER STRUCTURE BAPIPARAM OPTIONAL
*" PROFILES STRUCTURE BAPIPROF OPTIONAL
*" ACTIVITYGROUPS STRUCTURE BAPIAGR OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*" ADDTEL STRUCTURE BAPIADTEL OPTIONAL
*" ADDFAX STRUCTURE BAPIADFAX OPTIONAL
*" ADDTTX STRUCTURE BAPIADTTX OPTIONAL
*" ADDTLX STRUCTURE BAPIADTLX OPTIONAL
*" ADDSMTP STRUCTURE BAPIADSMTP OPTIONAL
*" ADDRML STRUCTURE BAPIADRML OPTIONAL
*" ADDX400 STRUCTURE BAPIADX400 OPTIONAL
*" ADDRFC STRUCTURE BAPIADRFC OPTIONAL
*" ADDPRT STRUCTURE BAPIADPRT OPTIONAL
*" ADDSSF STRUCTURE BAPIADSSF OPTIONAL
*" ADDURI STRUCTURE BAPIADURI OPTIONAL
*" ADDPAG STRUCTURE BAPIADPAG OPTIONAL
*" ADDCOMREM STRUCTURE BAPICOMREM OPTIONAL
*" GROUPS STRUCTURE BAPIGROUPS OPTIONAL
Ive Managed to glean from various sources on the internet, the various basics on doing a bapi call from VBA
Here is what i have so far.
Private Sub Fetch_User_details_Click()
'Take username in cell 2,2 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Variant
Dim Preturn As Variant
Dim copyFromc As String
'Clear Table Section of Spreadsheet
Worksheets("Sheet1").Select
For x = 9 To 200
For y = 1 To 8
Worksheets("Sheet1").Cells(x, y).ClearContents
Next y
Next x
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = ""
R3.Connection.client = ""
R3.Connection.user = ""
R3.Connection.Password = ""
R3.Connection.Language = "EN"
'Logon to SAP
If R3.Connection.logon(0, False) <> True Then
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
copyFromc = Worksheets("Sheet1").Cells(3, 2).Text
Set Pusername = MyFunc.exports("USERNAME")
Pusername.Value = copyFromc
'Call the BAPI
If MyFunc.call Then
' ok now what ?
' Process the returned data into the spreadsheet
Else
MsgBox ("Call returned FALSE")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
To update the data ( User Role Assignements ) i will be using bapi BAPI_USER_ACTGROUPS_ASSIGN
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(USERNAME) LIKE BAPIBNAME-BAPIBNAME
*" TABLES
*" ACTIVITYGROUPS STRUCTURE BAPIAGR
*" RETURN STRUCTURE BAPIRET2
* Dieser Baustein ist gleichgestellt mit der Pflege eines Benutzers
* über die Pflegetransaktion, gepflegt werden die Felder, für die die
* Pflege erlaubt ist
I need help deciphering the data received from the bapi and then repackaging it using VBA.
I know writing this in ABAP would take less than 30 mins, but that is not an option for me.Ok, Ive made some headway
I can now Read all the data i need from SAP
Now comes the bit to write it back again. Will Update when i have a solution
Private Sub copydata_Click()
Dim x1 As Integer, x2 As Integer
'copy all data from "Copy From" to "Copy To"
'first determine how many rows contain roles
'before copying the roles, check that the destination user has no roles assigned
If Cells(9, 6).Text <> "" Then
MsgBox ("Error. Destination User already has Roles assigned.")
Exit Sub
End If
For x1 = 0 To 1000
If Cells(9 + x1, 1).Text = "" Then
Exit For
End If
Next
Worksheets("Sheet1").Range(Cells(9, 1), Cells(9 + x1 - 1, 4)).Copy _
Destination:=Worksheets("Sheet1").Range(Cells(9, 6), Cells(9 + x1, 9))
For x2 = 1 To x1
Worksheets("Sheet1").Cells(9 + x2 - 1, 8).Value = Date
Next
End Sub
Sub Mail_small_Text_Outlook()
' Is working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = "User " & Worksheets("Sheet1").Cells(3, 7).Text & _
" Has Been Moddelled off of User " & _
Worksheets("Sheet1").Cells(3, 2).Text & " in system " & _
Worksheets("Connection").Cells(1, 2).Text & vbNewLine & vbNewLine & _
"Please Adjust Mitigating Controls Accordingly"
On Error Resume Next
With OutMail
.To = Worksheets("Connection").Cells(10, 2).Text
.CC = ""
.BCC = ""
.Subject = "User Modelled"
.Body = strbody
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Private Sub Fetch_CopyTo_User_Click()
'Take username in cell 3,7 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Object
Dim PAddress As Object
Dim PTable As Object
Dim Preturn As Object
Dim copyFromc As String
'Clear Table Section of Spreadsheet
Worksheets("Sheet1").Cells(5, 8).ClearContents
Worksheets("Sheet1").Cells(6, 8).ClearContents
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = Worksheets("Connection").Cells(1, 2).Text
R3.Connection.SystemNumber = Worksheets("Connection").Cells(2, 2).Text
R3.Connection.Destination = Worksheets("Connection").Cells(3, 2).Text
R3.Connection.HostName = Worksheets("Connection").Cells(4, 2).Text
R3.Connection.client = Worksheets("Connection").Cells(5, 2).Text
R3.Connection.user = Worksheets("Connection").Cells(6, 2).Text
R3.Connection.Password = Worksheets("Connection").Cells(7, 2).Text
R3.Connection.Language = Worksheets("Connection").Cells(8, 2).Text
'Logon to SAP
If R3.Connection.Logon(0, -1) <> True Then
MsgBox ("We Had a Logon Error")
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:\guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
Set Pusername = MyFunc.exports("USERNAME")
Set PAddress = MyFunc.imports("ADDRESS")
Set Preturn = MyFunc.tables("RETURN")
Set PTable = MyFunc.tables("ACTIVITYGROUPS")
Pusername.Value = Worksheets("Sheet1").Cells(3, 7).Text
'Call the BAPI
If MyFunc.call Then
Dim xxx As String
Worksheets("Sheet1").Cells(5, 7).Value = PAddress.Value("FIRSTNAME")
Worksheets("Sheet1").Cells(6, 7).Value = PAddress.Value("LASTNAME")
'Get Assigned Roles
Dim datarec As Object
Dim datafld As Object
x = 9
For Each datarec In PTable.Rows
Worksheets("Sheet1").Cells(x, 6).Value = datarec("AGR_NAME")
Worksheets("Sheet1").Cells(x, 7).Value = datarec("AGR_TEXT")
Worksheets("Sheet1").Cells(x, 8).Value = datarec("FROM_DAT")
Worksheets("Sheet1").Cells(x, 9).Value = datarec("TO_DAT")
x = x + 1
Next
copydata.Enabled = True
Else
MsgBox ("Error Calling Function - Probably Authorizations")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
Private Sub Fetch_User_details_Click()
'Take username in cell 3,2 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Object
Dim PAddress As Object
Dim PTable As Object
Dim Preturn As Object
Dim copyFromc As String
'Clear Table Section and other areas of Spreadsheet
Worksheets("Sheet1").Select
For x = 9 To 1000
For y = 1 To 9
Worksheets("Sheet1").Cells(x, y).ClearContents
Next y
Next x
Worksheets("Sheet1").Cells(5, 2).ClearContents
Worksheets("Sheet1").Cells(6, 2).ClearContents
Worksheets("Sheet1").Cells(5, 7).ClearContents
Worksheets("Sheet1").Cells(6, 7).ClearContents
copydata.Enabled = False
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = Worksheets("Connection").Cells(1, 2).Text
R3.Connection.SystemNumber = Worksheets("Connection").Cells(2, 2).Text
R3.Connection.Destination = Worksheets("Connection").Cells(3, 2).Text
R3.Connection.HostName = Worksheets("Connection").Cells(4, 2).Text
R3.Connection.client = Worksheets("Connection").Cells(5, 2).Text
R3.Connection.user = Worksheets("Connection").Cells(6, 2).Text
R3.Connection.Password = Worksheets("Connection").Cells(7, 2).Text
R3.Connection.Language = Worksheets("Connection").Cells(8, 2).Text
'Logon to SAP
If R3.Connection.Logon(0, -1) <> True Then
MsgBox ("We Had a Logon Error")
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:\guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
Set Pusername = MyFunc.exports("USERNAME")
Set PAddress = MyFunc.imports("ADDRESS")
Set Preturn = MyFunc.tables("RETURN")
Set PTable = MyFunc.tables("ACTIVITYGROUPS")
Pusername.Value = Worksheets("Sheet1").Cells(3, 2).Text
'Call the BAPI
If MyFunc.call Then
Dim xxx As String
Worksheets("Sheet1").Cells(5, 2).Value = PAddress.Value("FIRSTNAME")
Worksheets("Sheet1").Cells(6, 2).Value = PAddress.Value("LASTNAME")
'Get Assigned Roles
Dim datarec As Object
Dim datafld As Object
x = 9
For Each datarec In PTable.Rows
Worksheets("Sheet1").Cells(x, 1).Value = datarec("AGR_NAME")
Worksheets("Sheet1").Cells(x, 2).Value = datarec("AGR_TEXT")
Worksheets("Sheet1").Cells(x, 3).Value = datarec("FROM_DAT")
Worksheets("Sheet1").Cells(x, 4).Value = datarec("TO_DAT")
x = x + 1
Next
Else
MsgBox ("Error Calling Function - Probably Authorizations")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
Private Sub UpdateSap_Click()
End Sub -
Problems to SEND MAIL using WWV_FLOW_MAIL.SEND - APEX_MAIL
I tried send mail using the code below
DECLARE
l_body CLOB:= EMPTY_CLOB;
l_body_html CLOB:= EMPTY_CLOB;
BEGIN
wwv_flow_api.set_security_group_id;
l_body :='<html>
+<head>+
+<style type="text/css">+
+body{font-family: Arial, Helvetica, sans-serif;+
+font-size:10pt;+
+margin:30px;+
+background-color:#ffffff;}+
+span.sig{font-style:italic;+
font-weight:bold;
color:#811919;}
+</style>+
+</head>+
+<body>+
+</html>';+
l_body_html := '<html>
+<head>+
+<style type="text/css">+
+body{font-family: Arial, Helvetica, sans-serif;+
+font-size:10pt;+
+margin:30px;+
+background-color:#ffffff;}+
+span.sig{font-style:italic;+
font-weight:bold;
color:#811919;}
+</style>+
+</head>+
+<body>+
+</html>';+
wwv_flow_mail.send('[email protected]','[email protected]',nvl(l_body,'Texto com erro'),nvl(l_body_html,'erro2'),'K','[email protected]',
+'[email protected]','[email protected]');+
wwv_flow_mail.push_queue;
END;
+/+
This code return the message:
Mail To From Subject CC BCC Created On Created By Error Created
CHECK$01 [email protected] [email protected] K [email protected] [email protected] 08/23/2010 03:05:00 PM SYS
ORA-06502: PL/SQL: erro: erro de conversão de caractere em número numérico ou de valor
Follow my mail settings
SMTP Host Address : POP.SLE.TERRA.COM.BR
SMTP Host Port 110
Administration Email Address [email protected]
Notification Email Address [email protected]
what´s wrong ?I would try sending just basic text first, then move on to getting your other pieces dynamics. The very last step to me would be the email body.
Here is an example of a basic text email I use:
declare
e_id NUMBER;
c_id NUMBER;
emp_nm VARCHAR2(100);
clrk_id NUMBER;
e_clrk VARCHAR2(47);
e_org NUMBER;
e_sender VARCHAR2(50);
e_recip_lst VARCHAR2(255);
e_cc VARCHAR2(100);
e_bcc VARCHAR2(100);
e_subj VARCHAR2(50);
e_msg_ln1 VARCHAR2(100);
e_msg_ln2 VARCHAR2(100);
e_msg_ln3 VARCHAR2(100);
e_msg_ln4 VARCHAR2(100);
e_msg_ln5 VARCHAR2(100);
e_msg VARCHAR2(1000);
CRLF CHAR(2) := CHR(13) || CHR(11);
tmp_flag NUMBER;
begin
if :P2_INJURY_FLAG = 1 then
-- find out if it has changed first so we don't keep sending emails
select injury_flag, VEH_LOC
into tmp_flag, e_org
from APPS.tc
where tc_id = :P2_TC_ID;
if :P2_injury_flag <> tmp_flag then
begin
select FN_GET_USER(nvl(v('APP_USER'),user))
into clrk_id
from dual;
select ADMIN_USERNAME
into e_clrk
from APPS.APEX_ACCESS_CONTROL
where ID = clrk_id;
exception
when others then null; -- in case we cannot find the user
end;
e_id := :P2_EMP_ID;
c_id := :P2_TC_ID;
select EMP_FNAME ||' '|| EMP_MNAME ||' '|| EMP_LNAME into emp_nm
from APPS.EMPLOYEES
where EMP_ID = e_id; --
select RECIPIENTS, CC, BCC
into e_recip_lst, e_cc, e_bcc
from APPS.SAFETY_NOTIFICATIONS
where ORG_ID = e_org; --
e_sender := '[email protected]';
e_subj := 'Loss Reported';
e_msg_ln1 := 'Employee: ' || emp_nm || ' (' || e_id || ')'
|| CRLF;
e_msg_ln2 := 'Was reported as sustaining a loss' || CRLF;
e_msg_ln3 := 'by ' || e_clrk ||CRLF;
e_msg_ln4 := CRLF;
e_msg_ln5 := 'Sent ' || to_char(sysdate,'MONTH DD,YYYY HH:MI AM');
e_msg := e_msg_ln1 || e_msg_ln2 || e_msg_ln3 || e_msg_ln4 || e_msg_ln5 || CRLF || e_recip_lst;
utl_mail.send(
sender => e_sender,
recipients => e_recip_lst,
cc => e_cc,
bcc => e_bcc,
subject => e_subj,
message => e_msg);
end if;
end if;
end; -
[b]Tutorial:[/b] Simplify Developing OLE Automation Code Using VBA
INTRODUCTION
Automating Office applications from Oracle Forms can be a tedious, frustrating, and time-consuming process. Because the OLE2 and CLIENT_OLE2 built-ins do not validate the automation commands that they relay, code that compiles without errors often dies at runtime with a not-so-helpful error code. This tutorial will demonstrate how to simplify the development of automation code using a tool that ships with all Microsoft Office editions -- the Visual Basic for Applications (VBA) IDE.
The VBA IDE, a core Office component, is a full-fledged development environment featuring code completion, basic syntax highlighting, context-driven help and a runtime debugger. Its Object Browser provides a convenient means of browsing the Word object model, as well as searching by keyword.
For those who may not interested in following this tutorial in detail, I would like to stress the usefulness of the Object Browser as a tool for inspecting the functions supported by OLE server applications and, perhaps more importantly, valid values for function arguments. Whether/not anyone buys the assertion that starting with VBA prototypes is far more productive than pounding out OLE2 code from the very start, they will find the Object Browser invaluable as a reference -- I rely on it exclusively for this sort of documentation.
A BRIEF INTRODUCTION TO THE VBA IDE & THE OBJECT BROWSER UTILITY
Try this:
1. Open Word
2. Launch the VBA IDE by pressing <Alt><F11>
3. Open the Object Browser by pressing <F2>
The Object Browser allows you to visually navigate Word's class hierarchy. Its user interface is a bit crowded, so controls are unlabeled. Hovering the mouse cursor above a control will display a tooltip explaining that control's purpose. The browser's scope can be narrowed by using the Project/Library combo. Typing a keyword or substring in the Search Text combo and clicking on the Search button will cause all classes/members whose name contains the specified search text to be listed in the Search Results pane. Selecting an item from this list will update the two panes below it, showing the selected class, and its members. Beneath the Classes and Members panes is an untitled pane, gray in color, which displays details for the selected class/member, including hyperlinks to relevant information such as arguments, their types and allowable values. If Visual Basic Help is installed, pressing <F1> will display help on a selected class/member. (This feature can be installed from your Office install CD, if necessary.)
NOTE: While it is possible to cut-and-paste the code examples that follow, I highly recommend that they be typed in by hand. Doing so will provide a better understanding of how the IDE's code completion behaves. Use code completion most efficiently by not using the mouse or <Enter> key when selecting from completion lists. Instead, just type enough letters to select the desired list element, then continue along as if you had typed the entire element, typing the next operator in your statement. It really is slick!
HELLO WORLD - VBA-STYLE
1. Open Word
2. Launch the VBA IDE by pressing <Alt><F11>
3. Select Module from the Insert menu.
4. In the blank area that appears, enter the following code:
Public Sub HelloWorld()
Documents.Add
Selection.TypeText ("Hello, world!")
End Sub5. Press <F5> to run the code.
If you switch back to Word by pressing <Alt><F11>, there should appear a newly-created document containing the text Hello, world!.
A MORE AMBITIOUS EXAMPLE
In this example, we will launch Word, type some text, and alter its formatting. For the purposes of this tutorial, consider it the process we wish to automate from within Forms.
1. If Word is running, close it.
2. Open any Office application except Word, such as Excel, Outlook or PowerPoint
3. Launch the VBA IDE by pressing <Alt><F11>.
4. Select References from the Tools menu -- a dialog should pop up.
5. From within this dialog, locate and select Microsoft Word <version> Object Library, then click OK.
6. Select Module from the Insert menu.
7. In the blank area that appears, enter the following code:
Public Sub LaunchWord()
Dim app As Word.Application
Set app = CreateObject("Word.Application")
app.Visible = True '!!! IMPORTANT !!!
app.Documents.Add
With app.Selection
.TypeText "This is paragraph 1."
.TypeParagraph
.TypeText "This is paragraph 2."
.TypeParagraph
.TypeText "This is paragraph 3."
End With
With ActiveDocument
.Paragraphs(1).Range.Words(3).Bold = True
.Paragraphs(2).Range.Words(3).Italic = True
.Paragraphs(3).Range.Words(3).Underline = True
End With
End Sub8. Press <F5> to run the code.
A new Word session should have been launched. Switch to it, to view the results of our handiwork!
TAILORING VBA CODE INTENDED FOR OLE2 CONVERSION
Now, things get a bit uglier. The code listed above gives a good idea of how concise VBA code can be, but With blocks and chained object references do not translate readily into OLE2 code. Here's the same process, rewritten in a more OLE2-friendly style. Note the numerous intermediate object references that have been declared.
Public Sub LaunchWord()
Dim app As Word.Application
Dim doc As Word.Document
Dim docs As Word.Documents
Dim pars As Word.Paragraphs
Dim par As Word.Paragraph
Dim wrds As Word.Words
Dim sel As Word.Selection
Dim rng As Word.Range
Set app = CreateObject("Word.Application")
app.Visible = True '!!! IMPORTANT !!!
Set doc = app.Documents.Add
Set sel = app.Selection
sel.TypeText "This is paragraph 1."
sel.TypeParagraph
sel.TypeText "This is paragraph 2."
sel.TypeParagraph
sel.TypeText "This is paragraph 3."
Set pars = doc.Paragraphs
'select third word of first paragraph and make it bold
Set par = pars.Item(1)
Set rng = par.Range
Set wrds = rng.Words
Set rng = wrds.Item(3)
rng.Bold = True
'select third word of second paragraph and italicize it
Set par = pars.Item(2)
Set rng = par.Range
Set wrds = rng.Words
Set rng = wrds.Item(3)
rng.Italic = True
'select third word of second paragraph and underline it
Set par = pars.Item(3)
Set rng = par.Range
Set wrds = rng.Words
Set rng = wrds.Item(3)
rng.Underline = True
End Sub
TRANSFORMATION: CONVERTING VBA CODE INTO PL/SQL
Here is the PL/SQL counterpart to our previous VBA routine. Compare printouts of the two and note their similarities. Notice the need for argument lists -- this causes the code to fluff up quite a bit, and really interferes with readability.
PROCEDURE LAUNCH_WORD IS
v_app OLE2.OBJ_TYPE; -- Application
v_doc OLE2.OBJ_TYPE; -- Document
v_docs OLE2.OBJ_TYPE; -- Documents collection
v_pars OLE2.OBJ_TYPE; -- Paragraphs collection
v_par OLE2.OBJ_TYPE; -- Paragraph
v_wrds OLE2.OBJ_TYPE; -- Words collection
v_sel OLE2.OBJ_TYPE; -- Selection
v_rng OLE2.OBJ_TYPE; -- Range
v_args OLE2.LIST_TYPE; -- OLE2 argument list
BEGIN
/* launch Word and MAKE IT VISIBLE!!! */
v_app := OLE2.CREATE_OBJ('Word.Application');
OLE2.SET_PROPERTY(v_app, 'Visible', TRUE);
/* initialize key object references */
v_docs := OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
v_doc := OLE2.INVOKE_OBJ(v_docs, 'Add');
v_sel := OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
/* type first paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 'This is paragraph 1.');
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
OLE2.INVOKE(v_sel, 'TypeParagraph');
/* type second paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 'This is paragraph 2.');
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
OLE2.INVOKE(v_sel, 'TypeParagraph');
/* type third paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 'This is paragraph 3.');
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
/* set reference to Paragraphs collection */
v_pars := OLE2.GET_OBJ_PROPERTY(v_doc, 'Paragraphs');
/* select third word of first paragraph and make it bold */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 1);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, 'Bold', TRUE);
/* select third word of second paragraph and italicize it */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 2);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, 'Italic', TRUE);
/* select third word of second paragraph and underline it */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, 3);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, 'Underline', TRUE);
END;
REFACTORING FOR REUSABILITY AND READABILITY
While the previous procedure runs without errors, it suffers from poor readability which, in turn, makes it difficult to maintain. Here, we address those issues by moving repetetive low-level operations into separate procedures.
PROCEDURE LAUNCH_WORD IS
v_app OLE2.OBJ_TYPE; -- Application
v_doc OLE2.OBJ_TYPE; -- Document
v_docs OLE2.OBJ_TYPE; -- Documents collection
v_sel OLE2.OBJ_TYPE; -- Selection
v_args OLE2.LIST_TYPE; -- OLE2 argument list
BEGIN
/* launch Word and MAKE IT VISIBLE!!! */
v_app := OLE2.CREATE_OBJ('Word.Application');
OLE2.SET_PROPERTY(v_app, 'Visible', TRUE);
/* create a new Word document */
v_docs := OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
v_doc := OLE2.INVOKE_OBJ(v_docs, 'Add');
v_sel := OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
/* add a few paragraphs */
PRINT_PARAGRAPH(v_sel, 'This is paragraph 1.');
PRINT_PARAGRAPH(v_sel, 'This is paragraph 2.');
PRINT_PARAGRAPH(v_sel, 'This is paragraph 3.');
/* apply formatting */
APPLY_FORMATTING(v_doc, 1, 3, 'Bold', TRUE);
APPLY_FORMATTING(v_doc, 2, 3, 'Italic', TRUE);
APPLY_FORMATTING(v_doc, 3, 3, 'Underline', TRUE);
END;
PROCEDURE APPLY_FORMATTING(
v_doc OLE2.OBJ_TYPE,
v_paragraph_num NUMBER,
v_word_num NUMBER,
v_attribute VARCHAR2,
v_value BOOLEAN) IS
v_pars OLE2.OBJ_TYPE; -- Paragraphs collection
v_par OLE2.OBJ_TYPE; -- Paragraph
v_wrds OLE2.OBJ_TYPE; -- Words collection
v_rng OLE2.OBJ_TYPE; -- Range
v_args OLE2.LIST_TYPE; -- OLE2 argument list
BEGIN
/* set reference to Paragraphs collection */
v_pars := OLE2.GET_OBJ_PROPERTY(v_doc, 'Paragraphs');
/* get specified paragraph */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, v_paragraph_num);
v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
OLE2.DESTROY_ARGLIST(v_args);
/* get words for specified paragraph */
v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
/* apply formatting to word found at specified index */
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, v_word_num);
v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
OLE2.SET_PROPERTY(v_rng, v_attribute, v_value);
END;
PROCEDURE PRINT_PARAGRAPH(v_sel OLE2.OBJ_TYPE, v_text VARCHAR2) IS
v_args OLE2.LIST_TYPE;
BEGIN
v_args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(v_args, v_text);
OLE2.INVOKE(v_sel, 'TypeText', v_args);
OLE2.DESTROY_ARGLIST(v_args);
OLE2.INVOKE(v_sel, 'TypeParagraph');
END;
CONCLUSION
It is my hope that this tutorial, despite it's introductory nature, has demonstrated the value of the VBA IDE, the ease with which automation processes can be prototyped using VBA, the noticeable similarity between VBA automation routines and their Forms PL/SQL counterparts, and the advantages of testing automation processes within the VBA IDE. Please feel free to follow up with any specific questions or concerns you may have.
Thanks,
Eric Adamson
Lansing, Michigan
FINAL NOTE: These examples use the OLE2 built-in, and will operate correctly when called from forms running in the Form Builder OC4J. Deploying them to an Oracle Application Server will launch Word on the server itself (if available), which is usually not the developer's intent! Automating Word client-side via web forms requires adding WebUtil support. Adapting the code for WebUtil is trivial -- just replace all instances of OLE2 with CLIENT_OLE2. Adapting forms for WebUtil and configuring OLE support into your Oracle Application Server, however, are beyond the scope of this tutorial.
REVISION HISTORY
This promises to be something of a 'living document'. I've snuck changes through without comment in the past, but in the future, I'll try to document significant changes here.
2006-08-21
* Prefaced boring subject line with text: 'Tutorial:' to clarify purpose
* Added emphasis on value of Object Browser as a referenceThanks James, for your kind words. I do hope this information will help folks out. I honestly believe that tinkering around in the VBA IDE will prove highly gratifying for automation developers. It can be assured that learning to make Word jump through hoops is much more straight-forward in this environment. I'm not one for mottos, but if I were pressed for a cheesy motto, I would say: First, make it work. Then, make it work in Oracle!
Once the idea has sunk in, that Visual Basic routines for automating Word are exact analogs to their OLE2 counterparts, we can remove keywords like Oracle and PL/SQL from our Google searches on Word automation which, at least in this context, are the proverbial kiss of death. Suddenly we find ourselves liberated by the possibility of steal-, ahem... borrowing ideas from the Visual Basic* community!
As for links, my link of choice is invariably http://groups.google.com -- if you don't already use it at least ten times a day, you must try it. This is the venerable USENET archive, including the holdings of now-extinct DejaNews. Another possible site of interest is http://word.mvps.org/FAQs/MacrosVBA, which may serve as a good starting point for those who wish to learn how to do fancy tricks with Word using VBA.
If these links don't prove immediately helpful, please feel free to give specifics on the sort of operations you are interested in automating, and I'll see if I can post an example that addresses it.
Regards,
Eric Adamson
Lansing, Michigan
PS: I do hope, as people read my posts, with every other acronym being VBA, that they are not mistakenly hearing a call to learn Visual Basic. I say this, not because I believe learning VB would be a Bad Thing, but because I assume that few of us feel we have the time to learn a new programming language. Despite having come to the Oracle camp already knowing VB/VBA, and having acquired a fair bit of experience with automating Office applications as an Access developer, I remain confident that what I am suggesting people attempt does not rise to the level of learning a language. What I am suggesting is that they learn enough of the language to get by.
*VB vs. VBA
Just a quick word on this, as readers may wonder why I seem to use these terms interchangeably. Visual Basic (VB) can refer to either a development platform or a programming language. Visual Basic for Applications (VBA) is a language -- more precisely, it is a subset of the Visual Basic language. One purchases VB, usually quite intentionally. VBA is included with Microsoft Office, as is VBA's development environment, the VBA IDE. The key distinction between VB and VBA is that VBA cannot be used to create self-contained executables. Rather, VBA relies on VBA-enabled applications, such as Microsoft Office applications, to serve as a container for VBA code, and to provide a runtime environment for that code. For the purposes of discussing OLE Automation, VB and VBA are quite interchangeable. -
How can send mails using hotmail/rediffmail domain name?
I have used the below code to send a mail using javamail API?Even when I am sending my application does not have notified any of error/exceptions,But the message is not reached to I have given receipient's address in the to field.
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Sendmail1 extends HttpServlet {
private String smtpHost;
// Initialize the servlet with the hostname of the SMTP server
// we'll be using the send the messages
public void init(ServletConfig config)
throws ServletException {
super.init(config);
smtpHost = config.getInitParameter("smtpHost");
//smtpHost = "sbm5501";
smtpHost = "www.rediffmail.com";
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, java.io.IOException {
String from = request.getParameter("from");
String to "[email protected]";
String cc = "[email protected]";
String bcc ="[email protected]";
String smtp ="www.rediffmail.com";
String subject = "hai";
String text = "Hai how r u";
PrintWriter writer = response.getWriter();
if (subject == null)
subject = "Null";
if (text == null)
text = "No message";
String status;
try {
// Create the JavaMail session
java.util.Properties properties = System.getProperties();
if (smtp == null)
smtp = "www.rediffmail.com";
properties.put("mail.smtp.host", smtp);
Session session = Session.getInstance(properties, null);
//to connect
//Transport transport =session.getTransport("smtp");
//transport.connect(smtpHost,user,password);
// Construct the message
MimeMessage message = new MimeMessage(session);
// Set the from address
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
// Parse and set the recipient addresses
Address[] toAddresses = InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.TO,toAddresses);
Address[] ccAddresses = InternetAddress.parse(cc);
message.setRecipients(Message.RecipientType.CC,ccAddresses);
Address[] bccAddresses = InternetAddress.parse(to);
message.setRecipients(Message.RecipientType.BCC,bccAddresses);
// Set the subject and text
message.setSubject(subject);
message.setText(text);
Transport.send(message);
//status = "<h1>Congratulations,</h1><h2>Your message was sent.</h2>";
} catch (AddressException e)
status = "There was an error parsing the addresses. " + e;
} catch (SendFailedException e)
status = "<h1>Sorry,</h1><h2>There was an error sending the message.</h2>" + e;
} catch (MessagingException e)
status = "There was an unexpected error. " + e;
// Output a status message
response.setContentType("text/html");
writer.println("<title>sendForm</title><body bgcolor= ><b><h3><font color=green><CENTER>CALIBERINFO.COM</CENTER></h3>Your message was sent to recepient(s).<br><font color=red>"+"\n"+to);
writer.println("<br><br><a href=e:/mail/javamail/mail.html>back to compose</a>");
writer.close();
Please any one help me out from this probs.
Awaiting for yours reply,
or give me a reply to: [email protected]
Regards,
@maheshkumar.kHi,
how can send mails using hotmail/rediffmail domain name?In your java application,you specified www.rediffmail.com as your
smtp server.But that is the address of that website.Try will a smtp
server instead.For a list of free smtp servers,please visit http://www.thebestfree.net/free/freesmtp.htm
Hope this helps.
Good Luck.
Gayam.Srinivasa Reddy
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support/ -
Send mail using Internal Mail server doesn't work
I can't send mail using my companies mail server, which requires authentication and port 587 to send. We have a valid, non self-signed SSL certificate so that is not the issue. I can send mail using Bell's mail server but that violates our regulatory compliance obligations.
The server using POP3 and one must login to get mail as well as send. Unfortunately there is no otehr error message than the: error sending "mail subject". No further details are provided and when we check the mail servers logs its clear the Pre isn't even attempting to connect to the mail server. So the request to send mail isn't even being sent out. That could be an issue with the Pre or with Bell but Bell support will only troubleshoot to the point of fidning out if you can send using their mail server. We can so their support stops at that point.
I still have v1.3.1 of the WebOS as v1.3.5 doesn't seem to be out for the Bell Pre's yet. But from what I've read v1.3.5 is even worse at handling mail not better. However, there may be a solution out there to this beyond sending the Pre's back (I doubt we can) as Balckberry's and iPhone's don't have this issue.
Any advice is greatly appreciated.
Post relates to: Pre p100eww (Bell)Further update on this problem. It does send if I use TLS instead of SSL so that must mean that the Palm Pre doesn't use SSLv3 or higher. As TLS is a viable security setting option to maintain compliance I can use that. But still Plam should seriously consider upgrading tis SSL versioning.
-
How to send a mail using SMTPAppender in Log4j..?
Hello friends,
I'm new to this forum.
I'm trying to send mail using SMTPAppender.
I am getting this error..
javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.DocumentBuilderFactory cannot be found
at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:772)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:696)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
at org.apache.log4j.Logger.getLogger(Logger.java:105)
at com.honeywell.logging.Log.<clinit>(Log.java:36)
Exception in thread "main"
Here is the code...
Log.java
package com.something.log;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.xml.DOMConfigurator;
import java.net.URL;
import java.util.*;
import javax.mail.Message;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.net.SMTPAppender;
public class Main {
* @param args the command line arguments
private static final Logger lg=Logger.getLogger("com.something.log.Main");
public static void main(String[] args) {
URL url = Loader.getResource("log4j.xml");
DOMConfigurator.configure(url);
// create email appender
SMTPAppender smtpAppender = new SMTPAppender();
smtpAppender.setTo("[email protected]");
smtpAppender.setFrom("[email protected]");
smtpAppender.setSMTPHost("smtp.something.com");
smtpAppender.setSubject("Testing Email");
smtpAppender.setLocationInfo(false);
smtpAppender.setLayout(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"));
smtpAppender.activateOptions();
// add email appender
lg.addAppender(smtpAppender);
log4j.xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="file"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="logs/log.txt" />
<param name="threshold" value="info"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="mail" class="org.apache.log4j.net.SMTPAppender">
<param name="SMTPHost" value="smtp.something.com" />
<param name="From" value="[email protected]" />
<param name="To" value="[email protected]" />
<param name="Subject" value="[LOG] ..." />
<param name="BufferSize" value="1" />
<param name="threshold" value="error" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<priority value="debug"></priority>
<appender-ref ref="file" />
<appender-ref ref="mail"/>
</root>
</log4j:configuration>
log4j.properties
log4j.rootLogger=warn, file, mail
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=D:\log.txt
log4j.appender.file.threshold=info
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
#email appender
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#defines how othen emails are send
log4j.appender.mail.BufferSize=1
log4j.appender.mail.SMTPHost="smtp.something.com"
[email protected]
[email protected]
log4j.appender.mail.Subject=Log ...
log4j.appender.mail.threshold=error
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
Please help me in fixing the problem.....
Is this code correct to send email...??I've not reviewed all of your code/config there, but the error seems to me to indicate a problem parsing your log4j.xml file - have you been able to get a simple configuration working? Can you parse other XML files?
Good Luck
Lee -
How to send mail using jsp program
am very new to jsp and doing my final year project. i need to send mails using my jsp program.can anyone say wht to do that is wht to include to send mails using jsp program. n also a sample code to send mail using jsp program.
Thanx in advanceUse below script.
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
Properties props = new Properties();
props.put("mail.smtp.host", "mailserver.com");
Session s = Session.getInstance(props,null);
InternetAddress from = new InternetAddress("[email protected]");
InternetAddress to = new InternetAddress([email protected]");
MimeMessage message = new MimeMessage(s);
message.setFrom(from);
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("Your subject");
message.setText("Your text");
Transport.send(message);
%>{code} -
How to use VBA to View PDF file and use an OCR object?
As subject, I need to use VBA to open PDFs via Acrobat. Convert images to texts. And get some key words from the documents.
But I cannot find the API for VBA from SDK.The API for VB is part of the "Interapplication Communication" section, specifically the part for "OLE". You can also use much of the JavaScript API through a VB:JavaScript linkage.
I don't know if there is an API to running OCR. -
Hi all,
see below it.
TABLES: ZST2.
DATA : BEGIN OF ITAB OCCURS 0,
EMPNO LIKE ZST2-EMPNO,
EMPNAME LIKE ZST2-EMPNAME,
END OF ITAB.
DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.
START-OF-SELECTION.
SELECT EMPNO EMPNAME "PERNR ENAME
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM ZST2."WHERE PERNR < 50.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-EMPNO, 15 SY-VLINE , ITAB-EMPNAME.
*SY-VLINE.
ENDLOOP.
Receivers
receiver_list-recextnam = 'ur@company'. "-->
EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
Mail subject
w_object_hd_change-objdes = 'Message subject'.
Mail body
APPEND 'Message content' TO message_content.
Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.
how prepared it?
thx,
s.sureshhi,
chek this,,
TABLES :VARID. "Variant directory
DATA: GV_NAMES LIKE TSP01-RQ2NAME,
GD_BYTECOUNT LIKE TST01-DSIZE,
GD_BUFFER TYPE STRING,
PDF_LINES TYPE TLINE OCCURS 0 WITH HEADER LINE,
SEND_REQUEST TYPE REF TO CL_BCS,
L_SUBJECT LIKE SOOD-OBJDES,
DOCUMENT TYPE REF TO CL_DOCUMENT_BCS,
BCS_EXCEPTION TYPE REF TO CX_BCS,
V_CTR TYPE I VALUE 0,
IT_INPUT LIKE BDI_LINE OCCURS 0 WITH HEADER LINE,
IT_MESS_ATT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
IT_BINARY_CONT TYPE SOLIX_TAB,
LEN_OUT TYPE I,
T_SPONO LIKE TSP01SYS OCCURS 0 WITH HEADER LINE.
DATA :GV_RQCRETIME LIKE TSP01-RQCRETIME.
DATA IT_VALUE LIKE RSPARAMS OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF T_VARID OCCURS 0,
VARIANT LIKE VARID-VARIANT,
END OF T_VARID.
SELECTION SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_VAR FOR VARID-VARIANT.
SELECTION-SCREEN END OF BLOCK B1.
Select the varinat name from the table VARID
SELECT VARIANT INTO TABLE T_VARID
FROM VARID
WHERE REPORT EQ 'ZAMRP003'
AND VARIANT IN S_VAR.
SORT T_VARID.
CHECK NOT T_VARID[] IS INITIAL.
LOOP AT T_VARID.
SUBMIT ZAMRP003 USING SELECTION-SET T_VARID-VARIANT
TO SAP-SPOOL SAP COVER PAGE ' '
DESTINATION ' '
IMMEDIATELY 'X'
KEEP IN SPOOL 'X'
LINE-COUNT 60000
LINE-SIZE 134
LAYOUT 'X_58_170'
WITHOUT SPOOL DYNPRO AND RETURN.
COMMIT WORK AND WAIT.
CONCATENATE SY-DATUM '000000' INTO GV_RQCRETIME.
CONCATENATE 'ZAMRP003_' SY-UNAME+0(3) INTO GV_NAMES.
SELECT * FROM TSP01 INTO TABLE T_SPONO
WHERE RQCLIENT = SY-MANDT
AND RQ0NAME = 'LIST1S'
AND RQ2NAME = GV_NAMES
AND RQOWNER = SY-UNAME
AND RQCRETIME GE GV_RQCRETIME.
SORT T_SPONO BY RQIDENT DESCENDING.
CALL FUNCTION 'RS_VARIANT_CONTENTS'
EXPORTING
REPORT = 'ZAMRP003'
VARIANT = T_VARID-VARIANT
TABLES
VALUTAB = IT_VALUE
EXCEPTIONS
VARIANT_NON_EXISTENT = 1
VARIANT_OBSOLETE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE E000(ZH) WITH 'Error in processing variant'.
ENDIF.
Create the email request
PERFORM CREATE_EMAIL .
SORT T_SPONO BY RQIDENT DESCENDING.
READ TABLE T_SPONO INDEX 1.
IF SY-SUBRC NE 0.
MESSAGE E000(ZH) WITH 'Error creating spool'
RAISING CONVERSION_ERROR.
ENDIF.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = T_SPONO-RQIDENT
NO_DIALOG = ' '
IMPORTING
PDF_BYTECOUNT = GD_BYTECOUNT
TABLES
PDF = PDF_LINES
EXCEPTIONS
ERR_NO_ABAP_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DESTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11
OTHERS = 12.
IF SY-SUBRC <> 0.
MESSAGE E000(ZH) WITH 'Error converting spool to PDF'
RAISING CONVERSION_ERROR.
ENDIF.
Transfer the 132-long strings to 255-long strings
LOOP AT PDF_LINES.
TRANSLATE PDF_LINES USING ' ~'.
CONCATENATE GD_BUFFER PDF_LINES INTO GD_BUFFER.
ENDLOOP.
TRANSLATE GD_BUFFER USING '~ '.
DO.
IT_MESS_ATT = GD_BUFFER.
APPEND IT_MESS_ATT.
SHIFT GD_BUFFER LEFT BY 255 PLACES.
IF GD_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Convert format of PDF data to that required for email
REFRESH IT_BINARY_CONT.
PERFORM CONVERT_134_TO_255_STR TABLES IT_MESS_ATT
IT_BINARY_CONT.
Now add it as an attachment
CONCATENATE 'ZAMRP003' '.pdf' INTO L_SUBJECT.
TRY.
CALL METHOD DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = 'PDF'
I_ATTACHMENT_SUBJECT = L_SUBJECT
I_ATT_CONTENT_HEX = IT_BINARY_CONT.
Add document to send request
CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
CATCH CX_BCS INTO BCS_EXCEPTION.
Send the message that occurred and then exit
MESSAGE ID BCS_EXCEPTION->MSGID
TYPE BCS_EXCEPTION->MSGTY
NUMBER BCS_EXCEPTION->MSGNO
WITH BCS_EXCEPTION->MSGV1 BCS_EXCEPTION->MSGV2
BCS_EXCEPTION->MSGV3 BCS_EXCEPTION->MSGV4.
EXIT.
ENDTRY.
Send the email now
PERFORM SEND_THE_EMAIL CHANGING SEND_REQUEST.
COMMIT WORK.
ENDLOOP.
*& Form convert_134_to_255_str
text
FORM CONVERT_134_TO_255_STR TABLES PT_134
PT_255.
DATA: L_DSN(100).
L_DSN = 'c:\temp\text_workarea.txt'.
Output file in 134 byte blocks
OPEN DATASET L_DSN FOR OUTPUT IN BINARY MODE.
IF SY-SUBRC NE 0.
WRITE :/ 'Error in PDF Conversion'.
STOP.
ENDIF.
LOOP AT PT_134.
TRANSFER PT_134 TO L_DSN.
ENDLOOP.
CLOSE DATASET L_DSN.
Read file in 255 byte blocks
OPEN DATASET L_DSN FOR INPUT IN BINARY MODE.
IF SY-SUBRC NE 0.
WRITE :/ 'Error in PDF Conversion'.
STOP.
ENDIF.
READ DATASET L_DSN INTO PT_255.
WHILE SY-SUBRC = 0.
APPEND PT_255.
READ DATASET L_DSN INTO PT_255.
ENDWHILE.
APPEND PT_255.
CLOSE DATASET L_DSN.
Clear file
OPEN DATASET L_DSN FOR OUTPUT IN BINARY MODE.
CLOSE DATASET L_DSN.
ENDFORM. " convert_134_to_255_str
*& Form send_the_email
text
FORM SEND_THE_EMAIL CHANGING P_SEND_REQUEST TYPE REF TO CL_BCS.
DATA: L_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS,
L_SENT_TO_ALL TYPE OS_BOOLEAN,
LT_RECIP_ERROR TYPE BCSY_RE,
LT_ORIG_ERROR TYPE BCSY_ERCP,
LV_STR TYPE SZA5_D0700-SMTP_ADDR.
TRY.
Add recipients (e-mail address) ----------------------
LOOP AT IT_VALUE WHERE SELNAME = 'S_USER'.
Create recipient
LV_STR = IT_VALUE-LOW.
L_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
LV_STR ).
Add recipient with its respective attributes to send request
SEND_REQUEST->ADD_RECIPIENT( L_RECIPIENT ).
ENDLOOP.
Send document ---------------------------------------
CALL METHOD SEND_REQUEST->SEND_WITHOUT_DIALOG(
IMPORTING
E_RECIPIENTS_WITH_ERROR = LT_RECIP_ERROR
E_ORIG_RECS_WITH_ERROR = LT_ORIG_ERROR
E_SENT_TO_ALL = L_SENT_TO_ALL ).
For internet addresses, this should always be OK. It is only later
that an express message is sent if it fails. Hence no need to do
much error processing here.
IF L_SENT_TO_ALL = 'X'.
MESSAGE I217(ZH). "Sent to all recipients.
ENDIF.
CATCH CX_BCS INTO BCS_EXCEPTION.
Send the message that occurred and then exit
MESSAGE ID BCS_EXCEPTION->MSGID
TYPE BCS_EXCEPTION->MSGTY
NUMBER BCS_EXCEPTION->MSGNO
WITH BCS_EXCEPTION->MSGV1 BCS_EXCEPTION->MSGV2
BCS_EXCEPTION->MSGV3 BCS_EXCEPTION->MSGV4.
EXIT.
ENDTRY.
ENDFORM. " send_the_email
*& Form create_email
FORM CREATE_EMAIL.
DATA: SUB TYPE SO_OBJ_DES,
WA_TEXT TYPE SOLI,
LT_TEXT TYPE SOLI_TAB.
TRY.
-------- create persistent send request ------------------------
SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
SEND_REQUEST->SET_STATUS_ATTRIBUTES( 'E' ).
SEND_REQUEST->SEND_REQUEST->SET_LINK_TO_OUTBOX( 'X' ).
-------- create and set document with attachment ---------------
WA_TEXT = 'Dear Recipient,'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = ' '.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = ' '.
APPEND WA_TEXT TO LT_TEXT.
wa_text = 'We apologise for the inaccurate Fixed Asset '.
APPEND wa_text TO lt_text.
wa_text = 'Reports sent to you and any inconvenience caused by'.
APPEND wa_text TO lt_text.
wa_text = 'this error.'.
APPEND wa_text TO lt_text.
wa_text = ' '.
APPEND wa_text TO lt_text.
wa_text = 'The changing of the report from a manual to '.
APPEND wa_text TO lt_text.
wa_text = 'automatic process could not be fully tested in a test'
APPEND wa_text TO lt_text.
wa_text = ' environment and this has led to the problems that'.
APPEND wa_text TO lt_text.
wa_text = ' you have seen. We have now corrected these errors '.
APPEND wa_text TO lt_text.
wa_text = 'and the automated process will continue from now on'.
APPEND wa_text TO lt_text.
wa_text = ''.
APPEND wa_text TO lt_text.
wa_text = 'Thank you for your patience during this time.'.
APPEND wa_text TO lt_text.
wa_text = ''.
APPEND wa_text TO lt_text.
wa_text = ''.
APPEND wa_text TO lt_text.
WA_TEXT = 'This is the monthly fixed asset report for your'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'cost centre(s) which shows assets'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'for the previous calendar month.'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = ' '.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = ' '.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'N.B. The asset locations shown on this report'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'may be long out-of-date and are offered for'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'guidance only.'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'Please note that it is your responsibility to'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'know: Where each asset is; What it is; and Why'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'it is needed?'.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = ' '.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = ' '.
APPEND WA_TEXT TO LT_TEXT.
WA_TEXT = 'For any queries regarding the email or report'.
APPEND WA_TEXT TO LT_TEXT.
*-- Start of changes by SPUSA (001)
wa_text = 'please contact abc@com'.
WA_TEXT = 'please contact abc@com'.com'.
*-- End of changes by SPUSA (001)
APPEND WA_TEXT TO LT_TEXT.
SUB = 'Asset Management'.
DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = 'RAW'
I_TEXT = LT_TEXT
I_LENGTH = '24'
I_SUBJECT = SUB ).
CATCH CX_BCS INTO BCS_EXCEPTION.
Send the message that occurred and then exit
MESSAGE ID BCS_EXCEPTION->MSGID
TYPE BCS_EXCEPTION->MSGTY
NUMBER BCS_EXCEPTION->MSGNO
WITH BCS_EXCEPTION->MSGV1 BCS_EXCEPTION->MSGV2
BCS_EXCEPTION->MSGV3 BCS_EXCEPTION->MSGV4.
EXIT.
ENDTRY.
ENDFORM. " create_email
reward if helpful,
N.Rekha -
Hi,
I am sending an e-mail using java. It works fine, but I wanted to know if there is any possibility to attach a document, without using a File object. Because I have to write the File object and then delete it at the end. I would like to know if I can use for example a byte [], or something else.
Thank you very much.
This is my code, if that helps.
public static void sendWithAttach(String p_sender, String p_receiver, String p_subject,
String p_comment, int p_nombrePiecesJoints, HashMap<String, byte[]> p_files) {
Properties props = System.getProperties();
props.put("mail.smtp.host", Solapcore.getCurrent().getServletConfig().getServletContext().getInitParameter("SMTP"));
Session session = Session.getDefaultInstance(props, null);
MimeMessage sender = new MimeMessage(session);
MimeBodyPart mbp1 = new MimeBodyPart();
Multipart mp = new MimeMultipart();
List<File> listeFiles = new ArrayList<File>();
try {
//On assigne to, from, subject, body, priority
sender.setRecipients(javax.mail.Message.RecipientType.TO,
InternetAddress.parse(p_receiver, false));
sender.setFrom(new InternetAddress(p_sender));
sender.setSubject(p_subject);
mbp1.setText(p_comment);
//sender.setPriority(0);
mp.addBodyPart(mbp1);
//On attache les documents
for(Map.Entry<String, byte[]> entry : p_files.entrySet()) {
MimeBodyPart mbp2 = new MimeBodyPart();
String fileName = entry.getKey();
byte [] dataFile = entry.getValue();
File file = new File(fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(dataFile);
mbp2.attachFile(file);
mbp2.setFileName(fileName);
mp.addBodyPart(mbp2);
listeFiles.add(file);
sender.setContent(mp);
Transport.send(sender);
}catch(MessagingException mex) {
mex.printStackTrace();
}catch(FileNotFoundException fnf) {
fnf.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
}finally {
Iterator<File> itListeFiles = listeFiles.iterator();
while(itListeFiles.hasNext()) {
File tempFile = (File)itListeFiles.next();
tempFile.delete();
}Thank you very much.
public static void sendWithAttach(String p_sender, String p_receiver, String p_subject,
String p_comment, int p_nombrePiecesJoints, HashMap<String, byte[]> p_files) {
Properties props = System.getProperties();
props.put("mail.smtp.host", Solapcore.getCurrent().getServletConfig().getServletContext().getInitParameter("SMTP"));
Session session = Session.getDefaultInstance(props, null);
MimeMessage sender = new MimeMessage(session);
MimeBodyPart mbp1 = new MimeBodyPart();
Multipart mp = new MimeMultipart();
List<File> listeFiles = new ArrayList<File>();
try {
//On assigne to, from, subject, body, priority
sender.setRecipients(javax.mail.Message.RecipientType.TO,
InternetAddress.parse(p_receiver, false));
sender.setFrom(new InternetAddress(p_sender));
sender.setSubject(p_subject);
mbp1.setText(p_comment);
//sender.setPriority(0);
mp.addBodyPart(mbp1);
//On attache les documents
for(Map.Entry<String, byte[]> entry : p_files.entrySet()) {
MimeBodyPart mbp2 = new MimeBodyPart();
String fileName = entry.getKey();
byte [] dataFile = entry.getValue();
File file = new File(fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(dataFile);
mbp2.attachFile(file);
mbp2.setFileName(fileName);
mp.addBodyPart(mbp2);
listeFiles.add(file);
sender.setContent(mp);
Transport.send(sender);
}catch(MessagingException mex) {
mex.printStackTrace();
}catch(FileNotFoundException fnf) {
fnf.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
}finally {
Iterator<File> itListeFiles = listeFiles.iterator();
while(itListeFiles.hasNext()) {
File tempFile = (File)itListeFiles.next();
tempFile.delete();
} -
Hi All,
I am using Oracle 10g database and am trying to send e-mail using the UTL_MAIL.SEND functions.
I followed the instructions given here: http://technotes.towardsjob.com/oracle/utl-mail-package-oracle-10g/
The code that I am trying to execute is :
DECLARE
sender varchar2(64);
recipients varchar2(64);
subject varchar2(64);
message varchar2(64);
pri number;
BEGIN
sender:= '[email protected]';
recipients:= '[email protected]';
subject:= 'Test';
message:= 'Test Message';
UTL_MAIL.SEND(sender,recipients,'[email protected]','[email protected]','null',2);
END;
and I am getting the error
ORA-04063: package body "STERLING.UTL_MAIL" has errors
ORA-06508: PL/SQL: could not find program unit being called
Please help as to what I can do now.
Thanks in advance
Sidhi,
You must both install UTL_MAIL and define the SMTP_OUT_SERVER.
To install UTL_MAIL:
sqlplus sys/<pwd>
SQL> @$ORACLE_HOME/rdbms/admin/utlmail.sql
SQL> @$ORACLE_HOME/rdbms/admin/prvtmail.plb
to give perminssion to a user to send mail
grant execute on utl_mail to username;
EXECUTE UTL_MAIL.send(sender =>'[email protected]',recipients =>'[email protected]',subject =>'Test Mail',message => 'Hello World',mime_type => 'text; charset=us-ascii',priority => 3);
hope this help
regards,
deepak -
MAIL USING PL/SQL PROCEDURE TCP CONNECTION ERROR
I was trying to send an e-mail using the demo-mail helper package which uses UTL_SMTP package and on execution, it gives the following TCP Connection error. Is it some something to do with mail configuration?
This is the sample code I was trying to run.
demo_mail.mail( sender => 'Me <[email protected]>',
recipients => 'Someone <[email protected]>, ' ||
'"Another one" <[email protected]>',
subject => 'Test', message => 'Hi! This is a test.');
And this is the error I am getting.
class oracle/plsql/net/TCPConnection does not exist
at "SYS.UTL_TCP", line 537
at "SYS.UTL_TCP", line 199
at "SYS.UTL_SMTP", line 102
at "SYS.UTL_SMTP", line 121
at "VNARAYA.DEMO_MAIL", line 159
at "VNARAYA.DEMO_MAIL", line 119
at "VNARAYA.DEMO_MAIL", line 105
at "VNARAYA.SEND_MAIL", line 2
at line 1The Java library needed by UTL_TCP is not created properly. You may just run $ORACLE_HOME/rdbms/admin/initplsj.sql as SYS to install it:
cd $ORACLE_HOME/rdbms/admin
sqlplus sys/<sys-password> @initplsj.sql -
Can't down load mail using mail app
Can't down load mail using mail app OS, I already delete the com.apple.mail.plist but didn't work, it can connect to the server and in the progress bar, it appear: incoming messages ex. 39 of 39 but 0kb of transmission. And if I go to the Account info window, I can see the messages on the server, as well as the subject, date received, and the size of them. So, the mail, does connect to the server and see the new mail, but just doesn't download them. I also tried delete the mailbox and create a new one, but the same result.
If I use web mail I can see the mails.
Any clue to fix it.Hi!
I have the same problem, when I go on apple store and look for the Netflix app, it won't found it and when I'm on google I'd tape Netflix app, I click on the link which opens AppStore and a message comes saying "your request cannot be found" please help!!! Thank you
Abi
Maybe you are looking for
-
Best way to write objects in an xml and send the file?
hello all i am making some objects, which i conver to xml using the XStream and then i am saving them to a file, call a function to send the file to a servant (basically i do this by sending bytes and this may be the problem). In the servant i take t
-
Cloning display while keeping native resolutions.
Hi! I want to clone my screen but I want the picture to be displayed in de the native resolutions of both my displays. Situation: I have a 17" MacBook Pro (native resolution =1680x1050) and I have a 19" LCD-panel (native resolution = 1280x1024). Now,
-
I'm running 10.7.1 and iTunes 10.4 (64-bit). When adding artwork to selected items within iTunes via the get info window, the artwork is added TWICE for each item when double-clicking on the artwork box and navigating to the art. However, when select
-
Update GOITEM-ERFMG in MIGO using user exit in SAP ECC 6.0
Dear Gurus, Kindly help me to solve the issue. We have requrement to update GOITEM-ERFMG field at the time of MIGO based on text input in GOHEAD-BKTXT as selection criteria in selection query in Z table. We try to acheive this using different enhance
-
Datas in Infocube in BI Content
hi, when installing an Infocube from BI content whether data will be there inside the cube. else how to populate the data for cubes present in the BI Content. Please help me to understand and how to take sample datas thanks Sankaresh S