Solved

vb.net and Outlook 2010

Posted on 2011-09-30
4
564 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 70

Accepted Solution

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

Author Closing Comment

by:motokent
ID: 36891928
Thanks.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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