在 C# Windows 窗体上使用 System.Net.Mail 发送邮件
真正简单的问题(所以我想),我只想从我的表单发送邮件,而不必 Exit() 或 Restart()。
我查看了很多示例,它们都可以工作,但不能在表单内工作,我让它工作的唯一方法是通过调用:
MySmtpClient.Send(MyMailMessage);
MySmtpClient.Dispose();
但这在 .NET 2.0 中不可用(我的用户在他们的计算机上拥有什么) .
所以我尝试使用
MySmtpClient.SendAsync(MyMailMessage, MyMailMessage);
然后在触发 SendCompleted 事件处理程序后进行处理,但只有当我使用 Application.Exit();
退出表单时才会触发它;
我是否缺少一些简单的东西?
谢谢。
Real simple question (so I thought), I just want to send mail from my form without having to Exit() or Restart().
I've looked through many examples and they all work but not within a form and the only way I've gotten it to work is by calling:
MySmtpClient.Send(MyMailMessage);
MySmtpClient.Dispose();
But this is not available in .NET 2.0 (what my users' have on their machines).
So I tried using
MySmtpClient.SendAsync(MyMailMessage, MyMailMessage);
and then disposing after the SendCompleted event handler was triggered but it only gets triggered when I exit my form with Application.Exit();
Am I missing something simple?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 ScottGu 的博客
来自 MSDN
看起来.NET 2.0 SmtpClient 没有实现IDisposable。如果它正在占用您表单的资源,那么:
From ScottGu's blog
From MSDN
It looks like in .NET 2.0 SmtpClient did not implement IDisposable. If it's eating your form's resources, how about: