Quote:
>Hello everyone. I am new to Visual Basic and I was wondering if anyone
>knows if it is hard to launch an email program and send an email
>automatically from using Visual Basic. I need to send a mail
>every X:th minute during the night and this needs to be done
>automatically. Anyone out there that can help me?
>Feel free to reply here or drop me a mail at
>Jani Ekonoja
Hi Jani,
A bit of deja-vu here - I just found out how to do this 20 minutes
ago...
This is directly from the Microsoft KB (article Q161833 )
It works perfectly for me on a WinNT machine with Outlook. although I
changed the command button to a function for my needs.
Hope this is useful
Darragh
===============================
HOWTO: Send Mail from Visual Basic Using OLE Messaging
The information in this article applies to:
Standard, Professional, and Enterprise Editions of Microsoft Visual
Basic, 16-bit and 32-bit, for Windows, version 4.0
SUMMARY
This article outlines the steps necessary to programmatically send an
e-mail message from Visual Basic using the OLE Messaging Library. This
example assumes that the OLE Messaging Library was properly installed
on your computer (typically, by installing Exchange).
The sample code can also be used from VBA, allowing Access, Excel, or
Project to send e-mail via the OLE Messaging Library.
MORE INFORMATION
With the OLE Messaging Library, you can quickly and easily add e-mail
capabilities (that is, sending and receiving e-mail messages, and
interacting with folders and address books) to your Visual Basic
application. You can create programmable messaging objects, and then
use their properties and methods to meet the needs of your
application.
The objects and methods exposed by the OLE Messaging Library are much
more robust than the MAPI controls that ship with Visual Basic, thus
allowing access to many MAPI properties that the MSMAPI OCX controls
simply do not address.
"Microsoft OLE Messaging Library Programmers Reference" is available
in the Microsoft Developer Network (MSDN), or the Olemsg.hlp file that
installs with Exchange Forms Designer 4.0.
NOTE: If this object library is not available in the References list,
click the Browse button and search your Windows\System folder for the
file Mdisp32.tlb.
Sample Code
To build a Visual Basic project that sends a simple message, follow
these steps:
1. Open a new project in Visual Basic.
2. On the Tools menu, choose References and select the Microsoft CDO
1.21
Library.
3. Add a CommandButton to the default form. Accept the default name,
Command1.
4. Copy the following code into the General Declarations section of
the
default form:
Option Explicit
Private Sub Command1_Click()
Dim objSession As Object
Dim objMessage As Object
Dim objRecipient As Object
'Create the Session Object
Set objSession = CreateObject("mapi.session")
'Logon using the session object
'Specify a valid profile name if you want to
'Avoid the logon dialog box
objSession.Logon profileName:="MS Exchange Settings"
'Add a new message object to the OutBox
Set objMessage = objSession.Outbox.Messages.Add
'Set the properties of the message object
objMessage.subject = "This is a test."
objMessage.Text = "This is the message text."
'Add a recipient object to the objMessage.Recipients collection
Set objRecipient = objMessage.Recipients.Add
'Set the properties of the recipient object
objRecipient.Name = "John Doe" '<---Replace this with a valid
'display name or e-mail alias
objRecipient.Type = mapiTo
objRecipient.Resolve
'Send the message
objMessage.Send showDialog:=False
MsgBox "Message sent successfully!"
'Logoff using the session object
objSession.Logoff
End Sub
5. Run the project. Click Command1. You have sent e-mail from Visual
Basic.
REFERENCES
Microsoft OLE Messaging Library Programmers Reference
For additional information about Collaboration Data Objects versus
Active Messaging, please see the following article in the Microsoft
Knowledge Base:
ARTICLE-ID: Q176916
TITLE : INFO: Active Messaging and Collaboration Data Objects
(CDO)
Keywords : kbprg ActMsg OLEMSG vbwin
Technology : kbole kbvba
Version : WINDOWS:4.0, 1.2
Platform : WINDOWS
Issue type : kbhowto