rasaraja
asked on
Outlook Express Automation
Is it possible to use outlook express through VB?( The way Outlook ( !Express) uses automation??)If so, how can it be done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please check in your Project References, if Microsoft Outlook Express is listed. If it is listed, you can check it and use for automation.
Hi,
If u have Outlook express listed in your Project-References Menu then the following code will work
Public golApp As Outlook.Application
Public gnspNameSpace As Outlook.NameSpace
Function InitializeOutlook() As Boolean
On Error GoTo Init_Err
Set golApp = New Outlook.Application ' Application object.
Set gnspNameSpace = golApp.GetNamespace("MAPI" ) ' Namespace object.
InitializeOutlook = True
Init_End:
Exit Function
Init_Err:
InitializeOutlook = False
Resume Init_End
End Function
Function CreateMail(astrRecip As Variant, strSubject As String, strMessage As String, Optional astrAttachments As Variant) As Boolean
Dim objNewMail As Outlook.MailItem
Dim varRecip As Variant
Dim varAttach As Variant
Dim blnResolveSuccess As Boolean
On Error GoTo CreateMail_Err
If golApp Is Nothing Then
If InitializeOutlook = False Then
MsgBox "Unable to initialize Outlook Application " & "or NameSpace object variables!"
Exit Function
End If
End If
Set golApp = New Outlook.Application
Set objNewMail = golApp.CreateItem(olMailIt em)
With objNewMail
blnResolveSuccess = .Recipients.ResolveAll
objNewMail.Display
.To = astrRecip
.Subject = strSubject
.Body = strMessage
End With
CreateMail = True
CreateMail_End:
Exit Function
CreateMail_Err:
CreateMail = False
Resume CreateMail_End
End Function
call the function using the following code
CreateMail email1.Text, "Message", ""
bye
:-)
Mohan
If u have Outlook express listed in your Project-References Menu then the following code will work
Public golApp As Outlook.Application
Public gnspNameSpace As Outlook.NameSpace
Function InitializeOutlook() As Boolean
On Error GoTo Init_Err
Set golApp = New Outlook.Application ' Application object.
Set gnspNameSpace = golApp.GetNamespace("MAPI"
InitializeOutlook = True
Init_End:
Exit Function
Init_Err:
InitializeOutlook = False
Resume Init_End
End Function
Function CreateMail(astrRecip As Variant, strSubject As String, strMessage As String, Optional astrAttachments As Variant) As Boolean
Dim objNewMail As Outlook.MailItem
Dim varRecip As Variant
Dim varAttach As Variant
Dim blnResolveSuccess As Boolean
On Error GoTo CreateMail_Err
If golApp Is Nothing Then
If InitializeOutlook = False Then
MsgBox "Unable to initialize Outlook Application " & "or NameSpace object variables!"
Exit Function
End If
End If
Set golApp = New Outlook.Application
Set objNewMail = golApp.CreateItem(olMailIt
With objNewMail
blnResolveSuccess = .Recipients.ResolveAll
objNewMail.Display
.To = astrRecip
.Subject = strSubject
.Body = strMessage
End With
CreateMail = True
CreateMail_End:
Exit Function
CreateMail_Err:
CreateMail = False
Resume CreateMail_End
End Function
call the function using the following code
CreateMail email1.Text, "Message", ""
bye
:-)
Mohan
<ping>.. Listening
The presence of outlook express library depends of IE version, version 5 and above doesn't expose that.
ASKER
Hi ,
cmgarnett u'r code was excellent.Thanks a lot.
Mohan u'r stuff is for Microsoft Outlook and not Outlook Express.
Bye.
cmgarnett u'r code was excellent.Thanks a lot.
Mohan u'r stuff is for Microsoft Outlook and not Outlook Express.
Bye.