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(cooldude@here.com, awsomeguy@there.com);
Message.Subject = "Test asyc";
Message.Body = "Body text!";         
SmtpClient Smtp = new SmtpClient("127.0.0.1");         
Smtp.SendCompleted += new SendCompletedEventHandler((Object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
        {
            if (e.Error != null)
            {
                string test = e.Error.Message;
            }
            else
            {
                string Success = string.Empty;
            }
        });
        Smtp.SendAsync(Message, Message);
Advertisements
  1. Leave a comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: