Asychronously sending e-mail, lambda expression edition

Is there anything cooler, code-wise, than lambda expressions? It is what I envisioned when I wanted to be a computer programmer, writing programs with obscure syntax surrounding my huge pieces of electronics and bubbling cauldrons.

With lambda expressions, we get this. Here is one that uses the SmtpClient in ASP.NET to asynchronously send a message. You could do something interesting when the function checks for success or failure, but I didn’t.

MailMessage Message = new MailMessage(,;
Message.Subject = "Test asyc";
Message.Body = "Body text!";         
SmtpClient Smtp = new SmtpClient("");         
Smtp.SendCompleted += new SendCompletedEventHandler((Object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
            if (e.Error != null)
                string test = e.Error.Message;
                string Success = string.Empty;
        Smtp.SendAsync(Message, Message);
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: