smtpClient.Send套接字错误 [英] smtpClient.Send socket error

查看:111
本文介绍了smtpClient.Send套接字错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

smtpClient.Send(消息)


导致我按照以下跟踪中的具体细节出现问题。发送电子邮件

,但通常在发送第二封电子邮件时不会出现此错误,但有时在运行应用程序时,即使是第一次,也需要

。应用程序将需要发送重复的电子邮件,大约每秒一次或

两次。

这必须异步完成吗?谢谢。 -Greg


我收到一般错误消息;

故障排除异常:System.ObjectDisposedException''安全句柄

已关闭''


当对已处置的对象(例如封闭的流或注册表项)尝试操作
时,抛出ObjectDisposedException异常。


确保在尝试使用之前没有释放资源。

例如,如果尝试操作流,请确保它没有

之前已关闭。


System.Net.Sockets详细:0:[2568]退出套接字#43667493 :: Send() - >

1024#1024

System.Net.Sockets详细:0:[2568]套接字#43667493 ::发送()

System.Net.Sockets详细:0:[2568]数据来自Socket#43667493 ::发送

System.Net.Sockets详细:0:[2568] 00000000:52 65 63 4E 61 6D 65

7D-3C 42 52 3E 3D 30 44 3D:RecName}< BR> = 0D =

Sys tem.Net.Sockets详细:0:[2568] 00000010:30 41 54 6F 74 61 6C

4D-6F 76 65 2E 63 6F 6D 3C:0Axxxx.com<

System.Net.Sockets详细:0:[2568] 00000020:42 52 3E 3D 30 44 3D

30-41 28 38 37 37 29 20 39:BR> = 0D = 0A(877 )9

System.Net.Sockets详细:0:[2568] 00000030:36 38 2D 4D 4F 56 45

20-28 36 36 38 33 29 3C 42: 68-MOVE(6683)< B

System.Net.Sockets详细:0:[2568] 00000040:52 3E 3D 0D 0A 3D 30

44-3D 30 41 7B 52 65 63 45:R> = .. = 0D = 0A {RecE

System.Net.Sockets详细:0:[2568] 00000050:6D 61 69 6C 7D 3C 42
52-3E 3D 30 44 3D 30 41 3C:mail}< BR> = 0D = 0A<

System.Net.Sockets详细:0:[2568] 00000060:2F 66 6F 6E 74 3E 3C

2F-74 64 3E 3C 2F 74 72 3E:/ font>< / td>< / tr>

System.Net。插座详细:0:[2568] 00000070:3C 2F 74 61 62 6C 65

3E-3C 2F 62 6F 64 79 3E 3C:< / table>< / body> <

System.Net.Sockets详细:0:[2568] 00000080:2F 68 74 6D 6C 3E:

/ html>

System.Net.Sockets详细:0:[2568]退出套接字#43667493 :: Send() - >

134#134

System.Net.Sockets详细信息: 0:[2568]套接字#43667493 ::发送()

System.Net.Sockets详细:0:[2568]数据来自套接字#43667493 ::发送

系统.Net.Sockets详细:0:[2568] 00000000:0D 0A:..

System.Net.Sockets详细:0:[2568]退出套接字#43667493 :: Send() - >

2#2

System.Net.Sockets详细:0:[2568]套接字#43667493 ::发送()

System.Net .Sockets详细:0:[2568]数据来自Socket#43667493 ::发送

System.Net.Sockets详细:0:[2568] 00000000:0D 0A 2E 0D 0A:.....

System.Net.Sockets详细:0:[2568]退出套接字#43667493 ::发送() - >

5#5

System.Net.Sockets详细:0:[2568]套接字#43667493 ::接收()

System.Net.Sockets Verbo se:0:[2568]数据来自套接字#43667493 ::接收

System.Net.Sockets详细:0:[2568] 00000000:32 35 30 20 4D 61 69

6C-20 71 75 65 75 65 64 20:250邮件排队

System.Net.Sockets详细:0:[2568] 00000010:66 6F 72 20 64 65 6C

69-76 65 72 79 2E 0D 0A:交货......

System.Net.Sockets详细:0:[2568]退出

