+ Reply to Thread
Page 3 of 5 FirstFirst 1 2 3 4 5 LastLast
Results 21 to 30 of 41

Thread: Sending Email Asynchronously

  1. #21
    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, 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!!
    Oh....whoops....sorry micky....

    Just realised that the for each loop is just adding each address to the to property, not sending the email as well....

    The delay may be in your mail server...If you still have the whole function I posted, try setting the async flag (check_error, errorCheck or something) in the email function to check for errors and not send asyncronously to see if it makes any difference...

  2. #22
    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
    Oh....whoops....sorry micky....

    Just realised that the for each loop is just adding each address to the to property, not sending the email as well....

    The delay may be in your mail server...If you still have the whole function I posted, try setting the async flag (check_error, errorCheck or something) in the email function to check for errors and not send asyncronously to see if it makes any difference...
    so how do i edit it to not show all addresses in TO field?

    I'll try to check without async.

  3. #23
    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
    so how do i edit it to not show all addresses in TO field?

    I'll try to check without async.
    Try something like:-
    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, ";")
    
            myMail.From = New MailAddress(ConfigurationManager.AppSettings("NoReply"))
            myMail.Body = ""
            myMail.Subject = "Update"
     
            Dim mailBox As Object = myMail
            AddHandler SmtpMail.SendCompleted, AddressOf SmtpClient_OnCompleted
    
            For Each email_to As String In arr_email_to
                myMail.To.Add(New MailAddress(email_to))
                SmtpMail.SendAsync(myMail, mailBox)
                myMail.Remove(0) 'not sure about the remove method, so might have to check if you use the index or the email address string.
            Next
     
        End Function
    

  4. #24
    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'll try it RR.
    But there is no remove property for myMail.

  5. #25
    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

    Sorry micky...Not really thinking straight today...

    Try
    Code:
    For Each email_to As String In arr_email_to
    myMail.To = email_to
    SmtpMail.SendAsync(myMail, mailBox) 

  6. #26
    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
    Sorry micky...Not really thinking straight today...

    Try
    Code:
    For Each email_to As String In arr_email_to
    myMail.To = email_to
    SmtpMail.SendAsync(myMail, mailBox) 
    If i keep the SmtpMail.SendAsync line in For loop RR, i get this strange error!!
    System.InvalidOperationException: RegisterForEventValidation can only be called during Render();
    Last edited by micky; July 4th, 2009 at 04:44 AM.

  7. #27
    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 micky View Post
    If i keep the SmtpMail.SendAsync line in For loop RR, i get this strange error!!
    Workaround for this error was to add this
    Code:
    <%@ Page Language="VB" Async="true" EnableEventValidation="false" 
    But then it says that already a async procedure is running.

    So i assume that i cant have that SmtpMail.SendAsync line in For loop.

    But it just keep sending all emails in TO field.
    I think its the problem with system.net.mail.mailmessage.to, its a collection address

    Any ideas anyone?

  8. #28
    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 made some changes and it seems to be working now.
    Its sending mail one by one now.
    Thanx RR
    Code:
            Dim arr_email_to As Array = Split(emails, ";")
    
            For Each email_to As String In arr_email_to
                Dim SmtpMail As New SmtpClient(ConfigurationManager.AppSettings("SmtpServer"), 25)
                Dim myMail As New MailMessage()
    
                myMail.From = New MailAddress(ConfigurationManager.AppSettings("NoReply"))
                myMail.Body = "Update"
                myMail.Subject = "Update"
    
                myMail.To.Add(New MailAddress(email_to))
                SmtpMail.SendAsync(myMail, Nothing)
            Next
    

  9. #29
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by micky View Post
    Workaround for this error was to add this
    Code:
    <%@ Page Language="VB" Async="true" EnableEventValidation="false" 
    M, my only comment on this thread is regarding disabling Event Validation. Event Validation reduces the risk of unauthorized postbacks and callbacks. I would look into a better solution for this.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  10. #30
    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 jmurrayhead View Post
    M, my only comment on this thread is regarding disabling Event Validation. Event Validation reduces the risk of unauthorized postbacks and callbacks. I would look into a better solution for this.
    I can remove that.

    But ironically, now the code is showing emails in TO field again and also sending mails with different number of recipients to same person.
    Darn

+ Reply to Thread
Page 3 of 5 FirstFirst 1 2 3 4 5 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