Solved

vb.net and Outlook 2010

Posted on 2011-09-30
4
562 Views
Last Modified: 2012-05-12
I have a simple Visual Basic application that emails a report (html format) with Outlook.  It works fine with Outlook 2007, but fails with Outlook 2010.  I've changed the references from Microsoft.Office.Interop.Outlook 12.0 to 14.0, but that didn't help.  The debug code below works with Outlook 2007, but not Outlook 2010.  Any ideas?
Imports Microsoft.Office.Interop.Outlook
Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim HTML As String = "<html><head><title>testtesttest</title></head><body><div><h1>1<br>2<br>3</h1></div></body></html>"
        Dim app As New Microsoft.Office.Interop.Outlook.Application
        Dim appNameSpace As Microsoft.Office.Interop.Outlook._NameSpace = app.GetNamespace("MAPI")
        appNameSpace.Logon(Nothing, Nothing, False, False)
        Dim memo As Microsoft.Office.Interop.Outlook.MailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
        memo.To = "fred.flintstone@rubble.com"
        memo.Subject = "Barney..."
        memo.HTMLBody = HTML
        memo.Display()
    End Sub
End Class

Open in new window

0
Comment
Question by:motokent
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36891587
Do you get an error?
0
 

Author Comment

by:motokent
ID: 36891635
Yes.  See the code section for the error.  I might have stumbled across the solution... just comment out the two lines:
Dim appNameSpace As Microsoft.Office.Interop.Outlook._NameSpace = app.GetNamespace("MAPI")
appNameSpace.Logon(Nothing, Nothing, False, False)

I don't remember why those lines were there to begin with, but they must not be necessary.  Can you comment about them?
System.Runtime.InteropServices.COMException was unhandled
  ErrorCode=-2147221231
  Message=The server is not available. Contact your administrator if this condition persists.
  Source=Microsoft Outlook
  StackTrace:
       at Microsoft.Office.Interop.Outlook.NameSpaceClass.Logon(Object Profile, Object Password, Object ShowDialog, Object NewSession)
       at tryOutlook2010.Form1.Button1_Click(Object sender, EventArgs e) in d:\users\kent\documents\visual studio 2010\Projects\tryOutlook2010\tryOutlook2010\Form1.vb:line 7
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at tryOutlook2010.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Open in new window

0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 36891875
0
 

Author Closing Comment

by:motokent
ID: 36891928
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now