套接字#43667493 :: Receive() - > 31#31

System.Net详细:0:[2568]退出SmtpClient#25675301 ::发送()

System.Net.Sockets详细:0:[5560]套接字#57792633 :: Dispose()

System.Net.Sockets详细:0:[5560]套接字#57792633 ::关闭(两者都#2)

System.Transactions严重:0:< TraceRecord

xmlns =" http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"

Severity =" Critical" ;>< TraceIdentifier> http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled< / TraceIdentifier>< Description>未处理

例外< ; /描述>< AppDomain> LeadProcessingServiceConsol e.vshost.exe< / AppDomain>< Exception>< ExceptionType> System.ObjectD isposedException,

mscorlib,Version = 2.0.0.0,Culture = neutral ,

PublicKeyToken = b77a5c561934e089< / ExceptionType><消息>安全句柄已经

已关闭< / Message>< Sta ckTrace>在

System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket

socketHandle,Int32如何)

在System.Net.Sockets.Socket。关闭(SocketShutdown如何)

at

?.Finalize()< / StackTrace>< ExceptionString> System.ObjectDisposedE xception:

安全句柄已关闭

在System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket

socketHandle,Int32如何)

在System.Net上。 Sockets.Socket.Shutdown(SocketShutdown如何)

at?.Finalize()< / ExceptionString>< / Exception>< / TraceRecord>

System.Net错误:0:[5560]

中的异常#62476613 :: UnhandledExceptionHandler - 安全句柄已关闭

System.Net错误:0:[5560] at

System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket

socketHandle,Int32如何)

在System.Net.Sockets.Socket.Shutdown(SocketShutdown如何)

at?.Finaliz e()

解决方案

> smtpClient.Send(message)

我收到一般错误消息;
疑难解答异常:System.ObjectDisposedException''安全句柄
已关闭''
必须异步完成吗?谢谢。 -Greg




显然,SmtpClient正在最终确定底层套接字两次;它b / b
可能意味着你在使用SmtpClient时它处于一个合适的状态,尽管很难知道为什么不知道是什么

你的代码看起来像。应该没有必要异步进行,

虽然它更整洁;在这种情况下,人们会期望同步发送

以便更可靠,因为您可以确定

SmtpClient已完成发送上一条消息;如果你因为它是异步的那样翻了两倍

发送,那会导致异常。

如果你能发布一些代码会有所帮助,不过。


不,没有必要使用线程,但不知道你是如何*

这样做,我不能告诉你更多。


-

HTH,


Kevin Spencer

微软MVP

专业Numbskull


努力工作是一种药物

没有安慰剂。


" hazz" <公顷** @ sonic.net>在消息中写道

news:uT ************** @ TK2MSFTNGP02.phx.gbl ...

smtpClient.Send(message )

根据下面的描述中的细节导致我出现问题。发送电子邮件
但通常在发送第二封电子邮件时没有此错误,但有时在运行应用程序时,即使是第一次。应用程序将需要发送重复的电子邮件,大约每秒一两个。
这必须异步完成吗?谢谢。 -Greg

我收到一般错误消息;
异常故障排除:System.ObjectDisposedException''安全
句柄已关闭''
一个ObjectDisposedException尝试对已处置的对象(例如封闭的流或注册表项)执行操作时抛出异常。

确保在尝试使用之前未释放资源。


