关于MAPI发邮件退出导致错误的问题
这里是我的代码
Dim sender1 As New MAPISession
Dim message1 As New MAPIMessages
Dim m_path As String
Dim m_file_name As String
Dim m_file As String
sender1.LogonUI = False
sender1.NewSession = True
sender1.DownLoadMail = False
m_path = deBusiness.App_Path + "\attachtemp\"
m_file_name = getscriptname().Replace(".doc", ".zip")
m_file = m_path + m_file_name
sender1.SignOn()
message1.SessionID = sender1.SessionID
message1.Compose()
message1.AddressResolveUI = True
message1.AttachmentIndex = 0
message1.AttachmentPathName = m_file
message1.AttachmentName = m_file_name
message1.MsgSubject = getscriptname().Replace(".doc", "")
message1.MsgNoteText = " "
message1.Send(True)
sender1.SignOff()
当我执行到message1.send(True)的时候出现发邮件的窗口,此时如果正常发送则不会有错误,如果点退出的话就会出现错误:
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2146796287
HelpLink="MAPI98.CHM#32001"
Message="User cancelled process"
Source="MAPIMessages"
StackTrace:
at MSMAPI.MAPIMessagesClass.Send(Object vDialog)
at WordScriptLoader.Form1.sendmailwithattachment() in C:\DemoEnablerProject\WordScriptLoader\WordScriptLoader\Form1.vb:line 2475
at WordScriptLoader.Form1.Send_Click(Object sender, EventArgs e) in C:\DemoEnablerProject\WordScriptLoader\WordScriptLoader\Form1.vb:line 2449
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.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(Int32 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 System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WordScriptLoader.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly 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)
at System.Threading.ThreadHelper.ThreadStart()
麻烦有经验的大哥帮忙解决下吧~~~