473,287 Members | 1,447 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,287 software developers and data experts.

Duplicate Emails with System.Web.Mail.SmtpMail.Send

When using this bit of code, it sends two emails most of the time.
Sometimes it doesn't send two, but most of the time it does. I put the
system time (Now) in the Subject and each email has a different time by a
minute or so. I also tried to count the number of emails it is sending by
using the intEmail = intEmail + 1, but the number is always 1.Could anyone
tell me why this is happening or give me advice on how to change it. Thanks
in advance. Help is always greatly appreciated.

If Session("email") <> "" Then
intEmail = intEmail + 1
Dim strBody, strSubject as String
Dim email as New System.Web.Mail.MailMessage
strSubject = "Class Registration Confirmation" & " - " & Now & " - Email
#" & intEmail
strBody = Session("fname") & " " & Session("lname") & ", " & vbcrlf & _
"You registered for the following class." & vbcrlf & _
"Class Name: " & strClass & vbcrlf _
"Class Date: " & dtClass.DayOfWeek.ToString & ", " &
dtClass.ToShortDateString & vbcrlf & _
"Class Length: " & strLength
email.To = Session("email")
email.From = ConfigurationSettings.AppSettings("AdminEmail")
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer =
ConfigurationSettings.AppSettings("MailServer")
System.Web.Mail.SmtpMail.Send(email)

End If

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System
Nov 19 '05 #1
3 3478
I think we have to look deeper, like to where this method is being called
from. If this is called from something fired through the Page_load event, and
you have to click a button to leave the page, then the Page_Load will acually
be 'hit' twice, since the button click will fire Page_Load before the click
event. In the above scenario, the intEmail variable will be reinitialized
unless persisted somehow (like in session) Try looking along those lines.

Hope this helps.

"chuckdfoster" wrote:
When using this bit of code, it sends two emails most of the time.
Sometimes it doesn't send two, but most of the time it does. I put the
system time (Now) in the Subject and each email has a different time by a
minute or so. I also tried to count the number of emails it is sending by
using the intEmail = intEmail + 1, but the number is always 1.Could anyone
tell me why this is happening or give me advice on how to change it. Thanks
in advance. Help is always greatly appreciated.

If Session("email") <> "" Then
intEmail = intEmail + 1
Dim strBody, strSubject as String
Dim email as New System.Web.Mail.MailMessage
strSubject = "Class Registration Confirmation" & " - " & Now & " - Email
#" & intEmail
strBody = Session("fname") & " " & Session("lname") & ", " & vbcrlf & _
"You registered for the following class." & vbcrlf & _
"Class Name: " & strClass & vbcrlf _
"Class Date: " & dtClass.DayOfWeek.ToString & ", " &
dtClass.ToShortDateString & vbcrlf & _
"Class Length: " & strLength
email.To = Session("email")
email.From = ConfigurationSettings.AppSettings("AdminEmail")
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer =
ConfigurationSettings.AppSettings("MailServer")
System.Web.Mail.SmtpMail.Send(email)

End If

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System

Nov 19 '05 #2
I think we've found the problem. I am calling it in the page_load. I'll
move it to the previous page when they click the submit button. Thank you
so much. If you don't mind another question, can you explain how it is done
twice?

Chuck Foster

"Chip Pettit" <Ch********@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
I think we have to look deeper, like to where this method is being called
from. If this is called from something fired through the Page_load event, and you have to click a button to leave the page, then the Page_Load will acually be 'hit' twice, since the button click will fire Page_Load before the click event. In the above scenario, the intEmail variable will be reinitialized
unless persisted somehow (like in session) Try looking along those lines.

Hope this helps.

"chuckdfoster" wrote:
When using this bit of code, it sends two emails most of the time.
Sometimes it doesn't send two, but most of the time it does. I put the system time (Now) in the Subject and each email has a different time by a minute or so. I also tried to count the number of emails it is sending by using the intEmail = intEmail + 1, but the number is always 1.Could anyone tell me why this is happening or give me advice on how to change it. Thanks in advance. Help is always greatly appreciated.

If Session("email") <> "" Then
intEmail = intEmail + 1
Dim strBody, strSubject as String
Dim email as New System.Web.Mail.MailMessage
strSubject = "Class Registration Confirmation" & " - " & Now & " - Email #" & intEmail
strBody = Session("fname") & " " & Session("lname") & ", " & vbcrlf & _ "You registered for the following class." & vbcrlf & _ "Class Name: " & strClass & vbcrlf _
"Class Date: " & dtClass.DayOfWeek.ToString & ", " & dtClass.ToShortDateString & vbcrlf & _
"Class Length: " & strLength
email.To = Session("email")
email.From = ConfigurationSettings.AppSettings("AdminEmail")
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer =
ConfigurationSettings.AppSettings("MailServer")
System.Web.Mail.SmtpMail.Send(email)

