469,304 Members | 2,018 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

SmtpMail causes application to hang...

Hello all:

Using an "Imports System.Web.Mail" clause at the head of my module, and
after executing the following code:

Dim msg As New MailMessage
msg.From = sender
msg.To = recipient
msg.Attachments.Add(New MailAttachment(attachFile))
msg.Subject = subjectString
SmtpMail.SmtpServer = mailservername
SmtpMail.Send(msg)

The message is sent just fine, but then my application refuses to
terminate... when sub Main ends, it just hangs, and a glance at my task
manager shows it to be using ever-increasing amounts of memory, and my
CPU usage shoots up to 100%, and I actually have to kill the
application for it to terminate. This did not start happening until
AFTER I installed the code above...

I see the same behavior whether I explicitly destroy the MailMessage
object or not, whether I reset the mail server name or not...
Any help will be greatly appreciated!

Cheers,
zdrakec

Nov 21 '05 #1
19 3127
I don´t know the asnwer, but most of them related to System.Web.Mail are at:

http://systemwebmail.com/

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
<zd*****@yahoo.com> escribió en el mensaje
news:11**********************@c13g2000cwb.googlegr oups.com...
Hello all:

Using an "Imports System.Web.Mail" clause at the head of my module, and
after executing the following code:

Dim msg As New MailMessage
msg.From = sender
msg.To = recipient
msg.Attachments.Add(New MailAttachment(attachFile))
msg.Subject = subjectString
SmtpMail.SmtpServer = mailservername
SmtpMail.Send(msg)

The message is sent just fine, but then my application refuses to
terminate... when sub Main ends, it just hangs, and a glance at my task
manager shows it to be using ever-increasing amounts of memory, and my
CPU usage shoots up to 100%, and I actually have to kill the
application for it to terminate. This did not start happening until
AFTER I installed the code above...

I see the same behavior whether I explicitly destroy the MailMessage
object or not, whether I reset the mail server name or not...
Any help will be greatly appreciated!

Cheers,
zdrakec

Nov 21 '05 #2
Thanks for the link, but unfortunately, I did not see anything that
addresses this issue there...

zdrakec

Carlos J. Quintero [.NET MVP] wrote:
I don´t know the asnwer, but most of them related to System.Web.Mail are at:
http://systemwebmail.com/


Nov 21 '05 #3
Zdrakec,

This snippet you show now in this newsgroup has been here often.

Mostly is the error that the smtp mailserver is not correct. That is not in
your situation. Therefore in my opinion has it to do with an endless loop
somewhere however not in this snippet.

Just my thought,

Cor
Nov 21 '05 #4
Hello Cor:

Well, this was my first thought, but there IS no loop between the
execution of this code and the exit from Sub Main.In fact, if I step
through execution after the send method call, everything runs just
fine... but after exiting sub Main, the application doesn't terminate.
This ONLY happens if the SmptMail.Send(msg) is invoked, otherwise
not...

Still puzzled...

Thanks,
zdrakec

Nov 21 '05 #5
Zdrakec,

Have you to test it (not for original) tried a me.close direct after the
send?

Cor
Nov 21 '05 #6
<zd*****@yahoo.com> schrieb;
Using an "Imports System.Web.Mail" clause at the head of my module, and
after executing the following code:

Dim msg As New MailMessage
msg.From = sender
msg.To = recipient
msg.Attachments.Add(New MailAttachment(attachFile))
msg.Subject = subjectString
SmtpMail.SmtpServer = mailservername
SmtpMail.Send(msg)

The message is sent just fine, but then my application refuses to
terminate... when sub Main ends, it just hangs, and a glance at my task
manager shows it to be using ever-increasing amounts of memory, and my
CPU usage shoots up to 100%, and I actually have to kill the
application for it to terminate. This did not start happening until
AFTER I installed the code above...


If you are running virusscanners or firewalls, turn them off temporarily to
be sure that they don't cause the problem.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Hello Cor, Herfried:

There is no me.close to execute, this is being run from a module, not a
form class object. I turned off my virus scanner and firewall, but with
no change. I point out that the mail message is successfully being
sent!

I tried doing a "threading.thread.currentthread.abort" command, and
trapping the resulting ThreadAbortException; however, while this does
in fact kill the app, it also gives me that annoying message
"Application has caused a problem... do you want to create a dump file"
dialog. Since this will end up being an unattended server process, I
can't have a dialog box open! I get this error despite the fact that
the exception is being caught...

More suggestions?

Cheers,
zdrakec

Nov 21 '05 #8
A co-worker had a similar problem. He commented out the line
SmtpMail.SmtpServer = mailservername
and SmtpMail worked.

