open a new e-mail

waraq

Member
Joined
Dec 18, 2006
Messages
23
Location
Harrison, TN
Programming Experience
Beginner
Hi! I would like to open a new e-mail with a command button from my application. This is the code that "I think will open a new e-mail pane":

PrivateSub Application_NewMail()
Dim objApp As Outlook.Application
Dim objExplorer As Outlook.Explorer
objApp = CreateObject("Outlook.Application")
objExplorer = objApp.ActiveExplorer
With objExplorer
If .IsPaneVisible(1) = FalseThen
.ShowPane(1, True)
EndIf
EndWith
EndSub

This code is not working like it should. But I know I'm doing something wrong, becouse this Outlook.Application and Outlook.Explorer are not define. Please would you guide me how to solve this problem.

Thank You

Waraq
 
You need to add a reference to Outlook before referencing the library. To add a reference, right click on the project in the solution explorer and select add reference, then look for the Outlook entry.

Note that the method you have shown will only work if the user has Outlook installed. When you add a reference, you are referencing a certain version of Outlook, so the user must have that version of Outlook installed. If this is undesirable, you can use late binding.

Looking at your code it appears you are mixing late binding and referenced libraries.

If you don't need to worry about which email client is opened and you only want to open a new email using the user's default email client, you can use the Process class in combination with the mailto command.
 
Hi Thank you for your help. I'm a new in VB.net and the book that I am reading it is not very clear on how to open a new email. I think you have an eassy way to explain. Please be more specific in the Proces Class. I will appriciate it.

Waraq
 
VB.NET:
Using prcss As New Process
    prcss.StartInfo.FileName = "mailto:paszt@foo.com&cc=waraq@foo.org&" & _
      "Bcc=someone@foo.net&subject=Hello&Body=body text"
    prcss.Start()
End Using
The code could be written in one line:
VB.NET:
Process.Start("mailto:paszt@foo.com&cc=waraq@foo.org&Bcc=someone@foo.net&subject=Hello&Body=body text")
but the first is a good idea since the Process class implements IDisposable the "Using" construct assists with Disposing the process once its finished.
 
oh sorry, just noticed you are using V1.1 which doesn't include the "Using" contruct. You will have to call the Dispose method of the process class manually.
 
Back
Top