End If

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System

Nov 19 '05 #3
This explanation is valid only if there is a button, or some other postback
event fired to leave the page... The page will always do the page_load, even
when the post is a postback. Other events are handled after the page_load
event. So, say you click to leave the page... page_load does it's thing, then
the click event handler does it's thing. Any thing in page_load gets done
again on postback.

Some things you could do to work with this behavior are:

1. Wrap the things you want to happen only once when the page loads for the
first time in an if (!IsPostBack) statement.
2. Save a counter to Session on the last load event (I use Page_PreRender)
and then load that varialble first thing in Page_Load on postback

And I'm sure there are more... Hope this helps.

Chip Pettit

"chuckdfoster" wrote:
I think we've found the problem. I am calling it in the page_load. I'll
move it to the previous page when they click the submit button. Thank you
so much. If you don't mind another question, can you explain how it is done
twice?

Chuck Foster

"Chip Pettit" <Ch********@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
I think we have to look deeper, like to where this method is being called
from. If this is called from something fired through the Page_load event,

and
you have to click a button to leave the page, then the Page_Load will

acually
be 'hit' twice, since the button click will fire Page_Load before the

click
event. In the above scenario, the intEmail variable will be reinitialized
unless persisted somehow (like in session) Try looking along those lines.

Hope this helps.

"chuckdfoster" wrote:
When using this bit of code, it sends two emails most of the time.
Sometimes it doesn't send two, but most of the time it does. I put the system time (Now) in the Subject and each email has a different time by a minute or so. I also tried to count the number of emails it is sending by using the intEmail = intEmail + 1, but the number is always 1.Could anyone tell me why this is happening or give me advice on how to change it. Thanks in advance. Help is always greatly appreciated.

If Session("email") <> "" Then
intEmail = intEmail + 1
Dim strBody, strSubject as String
Dim email as New System.Web.Mail.MailMessage
strSubject = "Class Registration Confirmation" & " - " & Now & " - Email #" & intEmail
strBody = Session("fname") & " " & Session("lname") & ", " & vbcrlf & _ "You registered for the following class." & vbcrlf & _ "Class Name: " & strClass & vbcrlf _
"Class Date: " & dtClass.DayOfWeek.ToString & ", " & dtClass.ToShortDateString & vbcrlf & _
"Class Length: " & strLength
email.To = Session("email")
email.From = ConfigurationSettings.AppSettings("AdminEmail")
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer =
ConfigurationSettings.AppSettings("MailServer")
System.Web.Mail.SmtpMail.Send(email)

End If

--
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: VB Programmer | last post by:
My company has it's own webserver, which is going to host our ASP.NET web application. We want the website to be able to send out emails. 1. What do I need on the server so that it has the...
1
by: mark | last post by:
I need to send order confirmation emails through my asp.net storefront. With my Asp 3.0 sites I use cdonts with no issues. I've researched the system.web.mail asp.net way and haven't got it to...
2
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
3
by: Steve Thurston | last post by:
Hi, I'm attempting to send emails for the first time using ASP.NET, so I'm hoping there's just a beginner's error going on here for me. But my emails aren't reaching their destination, and I...
3
by: Nick Brown | last post by:
Has any1 else had this error message. If so how do u solve it? The specified module could not be found. Description: An unhandled exception occurred during the execution of the current web...
6
by: Brian M | last post by:
I have an ASP.NET application using .NET Framework 1.1 running on a Windows 2003 server. The application uses SMTP to send emails. This application was moved from an IIS 5 machine where it worked...
7
by: farhan wajahat | last post by:
i have made a command button and on the click event of the button following code is mentioned: im mailnew As New MailMessage() mailnew.From = "financialadjustment@mobilink.net" mailnew.To =...
7
by: tshad | last post by:
I am trying to figure out the best way to send automated emails? I have emails that I want to send out to certain clients that need them either daily or weekly. How would I do in asp.net? ...
2
by: Joey | last post by:
I am currently developing a C# asp.net application where users are required to register. The application then generates a simple, plain text email and sends it to the new user. I have been...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...

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.