|
-
May 7th, 2013, 02:13 PM
#1
Thread Starter
Member
[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 ?
-
May 7th, 2013, 02:22 PM
#2
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.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 7th, 2013, 05:12 PM
#3
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
Last edited by Siddharth Rout; May 7th, 2013 at 05:19 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 8th, 2013, 02:08 AM
#4
Thread Starter
Member
Re: Try and Catch with outlook
I think i can use this option , thanks
-
May 8th, 2013, 04:40 AM
#5
Addicted Member
Re: Try and Catch with outlook
 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?
-
May 8th, 2013, 05:15 AM
#6
Re: [RESOLVED] Try and Catch with outlook
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 8th, 2013, 08:13 AM
#7
Thread Starter
Member
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 .
-
May 8th, 2013, 11:41 AM
#8
Re: [RESOLVED] Try and Catch with outlook
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|