Results 1 to 8 of 8

Thread: [RESOLVED] Try and Catch with outlook

  1. #1

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    Resolved [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 ?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  4. #4

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    Re: Try and Catch with outlook

    I think i can use this option , thanks

  5. #5
    Addicted Member
    Join Date
    Sep 2009
    Location
    Australia
    Posts
    130

    Re: Try and Catch with outlook

    Quote Originally Posted by dunfiddlin View Post
    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?

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Try and Catch with outlook

    There are many ways. If you search google, it is full of such examples. Here are couple of them

    1. http://social.msdn.microsoft.com/For...b-7aa19973b328 See Kevininstructor's and Paul's post
    2. http://www.codeproject.com/Articles/...ws-application
    3. http://www.codeproject.com/Articles/...mail-in-VB-net
    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

  7. #7

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    48

    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 .

  8. #8

    Re: [RESOLVED] Try and Catch with outlook

    Quote Originally Posted by BASSIES View Post
    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
  •  



Click Here to Expand Forum to Full Width