Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Issue from VB 2

Status
Not open for further replies.

Mavors

Programmer
Aug 28, 2000
43
0
0
US
I am trying to open the default email program on the system my application is running on through the clicking of an email address on one of my forms. Does anyone happen to know of an easy way to open a new email compose through code?

Thanx in advance,
Mavors
Cincinnati, Ohio
 
Option Explicit
Private Declare 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

ShellExecute 0&, "Open", "mailto: " + strMailAddress, "", "", vbNormal
 
If your default Email is Microsoft OutLook then you can set a reference to the Microsoft.Outlook 9.0 Object Library and use the following code example;

Sub SendEmail()
Dim olapp As Outlook.Application
Dim oitem As Outlook.MailItem
Dim sSubject As String
Dim sBody As String
Dim sTo As String

sSubject = "You Have Mail!"
sBody = "Message information."
'Set ComBcc.Value = ""
'Set ComCc.Value = ""
sTo = "Gary.Stewart@onebox.com"
Set olapp = New Outlook.Application
Set oitem = olapp.CreateItem(olMailItem)
With oitem
.Subject = sSubject
.To = sTo
.Body = sBody
.Send
End With
Set olapp = Nothing
Set oitem = Nothing

End Sub
 
Thank you Strongm and StewartGW for the replies. I am not sure all the users of my application will be using Outlook so I think the API will work the best for my situation.

Thank you for all the help. Mavors
Cincinnati, Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top