+ Reply to Thread
Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 41

Thread: Sending Email Asynchronously

  1. #11
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    ok, so i am about to implement this
    So the current scenario is, i have to first insert a record in database, then send mails to all desired people.

    So after the insert, i should get all the emails of the people from database and then call this function to send mail??

    Secondly, i dont want to anything if the send mail is failed or successful, so do i need this function SmtpClient_OnCompleted?

  2. #12
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Yes you would need this function.

    Send the emails using the async function and then it'll just send them in the background without waiting for a response...

    The Smtp_OnCompleted function is called by the Async sending function.

  3. #13
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    ok, will this function Smtp_OnCompleted printout something if process is failed or successful?

  4. #14
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by micky View Post
    ok, will this function Smtp_OnCompleted printout something if process is failed or successful?
    No, I don't believe so....I can't really remember if I'm honest m...

  5. #15
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by richyrich View Post
    No, I don't believe so....I can't really remember if I'm honest m...
    ok RR, i'll see what happens
    thanx

  6. #16
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    Ok, i am facing this error on red line
    Code:
     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.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: 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.
    
    My code
    Code:
        Public Shared Function SendMailUpdate(ByVal emails As String)
            Dim SmtpMail As New System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings("SmtpServer"), 25)
            Dim myMail As New MailMessage()
    
            'SmtpMail.DeliveryMethod = SmtpDeliveryMethod.Network
            Dim arr_email_to As Array = Split(emails, ";")
    
            For Each email_to As String In arr_email_to
                myMail.To.Add(New MailAddress(email_to))
            Next
    
            myMail.From = New MailAddress(ConfigurationManager.AppSettings("NoReply"))
            myMail.Body = ""
            myMail.Subject = "Update"
    
            Dim mailBox As Object = myMail
            AddHandler SmtpMail.SendCompleted, AddressOf SmtpClient_OnCompleted
            SmtpMail.SendAsync(myMail, mailBox)
        End Function
    
    Function is called from a page like this
    Code:
    GlobalClasses.SendMailUpdate(strEmailIDs)
    
    Any ideas?
    Last edited by micky; July 3rd, 2009 at 09:04 AM.

  7. #17
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    ok added red part in .aspx file of this page in top line and it worked
    Code:
    <%@ Page Language="VB" Async="true" AutoEventWireup="false"
    
    Last edited by micky; July 3rd, 2009 at 08:57 AM.

  8. #18
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    Do you think these lines in function SendMailUpdate above will send only 1 mail??
    Code:
    For Each email_to As String In arr_email_to
        myMail.To.Add(New MailAddress(email_to))
    Next
    
    Last edited by micky; July 3rd, 2009 at 09:08 AM.

  9. #19
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by micky View Post
    Do you think these lines in function SendMailUpdate above only will send 1 mail??
    Code:
    For Each email_to As String In arr_email_to
        myMail.To.Add(New MailAddress(email_to))
    Next
    
    It should send a seperate email to each address in the array created by splitting the list of email addresses you pass to the function

  10. #20
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,758
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by richyrich View Post
    It should send a seperate email to each address in the array created by splitting the list of email addresses you pass to the function
    Ok, its sometimes sending, sometimes not
    Is it a slow process RR, i mean i am receiving mails with some delay??

    Also its showing all addresses in TO field in mail!!

+ Reply to Thread
Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast

Similar Threads

  1. Sending Emails Using ASP.NET
    By richyrich in forum .NET Code Samples
    Replies: 5
    Last Post: July 6th, 2009, 05:21 AM
  2. Sending HTML email...
    By bryceowen in forum PHP Development
    Replies: 3
    Last Post: April 8th, 2009, 08:28 PM
  3. Excel and Email
    By Chrissy in forum ASP Development
    Replies: 10
    Last Post: February 16th, 2009, 09:11 PM
  4. Sending Email with ASP and CDOSYS
    By jmurrayhead in forum ASP Code Samples
    Replies: 1
    Last Post: November 13th, 2008, 09:26 AM
  5. Sending Email using CDOSYS & Classic ASP
    By richyrich in forum ASP Code Samples
    Replies: 0
    Last Post: March 17th, 2008, 10:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO