473,769 Members | 6,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SmtpSe rver = mailservername
SmtpMail.Send(m sg)

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
19 3370
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.SmtpSe rver = 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******** *************@z 14g2000cwz.goog legroups.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.SmtpSe rver = ""

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.SmtpSe rver = 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(fileNa me)) > 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.SmtpSe rver = serverName
SmtpMail.Send(m sg)
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.SmtpSe rver = Nothing
End Sub
End Class

When my application executes the SendMessage method above, and ONLY
when it also sets the name of the SmtpMail.SmtpSe rver 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.SmtpSe rver 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\mail root\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.goo glegroups.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(fileNa me)) > 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.SmtpSe rver = serverName
SmtpMail.Send(m sg)
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.SmtpSe rver = Nothing
End Sub
End Class

When my application executes the SendMessage method above, and ONLY
when it also sets the name of the SmtpMail.SmtpSe rver 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.SmtpSe rver 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
379
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 integrated window authentication. it does work, and works fine on my dev machine. it also works fine on the test server, but with some considerations. on the test server, i can send emails IF they do not include any attachments. as soon as i send an email...
1
2699
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 e-mail addresses out side my company walls. When the e-mail is send on some one in my company it works perfect. I think it is a relay issue. Our system administrator will not allow relaying. In the ASP.Net web.config file I let the web application...
3
9256
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 e-mail addresses out side my company walls. When the e-mail is send on some one in my company it works perfect. I think it is a relay issue. Our system administrator will not allow relaying. In the ASP.Net web.config file I let the web application...
4
7552
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 SP2, and IIS's SMTP and WWW servers are installed. Here is the error trace: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an...
0
1830
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: ------------------------------------------- //try { // security assertion
1
1128
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 the user can not browse anymore. I thought that a possible solution is to send the Email in new thread so the application will continue to work also when the mail server is down. What's the easiest way to accomplish this ? Anyone has an example...
2
1700
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 textbox contained in a user control that's put on a MDI Child form causes the application to hang as soon as you hit the Delete key while editing. Everything freezes and only Ctrl + Esc or Ctrl + Alt + Delete will bring things back to life.
0
995
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 Email, FirstName, MiddleName, LastName. I also have a form that will load users into this listview from a number of different places defined by ODBC. The population of this listview works perfectly, however with a small number of users, the...
17
6432
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. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.