How can I automate oultlook so that I can provide the user with a new message with something like "to:abc@abc.com" and is ready for the user to just type in the body of the message?
Ikim2000 - I see that you have started 13 threads, and have only said thank you once, and have yet to indicate that any post has been helpful.
Since you're fairly new to the forum, yet may not be aware that Tek-Tips is a forum by and between professionals, it is not a tech support site, and its a good practice to share as you can with other members of the forum and to show professional courtesy when warranted.
That being said, I suggest that you do a search on this forum for MAPI - <tappety tappety tap> - Ah Yes : try thread222-485548 where I answered the question today
See also faq222-2244
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
Mailto also let's you add the subject and message body but is limited to a few hundred chars in total. It can't add attachments or send the e-mail. For anything more complicated you need to automate Outlook. Try
Paul,
Neat tip! I never thought of this approach. Can you let us in on the syntax for adding the subject and/or body text? I searched the net but didn't find much info on subject and body...
Thanks,
sdraper
If you want to do something that requires automation, are using Outlook 98, 2000 or 20002 and don't want to spend time learning the object model then check out my OLServices ActiveX library; evaluation copy available at my web site.
Re Mailto: the following is an extract from an FAQ I wrote for a Lotus Approach support site that I host. The LotusScript language is very similar to VBA so you should be able to adapt this where necessary. It shows how to add the recipient, subject and body. Multiple recipients should be separated with semi-colons. Search the web for RFC2368 for more details of the mailto protocol.
>>You can't use Chr(13) & Chr(10) to produce a carriage return in the body; mailto is an internet protocol and expects the equivalent HTML codes. I ususally declare a constant in Globals - Declarations
Public Const HTML_CR = "%0D%0A"
If you're merging text containing carriage returns from the database into the e-mail body then you need to replace them with the above HTML code. This function can be used to carry out the replacement:
Public Function fReplaceCR(Byval strText As String) As String
'--- Strips Lf's and Cr's from a string and replaces them with
'--- a html encoded line break - %0D%0A
'--- a public contstant HTML_CR has been declared
Here's an example subroutine that creates an e-mail addressed to the current record in an Approach database. The e-mail address is displayed in a fieldbox named fbxEmail. The content is read from other fields on the view.
Sub CreateEMail
Dim intRtn As Integer 'Shell function return value
Dim strBody As String 'Message body
Dim strTmp As String 'Temp string buffer
'Build the e-mail body from the salutation, letter and sign off fields
'Replace carriage returns with HTML codes
strBody = CurrentView.Body.fbxSalutation.Text & HTML_CR & HTML_CR
strBody = strBody & fReplaceCR(CurrentView.Body.fbxLettText.Text) _
& HTML_CR & HTML_CR
strBody = strBody & fReplaceCR(CurrentView.Body.fbxSignOff.Text)
'Build the full content: headers and body
'Add the recipient
strTmp = CurrentView.Body.fbxEMail.Text
'Add the subject
strTmp = strTmp & "?Subject=" & CurrentView.Body.fbxSubject.Text
'Add the message body contents
strTmp = strTmp & "&Body=" & strBody
'Create the e-mail
intRtn = Shell("rundll32.exe url.dll,FileProtocolHandler mailto:" & strTmp)
End Sub
3. EML File. If the .eml file extension is registered on the system, you can overcome the mailto limitation that restricts the total content to a few hundred characters. The method is to create a text file, with a .eml extension, containing the e-mail content then Shell the file. Through its registered association and action on open, an e-mail will be created from the file using Outlook Express.
We'll adapt the above example to use a .eml file. In this case the normal Chr(13) and Chr(10) characters are used for carriage returns in the e-mail body.
Also, the LotusScript Shell function can't be used because it will only run an executable. We need to use the Windows ShellExecute function which is declared in Globals - Declarations as follows:
Declare Public Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (Byval hwnd As Long, _
Byval lpOperation As String, Byval lpFile As String, _
Byval lpParameters As String, Byval lpDirectory As String, _
Byval nShowCmd As Long) As Long
Sub CreateEMail
Dim hWnd As Long 'Handle to Approach window
Dim lngRtn As Long 'API function return value
Dim hFile As Integer 'Handle to the .eml file
Dim strFile As String 'Full path/filename of .eml file
Dim strBody As String 'Message body
'Assign the output filename
strFile = "c:\windows\temp\tmp01.eml"
'Get the Approach window handle
hWnd = CurrentWindow.GetHandle
'Build the e-mail body from the salutation, letter and sign off fields
strBody = CurrentView.Body.fbxSalutation.Text & _
Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)
strBody = strBody & CurrentView.Body.fbxLettText.Text _
& Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)
strBody = strBody & CurrentView.Body.fbxSignOff.Text
'Get a free file handle
hFile = FreeFile
'Open the .eml file for writing
Open strFile For Output As hFile
'Add the reply address
Print #hFile, "From: <sales@northwindit.co.uk>"
'Add the recipient
Print #hFile, "To: " & Chr$(34) & CurrentView.Body.fbxEMail.Text & Chr$(34)
'Add the subject
Print #hFile, "Subject: " & CurrentView.Body.fbxSubject.Text
Print #hFile, "X-Unsent: 1"
Print #hFile, 'Blank line
'Add the body
Print #hFile, strBody
Print #hFile, 'Blank line
Close #hFile
Note that you can use the Windows API to get the path to the Windows temp folder. It's covered in the discussion, "Win32 API functions". Unfortunately you can't delete the .eml file from the script immediately after creating the e-mail. It is deleted too quickly and you will get an error message from Outlook Express that the .eml file was not found.<<
Thanks Paul! That answered my question and several others that popped into my head after the fact. I use the Outlook object model extensively in my everyday code and sometimes it seems a bit of overkill. This little ditty will be great for a quick notificaiton email and the like. Really appreciate your information
Thanks Again,
sdraper
Great answer paulbent about alternative answer to automating Outlook..when i use your method, i don't need to worry about the system's email client type, whether the instance already exists, it's much easier if i just want to send an email. thanx,Ike.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.