System.Net.Sockets详细:0:[2568]退出套接字#43667493 :: Send() - >
1024#1024
System.Net.Sockets详细:0:[2568]套接字#43667493 ::发送()
System.Net。套接字详细:0:[2568]来自套接字#43667493的数据::发送
System.Net.Sockets详细:0:[2568] 00000000:52 65 63 4E 61 6D 65
7D-3C 42 52 3E 3D 30 44 3D:RecName}< BR> = 0D =
System.Net.Sockets详细:0:[2568] 00000010:30 41 54 6F 74 61 6C 4D-6F 76 65 2E 63 6F 6D 3C:0Axxxx.com<
System.Net.Sockets详细:0:[2568] 00000020:42 52 3E 3D 30 44 3D
30-41 28 38 37 37 29 20 39:BR> = 0D = 0A(877)9
System.Net.Sockets详细:0:[2568] 00000030:36 38 2D 4D 4F 56 45
20-28 36 36 38 33 29 3C 42:68-MOVE(6683)< B
System.Net.Sockets详细:0:[2568] 00000040:52 3E 3D 0D 0A 3D 30
44-3D 30 41 7B 52 65 63 45:R> = .. = 0D = 0A {RecE
System.Net.Sockets详细:0:[2568] 00000050:6D 61 69 6C 7D 3C 42
52-3E 3D 30 44 3D 30 41 3C:mail}< BR> = 0D = 0A<
System.Net.Sockets详细:0:[2568] 00000060:2F 66 6F 6E 74 3E 3C
2F-74 64 3E 3C 2F 74 72 3E:/ font>< / td>< / tr>
System.Net.Sockets详细:0:[2568] 00000070:3C 2F 74 61 62 6C 65
3E -3C 2F 62 6F 64 79 3E 3C:< / table>< / body><
System.Net.Sockets详细:0:[2568] 00000080:2F 68 74 6D 6C 3E:
/ html>
System.Net.Sockets详细:0:[2568]退出套接字#43667493 ::发送() - >
134#134
System.Net.Sockets详细:0:[2568]套接字#43667493 ::发送()<系统.Net.Sockets详细:0:[2568]来自Socket的数据#43667493 ::发送
System.Net.Sockets详细:0:[2568] 00000000:0D 0A:..
System.Net.Sockets详细:0:[2568]退出套接字#43667493 :: Send() - >
2#2
System.Net.Sockets详细:0:[2568]套接字#43667493 :: Send()
System.Net.Sockets详细:0:[2568]来自Socket的数据#43667493 ::发送
System.Net.Sockets详细:0:[2568] 00000000:0D 0A 2E 0D 0A:.....
System.Net.Sockets详细:0:[2568]退出套接字#43667493 ::发送() - >
5#5
System.Net .Sockets详细:0:[2568]套接字#43667493 :: Receive()
System.Net.Sockets详细:0:[2568]数据来自套接字#43667493 ::接收
System.Net.Sockets详细:0:[2568] 00000000:32 35 30 20 4D 61 69
6C-20 71 75 65 75 65 64 20:250邮件排队
System.Net.So ckets详细:0:[2568] 00000010:66 6F 72 20 64 65 6C
69-76 65 72 79 2E 0D 0A:用于交付...
System.Net.Sockets详细:0:[ 2568]退出
插座#43667493 ::接收() - > 31#31
System.Net详细:0:[2568]退出SmtpClient#25675301 ::发送()
System.Net.Sockets详细:0:[5560]套接字#57792633 :: Dispose()
System.Net.Sockets详细:0:[5560]套接字#57792633 ::关闭(两者都#2)
System.Transactions严重:0:< TraceRecord
xmlns =" http ://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity =" Critical">< TraceIdentifier> http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004 / 07 /可靠性/例外/未处理< / TraceIdentifier><描述>未处理
例外< /描述>< AppDomain> LeadProcessingServiceConsol e.vshost.exe< / AppDomain>< Exception>< ExceptionType>系统。 ObjectD isposedException,
mscorlib,Version = 2.0.0.0,Culture = neutral,
PublicKeyToken = b77a5c561934e089< / ExceptionType>< Message>安全句柄已关闭< / Message>< StackTrace> ;在
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket
socketHandle,Int32如何)
在System.Net.Sockets.Socket.Shutdown(SocketShutdown how)

?.Finalize()< / StackTrace>< ExceptionString> System.ObjectDisposedE xception:
安全句柄已关闭
在System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket
socketHandle,Int32如何)
在System.Net.Sockets.Socket.Shutdown(SocketShutdown如何)
在?.Finalize()< / ExceptionString>< / Exception>< / TraceRecord>
System.Net错误:0:[5560]例外#62476613 :: UnhandledExceptionHandler - 安全句柄已关闭
System.Net错误:0:[5560]在
系统.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket
socketHandle,Int32如何)
在System.Net.Sockets.Socket.Shutdown(SocketShutdown如何)
at?.Finalize()



