Last post Mar 23, 2017 06:35 AM by Bluenose
Mar 07, 2017 02:01 AM|Bluenose|LINK
My SMTP code sents an email and a duplicate to the user at exactly the same time (so he receives two emails). To try to eliminate this duplicity, I have placed a breakpoint here in my vb.net SMTP code:
and then pressed F5. That loaded up my Web page (www.dimadayoub.net/forgot.aspx) which I then closed and then, from the menubar, selected 'Step into'.
I am not quite sure what I am looking for (or where to look for it), but there is a list in the Locals pane, nothing in the Watch pane and, in Call stack, I see Global code [forgot.aspx] Line 104 and Language: Script. In the Command pane, I see an inexplicable
12:07:42.5488: Referenced file '~/Scripts/_references.js' not found.
And yet, in the Scripts folder in Solution Explorer (VS 2013 Express), I can see the _references.js.
(I can't see that being the reason for a duplicate email even if the JS file were missing).
Any advice would be welcome.
Mar 07, 2017 08:45 AM|kaushalparik27|LINK
Place a breakpoint in above line and make sure if that is being hit twice when you perform an event/action? If so, (which is likely to be in your case) then every time when it is being hit, check the call stack.
Mar 07, 2017 12:43 PM|Bluenose|LINK
Thank you for your message.
I am not too sure what you mean by 'make sure if that is being hit twice when you perform an event/action?'
When I put a breakpoint here:
and then press F5 and then 'Step into', it shows me this:
That piece of code (an invisible counter) is not in my forget.aspx file - only in the index.aspx file, and I am quite happy to remove it.
In the Call Stack pane, I see Global code [localhost:49835] Line 78
Then I go to Debug | Continue. It is still on that invisible counter and the Call Stack pane is empty. Then Debug | Stop debugging.
Mar 07, 2017 12:56 PM|kaushalparik27|LINK
Actually, what I meant is to put a breakpoint at Smtpserver.Send(myMessage) and see if breakpoint hit two times. If so, then you may check call stack to see from where the action is triggering.
Mar 07, 2017 11:07 PM|Bluenose|LINK
All that happens is that when I put a breakpoint at Smtpserver.Send(myMessage), and click Start debugging is that it loads the Web page which I then close. I click on Start debugging again
and, again, it loads the page. The breakpoint remains on that line: Smtpserver.Send(myMessage).
I can't see any window pane that shows Stack trace.
Mar 08, 2017 02:53 AM|Cathy Zou|LINK
I use the following code to send email. It work well without any problem, I suggest you could change your code based on the code in the following :
Using mailMessage As New MailMessage()
mailMessage.From = New MailAddress("email@example.com")
mailMessage.Subject = "subject"
mailMessage.Body = "body"
mailMessage.IsBodyHtml = True
Dim smtp As New SmtpClient("smtp.live.com", 587)
smtp.UseDefaultCredentials = False
smtp.EnableSsl = True
smtp.Credentials = New NetworkCredential("firstname.lastname@example.org", "sender's password here!")
Mar 08, 2017 03:39 AM|Bluenose|LINK
Thank you for your reply.
My code is, essentially, the same as yours:
Dim myMessage As New MailMessage
Dim Smtpserver As New SmtpClient
Dim strEmailValue As String = Request.Form("strEmailTextBox") 'strEmailValue = user email; strEmailTextBox = ID of email field
'Create the mail message
myMessage.From = New MailAddress("email@example.com") 'Webmaster's email
myMessage.To.Add(New MailAddress(strEmailValue)) 'user's email
myMessage.Subject = ("Password Reset Request")
myMessage.Body = ""
myMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
myMessage.IsBodyHtml = True
myMessage.Priority = MailPriority.Normal
Dim PlainMessage As AlternateView = AlternateView.CreateAlternateViewFromString("Hello. To reset your password, please click on this link", Nothing, "text/plain")
Dim mimeType As ContentType = New ContentType("text/html")
Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("<img src=cid:dimaHeader><br /><br /><br /><body style='font-family:candara; color:#000000; background-color:#ffffff; margin-left:2em;'>Hello " & strEmailValue & "<br /><br /> To reset your password, please click on this <a href=''>link</a><br /><br />Thank you<br /><br />Regards<br /></br />Dima<br /><br ><a href='http://www.mysite.net'>http://www.mysite.net</a></body>", Nothing, "text/html")
Dim Logo As New LinkedResource(Server.MapPath("~/Images/dimaHeader.jpg"), "image/jpeg") 'embedded image
Logo.ContentId = "dimaHeader"
Smtpserver.DeliveryMethod = SmtpDeliveryMethod.Network
Smtpserver.Host = ("126.96.36.199")
Smtpserver.Port = 25
Smtpserver.EnableSsl = False
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("firstname.lastname@example.org", "SMTP_password")
Smtpserver.Credentials = basicAuthenticationInfo
myMessage = Nothing
Smtpserver = Nothing
One difference is that I have nothing in myMessage.Body. Instead, I have declared
I am not sure if having nothing in myMessage.Body is permitted or responsible for sending duplicate emails? (In Windows PowerShell only three fields are required in an email: To, From, and Subject). The other difference is that you have:
smtp.EnableSsl = True
My hosting service would not allow that, so I have it set to 'False'.
My SMTP code works fine in that the user receives a personalised HTML email (or plain text); it is just this duplicate that is the problem.
Can you see anything in the code I have posted that accounts for this duplicate email problem?
Mar 16, 2017 09:39 AM|Cathy Zou|LINK
I think the answers of kaushalparik27 is a right way, but I confuse on that why you cannot debug the code.
The code of sending email looks all well (it’s not the reason of this issue).
how the code call SMTP send function?
Mar 23, 2017 06:35 AM|Bluenose|LINK
In VS, I select this line of code,
Then I press F9 and then F5 and get a 'Validation Complete' message at the bottom of my page of code and the Web page launches in my browser. I close the browser and select the 'Immediate Window' at the bottom of my page of code and that window is empty. 'Locals'
and 'Watch' tabs are also empty. VS is still debugging at this point and I can see 'Call Stack' which is also empty. 'Command Window' is also empty apart from this arrow:
> in the top left-hand corner. I don't know what that arrow is doing.
Several tutorials suggest using 'Use HitCount' to display the number of times the breakpoint has been hit during execution. On the menubar under 'Debug', there is no 'Use HitCount' item.
When I hover my mouse over
I can see
Dim myMessage as System.Net.Mail.SmtpCilent
I am using the following relevant namespaces: