关于MAPI发邮件退出导致错误的问题

ltjsjyyy 2008-10-09 03:20:46
这里是我的代码
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()
麻烦有经验的大哥帮忙解决下吧~~~
...全文
262 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
paulin 2008-10-10
  • 打赏
  • 举报
回复
嗯 发现退出的话组件会强制释放调用的进程资源
改用word下的发送邮件,关闭也没有问题

object oMissing = System.Reflection.Missing.Value;

Word._Application oWord;

Word._Document oDoc;

object oTemplate = "c:\\11.doc";

oWord = new Word.Application();

oWord.Visible = false;

oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

oDoc.SendMail();

oDoc.Close(ref oMissing, ref oMissing, ref oMissing);

oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
华芸智森 2008-10-09
  • 打赏
  • 举报
回复
发送完后调用一次:
message1.Dispose
sender1.Dispose
ltjsjyyy 2008-10-09
  • 打赏
  • 举报
回复
CdoSys和System.Web.Mail
这2个是直接发出去了?还是出来界面让用户自己发送?
paulin 2008-10-09
  • 打赏
  • 举报
回复
如果急的话先换别的发送附件吧
http://support.microsoft.com/kb/310212/zh-cn

http://blog.csdn.net/egxsun/archive/2007/01/31/1498971.aspx
paulin 2008-10-09
  • 打赏
  • 举报
回复
是的,的确是退出时有问题,我试了下还是不行
如果你在outlook中设置立即发送邮件就不可能出现退出的情况了吧..

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