哦,sorrry Paul。并且很抱歉这是vb.net。我正在做C#和

vb.net项目。希望smtpClient代码逻辑流程足以支持
帮助。


函数Send1(ByVal strFrom As String,ByVal strTo As String,ByVal

strSubject As String,ByVal strBody As String,可选的ByVal格式为

String ="")As Boolean

试试

使用消息As New MailMessage(strFrom,strTo,strSubject,strBody)

Dim smtpClientAs SmtpClient = New SmtpClient()

Dim fromAddress As MailAddress = New MailAddress(fromAddress1 ,

发件人名称)

smtpClient.Host =

System.Configuration.ConfigurationManager.AppSetti ngs(" MxServer")

smtpClient.Port = 25

smtpClient.Send(消息)

结束使用

结束尝试

" Paul Henderson" < PA *********** @ pittville.demon.co.uk>在消息中写道

news:11 ********************* @ e56g2000cwe.googlegro ups.com ...

smtpClient.Send(message)


我收到一般错误消息;
疑难解答异常:System.ObjectDisposedException ''安全
句柄已关闭''
必须这是异步完成吗?谢谢。 -Greg



显然,SmtpClient正在最终确定底层套接字两次;它可能意味着当你没有处于合适的状态时使用SmtpClient,虽然很难在不知道你的代码是什么的情况下看到原因。应该没有必要异步进行,
虽然它更整洁;在这种情况下,人们会期望同步发送更可靠,因为您可以确定
SmtpClient已完成发送上一条消息;如果你因为它是异步的而加倍发送,那会导致异常。
如果你能发布一些代码,那将会有所帮助。


smtpClient.Send(message)

is causing me problems as per specifics in the trace below. Email is sent
but not without this error typically upon sending the second email, but
sometimes when running the app, even the first time. The application will
be required to be sending out repeated emails, about one every second or
two.
Must this be done asynchronously? Thank you. -Greg

I get the generic error messages;
Troubleshooting Exceptions: System.ObjectDisposedException ''Safe handle
has been closed''

An ObjectDisposedException exception is thrown when an operation is
attempted on a disposed object, such as a closed stream or registry key.

Make sure you have not released a resource before attempting to use it.
For example, if attempting to manipulate a stream, make sure it has not
been previously closed.


System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
1024#1024
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Send()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Send
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 52 65 63 4E 61 6D 65
7D-3C 42 52 3E 3D 30 44 3D : RecName}<BR>=0D=
System.Net.Sockets Verbose: 0 : [2568] 00000010 : 30 41 54 6F 74 61 6C
4D-6F 76 65 2E 63 6F 6D 3C : 0Axxxx.com<
System.Net.Sockets Verbose: 0 : [2568] 00000020 : 42 52 3E 3D 30 44 3D
30-41 28 38 37 37 29 20 39 : BR>=0D=0A(877) 9
System.Net.Sockets Verbose: 0 : [2568] 00000030 : 36 38 2D 4D 4F 56 45
20-28 36 36 38 33 29 3C 42 : 68-MOVE (6683)<B
System.Net.Sockets Verbose: 0 : [2568] 00000040 : 52 3E 3D 0D 0A 3D 30
44-3D 30 41 7B 52 65 63 45 : R>=..=0D=0A{RecE
System.Net.Sockets Verbose: 0 : [2568] 00000050 : 6D 61 69 6C 7D 3C 42
52-3E 3D 30 44 3D 30 41 3C : mail}<BR>=0D=0A<
System.Net.Sockets Verbose: 0 : [2568] 00000060 : 2F 66 6F 6E 74 3E 3C
2F-74 64 3E 3C 2F 74 72 3E : /font></td></tr>
System.Net.Sockets Verbose: 0 : [2568] 00000070 : 3C 2F 74 61 62 6C 65
3E-3C 2F 62 6F 64 79 3E 3C : </table></body><
System.Net.Sockets Verbose: 0 : [2568] 00000080 : 2F 68 74 6D 6C 3E :
/html>
System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
134#134
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Send()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Send
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 0D 0A : ..
System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
2#2
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Send()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Send
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 0D 0A 2E 0D 0A : .....
System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
5#5
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Receive()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Receive
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 32 35 30 20 4D 61 69
6C-20 71 75 65 75 65 64 20 : 250 Mail queued
System.Net.Sockets Verbose: 0 : [2568] 00000010 : 66 6F 72 20 64 65 6C
69-76 65 72 79 2E 0D 0A : for delivery...
System.Net.Sockets Verbose: 0 : [2568] Exiting
Socket#43667493::Receive() -> 31#31
System.Net Verbose: 0 : [2568] Exiting SmtpClient#25675301::Send()
System.Net.Sockets Verbose: 0 : [5560] Socket#57792633::Dispose()
System.Net.Sockets Verbose: 0 : [5560] Socket#57792633::Shutdown(Both#2)
System.Transactions Critical: 0 : <TraceRecord
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled
exception</Description><AppDomain>LeadProcessingServiceConsol e.vshost.exe</AppDomain><Exception><ExceptionType>System.ObjectD isposedException,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Safe handle has been
closed</Message><StackTrace> at
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at
?.Finalize()</StackTrace><ExceptionString>System.ObjectDisposedE xception:
Safe handle has been closed
at System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at ?.Finalize()</ExceptionString></Exception></TraceRecord>
System.Net Error: 0 : [5560] Exception in the
#62476613::UnhandledExceptionHandler - Safe handle has been closed
System.Net Error: 0 : [5560] at
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at ?.Finalize()

