[RESOLVED] Try and Catch with outlook
With this code i send a email with outlook.
Code:
Dim application = New Microsoft.Office.Interop.Outlook.Application
Dim outlookEmail = CType(application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem), MailItem)
outlookEmail.To = "*********@gmail.com"
outlookEmail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain
outlookEmail.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal
outlookEmail.Body = ("Test")
outlookEmail.Subject = ("Ok")
outlookEmail.Display(False)
outlookEmail.Send()
it works great , but when there is no outlook on the pc installed the programma crash.
Try and catch is not working ?
The error is
Code:
'Catch' cannot catch type 'Microsoft.Office.Interop.Outlook.Exception' because it is not 'System.Exception' or a class that inherits from 'System.Exception'.
Who can help me ?
Re: Try and Catch with outlook
Depends what you mean by help. There obviously isn't any way to make this work without Outlook so the simplest way round this problem is simply to indicate to any potential users that that's the case and prevent them installing it. However there is actually no reason to involve Outlook at all in something as simple as sending an email.
Re: Try and Catch with outlook
Your code is assuming (You are using Early Binding) that the outlook application will be present. Why not Latebind and then check if the Outlook object exists? See this example
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim OutApp As Object
OutApp = CreateObject("Outlook.Application")
If Not OutApp Is Nothing Then
MessageBox.Show("Outlook is installed")
Else
MessageBox.Show("Outlook is not installed")
End If
End Sub
Re: Try and Catch with outlook
I think i can use this option , thanks
Re: Try and Catch with outlook
Quote:
Originally Posted by
dunfiddlin
However there is actually no reason to involve Outlook at all in something as simple as sending an email.
How else can an email be sent?
Re: [RESOLVED] Try and Catch with outlook
Re: [RESOLVED] Try and Catch with outlook
I have to use Outlook , there is no free internet so i can't use Gmail .
But not on all pc's there is Outlook , that is way i wanted to use try and catch .
Re: [RESOLVED] Try and Catch with outlook
Quote:
Originally Posted by
BASSIES
I have to use Outlook , there is no free internet so i can't use Gmail .
But not on all pc's there is Outlook , that is way i wanted to use try and catch .
This doesn't really make sense. You have to have Internet to send an E-Mail. Why not, then, use the same server (I assume you're using some sort of server that accepts POP3/SMTP calls) that Outlook uses? I mean, you can give it login credentials to allow you to send code. It seems silly to involve Outlook as a middle man when it's quite simple to actually bypass Outlook entirely which removes your dependency on it.