Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

asp.net vb email

Posted on 2009-07-12
3
Medium Priority
?
569 Views
Last Modified: 2012-05-07
Hello,
I have email script, and it works fine in the sample page.
However, if I copy and paste the script in other page, it stop working.
It doesn't give me any error message, and I have no idea what's causing it.
IDs are the same in both pages.
May be it's conflicting with other script in code behind VB.

Any idea?

Thank you.
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
 
        Dim mailMessage As New System.Net.Mail.MailMessage
        mailMessage.From = New System.Net.Mail.MailAddress("test@test.com")
        mailMessage.To.Add(New MailAddress("test@test.com"))
 
        mailMessage.Subject = "I assigned you a job"
 
        Dim plainTextView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("text/plain", Nothing, "text/plain")
        Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("text/html", Nothing, "text/html")
        mailMessage.AlternateViews.Add(plainTextView)
        mailMessage.AlternateViews.Add(htmlView)
 
        Dim smtpClient As New SmtpClient()
        Dim userState As Object = mailMessage
 
        AddHandler smtpClient.SendCompleted, AddressOf SmtpClient_OnCompleted
 
        Try
            smtpClient.SendAsync(mailMessage, userState)
        Catch recExc As System.Net.Mail.SmtpFailedRecipientsException
            For receipient = 0 To recExc.InnerExceptions.Length
                Dim statusCode As System.Net.Mail.SmtpStatusCode
                statusCode = recExc.InnerExceptions(receipient).StatusCode
 
                If (statusCode = SmtpStatusCode.MailboxBusy) Or (statusCode = SmtpStatusCode.MailboxUnavailable) Then
                    System.Threading.Thread.Sleep(5000)
                    smtpClient.SendAsync(mailMessage, userState)
 
                Else
                End If
            Next
        Catch smtpExc As System.Net.Mail.SmtpException
        Catch ex As Exception
        End Try
    End Sub

Open in new window

0
Comment
Question by:jtuttle99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24836350
Did you try setting breakpoints and see if it is not hitting any Catch?
set breakpoints at
Try and all Catch and then debug ....Or add
Respose.Write(smtpExc.ToString) and
Respose.Write(ex.ToString) to your ending catch blocks..
0
 

Author Comment

by:jtuttle99
ID: 24836396
Hello, I did response.Write and got following message.

System.Net.Mail.SmtpException: Failure sending mail. ---> System.InvalidOperationException: Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event. at System.Web.AspNetSynchronizationContext.OperationStarted() at System.Net.Mail.SmtpClient.SendAsync(MailMessage message, Object userToken) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.SendAsync(MailMessage message, Object userToken) at maintain_employee_Default.SendMail() in C:\Documents and Settings\shinyat\My Documents\Visual Studio 2008\WebSites\greenlake\maintain\employee\blog_emp.aspx.vb:line 363
0
 

Author Closing Comment

by:jtuttle99
ID: 31602634
And I added Async="true" in the page, and it worked!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question