Solved

Sending Email SMTP Client Asynchronously

Posted on 2015-01-14
1
39 Views
Last Modified: 2016-01-30
I need to send email asychronously without interrupting the calling thread, but the built in sendasync method does block the calling thread.  If I run the software I'm using with an internet connection, there is no problem, but if I disconnect the computer from the internet, the software will freeze for approximately 15 seconds before giving up the attempt to send the email.  Here is the code I'm using:


        public void Send_Error_Email(SmtpClient inputClient, MailMessage inputMessage)
        {
            inputClient.SendCompleted += new SendCompletedEventHandler(error_SendCompleted);

            if (inputMessage.To != null)
            {
                if (inputMessage.To.Count > 0)
                {
                    //fix error regarding 'Mailbox unavailable'
                    inputClient.SendAsync(inputMessage, "Email");
                }
            }

Is there something wrong with this code?  I thought it was supposed to run on its own thread based on the MSDN description, but it does not do so. Thanks for any help you can offer.
0
Comment
Question by:l2Bravo
[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
1 Comment
 

Accepted Solution

by:
l2Bravo earned 0 total points
ID: 40591766
Nobody answered the question, but I found a solution by simply creating my own thread to send the email.  While the documentation seems to indicate the SendAsync method does this automatically, I assumed I did not have to.  But, because the documentation does not seem to be correct (or I'm reading it wrong), I created a simple thread to send the email and close after that action is completed, with a timeout of 10 seconds on the Send method.
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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

761 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