Solved

vb.net and Outlook 2010

Posted on 2011-09-30
4
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

739 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