This assumes the PC can send SmtpMail.

He thinks there was some bug in his mailservername value.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uU**************@tk2msftngp13.phx.gbl...
<zd*****@yahoo.com> schrieb;
Using an "Imports System.Web.Mail" clause at the head of my module, and
after executing the following code:

Dim msg As New MailMessage
msg.From = sender
msg.To = recipient
msg.Attachments.Add(New MailAttachment(attachFile))
msg.Subject = subjectString
SmtpMail.SmtpServer = mailservername
SmtpMail.Send(msg)

The message is sent just fine, but then my application refuses to
terminate... when sub Main ends, it just hangs, and a glance at my task
manager shows it to be using ever-increasing amounts of memory, and my
CPU usage shoots up to 100%, and I actually have to kill the
application for it to terminate. This did not start happening until
AFTER I installed the code above...
If you are running virusscanners or firewalls, turn them off temporarily

to be sure that they don't cause the problem.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
Hello Bill:

Well, yes, when I comment that out, the problem goes away. However, the
message also does not get sent! This is why I tried resetting this to
an empty string after the send call, thus:

msg.Attachments.Clear()
msg = Nothing
SmtpMail.SmtpServer = ""

Thanks though!

More?

Cheers,
zdrakec

Nov 21 '05 #10
Zdrakec,

Why dont you than not make a nice class from it so that you can instance it
and with that let it go automaticly out of scope and be cleaned up?

Cor
Nov 21 '05 #11
Well, that's a good idea, I'll try that... but I certainly expected it
to drop out of scope once the function that invoked it returned!

Cheers,

zdrakec

Nov 21 '05 #12
Tried it. No change.

<<sigh>>

More ideas?

Cheers,
zdrakec

Nov 21 '05 #13
It looks like mailservername is an invalid SmtpServer name. You can look at
the value to check.

The code below is using "" as the SmtpServer name. I would not expect this
to work.

If you set
SmtpMail.SmtpServer = Nothing
I would expect the same results as just commenting out the line. In that
case it depends on whether your PC can send Smtp e-mail - sounds like it is
not enabled on you PC.

<zd*****@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hello Bill:

Well, yes, when I comment that out, the problem goes away. However, the
message also does not get sent! This is why I tried resetting this to
an empty string after the send call, thus:

msg.Attachments.Clear()
msg = Nothing
SmtpMail.SmtpServer = ""

Thanks though!

More?

Cheers,
zdrakec

Nov 21 '05 #14
Hi Bill:

I want to point out that when I set the server name, the message gets
sent... which implies that the server name is indeed valid. I happen to
know the server name is good, since is the one my regular account uses
:)

I have tried setting SmtpMail.SmtpServer = Nothing, with the same
results as before.

I agree that something about setting the name is causing the problem...
I'm just not sure what....

Thanks,
zdrakec

Nov 21 '05 #15
Zdrakec,

Not tonight anymore for me, however maybe when you sent some more code
tomorrow or will somebody else have a look to it.

Now it is in my opinion guessing in the dark,

Cor
Nov 21 '05 #16
The class code is quite simple:

Option Strict On
Option Explicit On

Imports System.Web.Mail

Friend Class SendMail
Private msg As MailMessage
Private attach As MailAttachment
Private serverName As String

Friend Sub New(ByVal recipient As String, ByVal sentby As String, _
ByVal server As String, ByVal subject As String, Optional ByVal
fileName As String = "")
msg = New MailMessage
msg.From = sentby
msg.To = recipient
msg.Subject = subject
If Len(Trim(fileName)) > 0 Then
attach = New MailAttachment(fileName)
msg.Attachments.Add(attach)
End If
serverName = server
End Sub

Friend Sub SendMessage()
If msg Is Nothing Then Exit Sub
SmtpMail.SmtpServer = serverName
SmtpMail.Send(msg)
End Sub

Friend Sub Destroy()
Me.Finalize()
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
attach = Nothing
If Not msg Is Nothing Then
msg.Attachments.Clear()
msg = Nothing
End If
SmtpMail.SmtpServer = Nothing
End Sub
End Class

When my application executes the SendMessage method above, and ONLY
when it also sets the name of the SmtpMail.SmtpServer property to the
correct exchange server, what happens is:
1. The message is sent.
2. The application continues to execute normally, including the
destruction of the class object.
3. When the application exits Main (which is the startup object),
instead of terminating (as it normally does), it hangs. If I examine
the app with Task Manager, I find that the CPU utilization associated
with this .exe has gone to 99 (!) and stays there, even though nothing
else gets locked up... just this app, which refuses to terminate. I end
up having to use Task Manager to kill it.

