473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 3344
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jason | last post by:
Hi not sure if this is the write place, but i really need some help with this...! I have a piece of code that sends email using the SmtpMail class, in an ASP.NET web application, with...
1
by: Jens Øster | last post by:
Hi I am writing a ASP.NET web application that must sent some e-mails. I get the exception “Could not access 'CDO.Message' object†when I call SmtpMail.Send. This only happens when I send...
3
by: Jens | last post by:
Hi I am writing a ASP.NET web application that must sent some e-mails. I get the exception “Could not access 'CDO.Message' object†when I call SmtpMail.Send. This only happens when I send...
4
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP...
0
by: Eric van Wijk | last post by:
Hi All, After installing SP1 for Windows 2003, I'm running into the 'Error loading type library/DLL' exception when using CDO through System.Web.Mail: ...
1
by: ra294 | last post by:
Hi, I have a web application that sends Email on certain events. The problem is that sometimes the local mail server does not response to SmtpMail.Send and all the web application in stucked so...
2
by: H. Blijlevens | last post by:
Hi y'all! I'm trying to adapt a VB.Net application that a former employee built to keep track of product issues that our customers report. While doing so, I bump into the following problem: a...
0
by: Nathan Truhan | last post by:
Hello, I have a WinForms application to send out emails to a large group of students. This is not spam, but mail from our university to the students. Currentl I have a ListView with 4 columns...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.