opening outlook new email

Im trying!!

New member
Joined
Mar 11, 2007
Messages
3
Programming Experience
Beginner
Hi

I have created a button to open a new email message in outlook, but do not know the code for this can anyone help?
 
This is what I use.

Bear in mind, depending on the version of outlook (if it's XP or greater) you will get a security popup where after 10 seconds you press "yes" to send the email.
I got around this by using a third party dll called "Redemption".
(I have emails sent to multiple users at different parts of my app and couldn't afford to have that popup everytime for a user)

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oApplication [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Outlook.Application[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] oItem[/SIZE]
[SIZE=2]oItem = oApplication.CreateItem(0)[/SIZE]
 
 
[SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] oItem[/SIZE]
[SIZE=2].Subject = [/SIZE]
[SIZE=2].To = [/SIZE]
[SIZE=2].cc = [/SIZE]
[SIZE=2].BodyFormat = OlBodyFormat.olFormatHTML[/SIZE]
[SIZE=2].HTMLBody = [/SIZE]
[SIZE=2].Send() [COLOR=green]'or you could use .Display() so it shows the message before you send it[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE]

EDIT - you will also need to reference Office in your application, and at the top of the form with the email button use
VB.NET:
Imports Outlook
 
Hello,
create one button and paste the below code,
make sure you paste the function not in button click,
imports outlook
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oOutlook As New Outlook.Application
Dim olApp As Outlook.ApplicationClass = New Outlook.ApplicationClass
Dim olexp As Outlook.Explorer
'Create th Namespace Object
Dim olNS As NameSpaceClass = olApp.GetNamespace("Mapi")
'Logon to Outlook if it's not running
'The Profilename is "Outlook", password ""
'Create a new Mailitem (in the Draftsfolder)
'''Dim objMail As MailItem = olApp.CreateItem(OlItemType.olMailItem)
olexp = olApp.CreateItem(OlItemType.olMailItem)
' The mail to line is not required as the client wants to enter the email address

' manually.

olexp.To = ""
olexp.Subject = "sample email"
olexp.HTMLBody = olexp.BodyFormat
olexp.Body = ltr()
olexp.Save()
olexp.Display()
'Logoff from Session
'Release Marshal-Com Objects
System.Runtime.InteropServices.Marshal.ReleaseComObject(olexp)
System.Runtime.InteropServices.Marshal.ReleaseComObject(olApp)
End Sub
Private Function ltr() As String
Dim sr As StreamReader
sr = File.OpenText("D:\Documents and Settings\Yogi\Desktop\Letters.html")
Dim _filetext As String = sr.ReadToEnd()
sr.Close()
Return _filetext
End Function
 
Last edited:

Latest posts

Back
Top