解决方案

> smtpClient.Send(message)

I get the generic error messages;
Troubleshooting Exceptions: System.ObjectDisposedException ''Safe handle
has been closed''
Must this be done asynchronously? Thank you. -Greg



Apparently the SmtpClient is finalizing the underlying socket twice; it
might mean that you are using the SmtpClient when it is not in a
suitable state, though it''s difficult to see why without knowing what
your code looks like. There should be no need to do it asynchronously,
though it is neater; in this context, one would expect sending
synchronously to be more reliable as you can be sure that the
SmtpClient has finished sending the previous message; if you ''doubled
up'' sending because it was asynchronous, that would cause an exception.
It''d be helpful if you could post some code, though.


No, it''s not necessary to use threading, but without knowing how you *are*
doing this, I can''t tell you more than that.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"hazz" <ha**@sonic.net> wrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...

smtpClient.Send(message)

is causing me problems as per specifics in the trace below. Email is sent
but not without this error typically upon sending the second email, but
sometimes when running the app, even the first time. The application
will be required to be sending out repeated emails, about one every second
or two.
Must this be done asynchronously? Thank you. -Greg

I get the generic error messages;
Troubleshooting Exceptions: System.ObjectDisposedException ''Safe
handle has been closed''

An ObjectDisposedException exception is thrown when an operation is
attempted on a disposed object, such as a closed stream or registry key.

Make sure you have not released a resource before attempting to use it.
For example, if attempting to manipulate a stream, make sure it has not
been previously closed.