I have tried all sorts of things, but the bottom line is: I only get
this behavior if I set the SmtpMail.SmtpServer property to the name of
my exchange server.

More suggestions? I'm starting to run out of things to try!

Cheers,
zdrakec

Nov 21 '05 #17
Zdrakec,

This is in my opinion the first time you tell that it is the Exchange
server.

Here a message thread about that, maybe you find something because that is
something special, I saw it a very long while ago and I hope that it is in
this thread for you..

And delete all those crazy extra's you have done.
When they did not work, dont keep them than.
(I mean all that finalizing and setting to nothing, that should do the
framework)

http://groups-beta.google.com/group/...ee8dbd2030f4c3

When trying by the way you can in your code (withouth that finalizing) use
any SMtp.sever. That can as well be the one which is from your provider.
Don't use that for production because they are probably not happy with it.

I hope this helps?

Cor
Nov 21 '05 #18
I moved the code to a different machine, and the problem went away...
<<sigh>> thanks for the input, this one was frustrating..

Cheers,

zdrakec

Cor Ligthert wrote:
Zdrakec,

This is in my opinion the first time you tell that it is the Exchange server.

Here a message thread about that, maybe you find something because that is something special, I saw it a very long while ago and I hope that it is in this thread for you..

And delete all those crazy extra's you have done.
When they did not work, dont keep them than.
(I mean all that finalizing and setting to nothing, that should do the framework)

http://groups-beta.google.com/group/...ee8dbd2030f4c3
When trying by the way you can in your code (withouth that finalizing) use any SMtp.sever. That can as well be the one which is from your provider. Don't use that for production because they are probably not happy with it.
I hope this helps?

Cor


Nov 21 '05 #19
Before my co-worker had a similar problem, I was trying to use SmtpMail
also. I did not set the SmtpServer property.

There is a folder on my PC named
C:\Inetpub\mailroot\Badmail
and 2 or 3 files with different extensions were appearing there each tile I
tried to send mail. Used Notepad to look at the file contents. The file
with the .BAD extension looked like a fully formatted version of the mail I
was trying to send. One of the other files, had an error message explaining
in a very cryptic/useless manner what the problem was - but it also had an
error number which I was able to look up in the knowledgebase.

The knowledgebase article said, in my words, the message was improperly
formatted. The message had to have a From, a To, and either a Subject or a
Body - my message had all four.

My From value was "My Mailer". Since it did not work I was willing to try
anything - so I changed it to "My-Mailer" and it worked. From can't have
embedded spaces??

<zd*****@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
The class code is quite simple:

Option Strict On
Option Explicit On

Imports System.Web.Mail

Friend Class SendMail
Private msg As MailMessage
Private attach As MailAttachment
Private serverName As String

Friend Sub New(ByVal recipient As String, ByVal sentby As String, _
ByVal server As String, ByVal subject As String, Optional ByVal
fileName As String = "")
msg = New MailMessage
msg.From = sentby
msg.To = recipient
msg.Subject = subject
If Len(Trim(fileName)) > 0 Then
attach = New MailAttachment(fileName)
msg.Attachments.Add(attach)
End If
serverName = server
End Sub

Friend Sub SendMessage()
If msg Is Nothing Then Exit Sub
SmtpMail.SmtpServer = serverName
SmtpMail.Send(msg)
End Sub

Friend Sub Destroy()
Me.Finalize()
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
attach = Nothing
If Not msg Is Nothing Then
msg.Attachments.Clear()
msg = Nothing
End If
SmtpMail.SmtpServer = Nothing
End Sub
End Class

When my application executes the SendMessage method above, and ONLY
when it also sets the name of the SmtpMail.SmtpServer property to the
correct exchange server, what happens is:
1. The message is sent.
2. The application continues to execute normally, including the
destruction of the class object.
3. When the application exits Main (which is the startup object),
instead of terminating (as it normally does), it hangs. If I examine
the app with Task Manager, I find that the CPU utilization associated
with this .exe has gone to 99 (!) and stays there, even though nothing
else gets locked up... just this app, which refuses to terminate. I end
up having to use Task Manager to kill it.

I have tried all sorts of things, but the bottom line is: I only get
this behavior if I set the SmtpMail.SmtpServer property to the name of
my exchange server.

More suggestions? I'm starting to run out of things to try!

Cheers,
zdrakec

Nov 21 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jason | last post: by
1 post views Thread by ra294 | last post: by
2 posts views Thread by H. Blijlevens | last post: by
reply views Thread by Nathan Truhan | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.