locked
Threading RRS feed

  • Question

  • User1823730432 posted

    I need to apply the smtpClient.Send(mailMessage) with threading can anyone help


    109 Try

      110 

      111             If IsBodyHtml AndAlso alternativeView Then

      112                 Dim template As New myAlternativeView

      113 

      114                 mailMessage.AlternateViews.Add(template.EmailTemplate(_displayName, _Path))

      115                 smtpClient.Send(mailMessage)

      116             ElseIf sendAsync Then

      117                 AddHandler smtpClient.SendCompleted, AddressOf smtpClient_OnCompleted

      118                 Dim userState As Object = mailMessage

      119                 smtpClient.SendAsync(mailMessage, userState)

      120             Else

      121                 smtpClient.Send(mailMessage)

      122             End If

      123 

      124         Catch SmtpSenderException As SmtpFailedRecipientsException

    Friday, November 6, 2009 8:22 PM

Answers

  • User1823730432 posted

    Hi I have the threading working with a delegate and it works as I would expected

    Any links to information on the error codes

    thanks

      

    159 Case SmtpStatusCode.MustIssueStartTlsFirst

      160                 Case SmtpStatusCode.Ok

      161                 Case SmtpStatusCode.ServiceClosingTransmissionChannel

      162                 Case SmtpStatusCode.ServiceNotAvailable

      163                 Case SmtpStatusCode.ServiceReady

      164                 Case SmtpStatusCode.StartMailInput

      165                 Case SmtpStatusCode.SyntaxError

      166                 Case SmtpStatusCode.SystemStatus

      167                 Case SmtpStatusCode.TransactionFailed

      168                 Case SmtpStatusCode.UserNotLocalTryAlternatePath

      169                 Case SmtpStatusCode.UserNotLocalWillForward

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 11, 2009 12:10 AM

All replies

  • User-814327568 posted

    What is the problem you are facing doing so... 

    Friday, November 6, 2009 11:13 PM
  • User1823730432 posted

    Page hangs while the email is sent. The page needs to be redirected not hanging till the email is sent

    Friday, November 6, 2009 11:19 PM
  • User-952121411 posted

    For what you need I would use an Asyncronous Delegate.  You can send the email while the page continues processing (or any process for that matter) and should not hang while sending the email.  I have used the following template several times.  Take a look at the basic code below:

    'Used for calling e-mail sub asyncronously 
    Private Delegate Sub SendEmailAsync(ByVal Subject As String, ByVal MessageBody As String, ByVal EmailContact As String, ByVal EmailSender As String)
    
    Protected Overloads Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim AsyncResult As IAsyncResult
            'Launch sending an email on its own thread which will allow the 
            'page to load without waiting
    
            'Create an instance of the delegate with an address of the SendEmail() Sub
            Dim Invoker As New SendEmailAsync(AddressOf SendEmail)
    
            'Invoke the delegate asynchronously.
            AsyncResult = Invoker.BeginInvoke("Hello", "How Are You?", "You@Something.com", "Me@Something.com", Nothing, Nothing)
    
    End Sub
    
    
    Private Sub SendEmail(ByVal Subject As String, ByVal MessageBody As String, ByVal EmailContact As String, ByVal EmailSender As String)
    
        'Code to send email
    
    End Sub

    If you need more assistance, take a look to the following:

    Asynchronous Programming Design Patterns:

    http://msdn.microsoft.com/en-us/library/ms228969.aspx

    Hope this helps! Smile
     

    Tuesday, November 10, 2009 9:45 AM
  • User1823730432 posted

    Hi I have the threading working with a delegate and it works as I would expected

    Any links to information on the error codes

    thanks

      

    159 Case SmtpStatusCode.MustIssueStartTlsFirst

      160                 Case SmtpStatusCode.Ok

      161                 Case SmtpStatusCode.ServiceClosingTransmissionChannel

      162                 Case SmtpStatusCode.ServiceNotAvailable

      163                 Case SmtpStatusCode.ServiceReady

      164                 Case SmtpStatusCode.StartMailInput

      165                 Case SmtpStatusCode.SyntaxError

      166                 Case SmtpStatusCode.SystemStatus

      167                 Case SmtpStatusCode.TransactionFailed

      168                 Case SmtpStatusCode.UserNotLocalTryAlternatePath

      169                 Case SmtpStatusCode.UserNotLocalWillForward

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 11, 2009 12:10 AM