System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
1024#1024
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Send()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Send
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 52 65 63 4E 61 6D 65
7D-3C 42 52 3E 3D 30 44 3D : RecName}<BR>=0D=
System.Net.Sockets Verbose: 0 : [2568] 00000010 : 30 41 54 6F 74 61 6C
4D-6F 76 65 2E 63 6F 6D 3C : 0Axxxx.com<
System.Net.Sockets Verbose: 0 : [2568] 00000020 : 42 52 3E 3D 30 44 3D
30-41 28 38 37 37 29 20 39 : BR>=0D=0A(877) 9
System.Net.Sockets Verbose: 0 : [2568] 00000030 : 36 38 2D 4D 4F 56 45
20-28 36 36 38 33 29 3C 42 : 68-MOVE (6683)<B
System.Net.Sockets Verbose: 0 : [2568] 00000040 : 52 3E 3D 0D 0A 3D 30
44-3D 30 41 7B 52 65 63 45 : R>=..=0D=0A{RecE
System.Net.Sockets Verbose: 0 : [2568] 00000050 : 6D 61 69 6C 7D 3C 42
52-3E 3D 30 44 3D 30 41 3C : mail}<BR>=0D=0A<
System.Net.Sockets Verbose: 0 : [2568] 00000060 : 2F 66 6F 6E 74 3E 3C
2F-74 64 3E 3C 2F 74 72 3E : /font></td></tr>
System.Net.Sockets Verbose: 0 : [2568] 00000070 : 3C 2F 74 61 62 6C 65
3E-3C 2F 62 6F 64 79 3E 3C : </table></body><
System.Net.Sockets Verbose: 0 : [2568] 00000080 : 2F 68 74 6D 6C 3E :
/html>
System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
134#134
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Send()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Send
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 0D 0A : ..
System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
2#2
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Send()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Send
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 0D 0A 2E 0D 0A : .....
System.Net.Sockets Verbose: 0 : [2568] Exiting Socket#43667493::Send() ->
5#5
System.Net.Sockets Verbose: 0 : [2568] Socket#43667493::Receive()
System.Net.Sockets Verbose: 0 : [2568] Data from Socket#43667493::Receive
System.Net.Sockets Verbose: 0 : [2568] 00000000 : 32 35 30 20 4D 61 69
6C-20 71 75 65 75 65 64 20 : 250 Mail queued
System.Net.Sockets Verbose: 0 : [2568] 00000010 : 66 6F 72 20 64 65 6C
69-76 65 72 79 2E 0D 0A : for delivery...
System.Net.Sockets Verbose: 0 : [2568] Exiting
Socket#43667493::Receive() -> 31#31
System.Net Verbose: 0 : [2568] Exiting SmtpClient#25675301::Send()
System.Net.Sockets Verbose: 0 : [5560] Socket#57792633::Dispose()
System.Net.Sockets Verbose: 0 : [5560] Socket#57792633::Shutdown(Both#2)
System.Transactions Critical: 0 : <TraceRecord
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled
exception</Description><AppDomain>LeadProcessingServiceConsol e.vshost.exe</AppDomain><Exception><ExceptionType>System.ObjectD isposedException,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Safe handle has
been closed</Message><StackTrace> at
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at
?.Finalize()</StackTrace><ExceptionString>System.ObjectDisposedE xception:
Safe handle has been closed
at System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at ?.Finalize()</ExceptionString></Exception></TraceRecord>
System.Net Error: 0 : [5560] Exception in the
#62476613::UnhandledExceptionHandler - Safe handle has been closed
System.Net Error: 0 : [5560] at
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at ?.Finalize()



Oh, sorrry Paul. And doubly sorry this is vb.net. I am doing both C# and
vb.net projects. Hopefully the smtpClient code logic flow will be enough to
help out here.

Function Send1(ByVal strFrom As String, ByVal strTo As String, ByVal
strSubject As String, ByVal strBody As String, Optional ByVal Format As
String = "") As Boolean
Try
Using message As New MailMessage(strFrom , strTo , strSubject , strBody)
Dim smtpClientAs SmtpClient = New SmtpClient()
Dim fromAddress As MailAddress = New MailAddress(fromAddress1,
"Sender Name")
smtpClient.Host =
System.Configuration.ConfigurationManager.AppSetti ngs("MxServer")
smtpClient.Port = 25
smtpClient.Send(message)
End Using
End Try
"Paul Henderson" <pa***********@pittville.demon.co.uk> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com...

smtpClient.Send(message)


I get the generic error messages;
Troubleshooting Exceptions: System.ObjectDisposedException ''Safe
handle
has been closed''
Must this be done asynchronously? Thank you. -Greg



Apparently the SmtpClient is finalizing the underlying socket twice; it
might mean that you are using the SmtpClient when it is not in a
suitable state, though it''s difficult to see why without knowing what
your code looks like. There should be no need to do it asynchronously,
though it is neater; in this context, one would expect sending
synchronously to be more reliable as you can be sure that the
SmtpClient has finished sending the previous message; if you ''doubled
up'' sending because it was asynchronous, that would cause an exception.
It''d be helpful if you could post some code, though.



这篇关于smtpClient.Send套接字错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