X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FSystem.Net.Mail%2FSmtpClient.cs;h=c6abb68630e6eb9f60d043b808294012f0849c93;hb=10fa44a5e6ab5b6cc4c4a79da9a2a032d0901af5;hp=b151571620f12969ebab482469964ec5b285f772;hpb=a4a65eda9abad788aaf6737d0c83dcb6fe935ea8;p=mono.git diff --git a/mcs/class/System/System.Net.Mail/SmtpClient.cs b/mcs/class/System/System.Net.Mail/SmtpClient.cs index b151571620f..c6abb68630e 100644 --- a/mcs/class/System/System.Net.Mail/SmtpClient.cs +++ b/mcs/class/System/System.Net.Mail/SmtpClient.cs @@ -30,11 +30,12 @@ #if SECURITY_DEP -#if MONOTOUCH +#if MONOTOUCH || MONODROID using System.Security.Cryptography.X509Certificates; #else extern alias PrebuiltSystem; using X509CertificateCollection = PrebuiltSystem::System.Security.Cryptography.X509Certificates.X509CertificateCollection; +using System.Security.Cryptography.X509Certificates; #endif #endif @@ -47,7 +48,6 @@ using System.IO; using System.Net; using System.Net.Mime; using System.Net.Sockets; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Reflection; @@ -55,6 +55,9 @@ using System.Net.Configuration; using System.Configuration; using System.Net.Security; using System.Security.Authentication; +#if NET_4_5 +using System.Threading.Tasks; +#endif namespace System.Net.Mail { public class SmtpClient @@ -745,6 +748,43 @@ namespace System.Net.Mail { Send (new MailMessage (from, to, subject, body)); } +#if NET_4_5 + public Task SendMailAsync (MailMessage message) + { + var tcs = new TaskCompletionSource (); + SendCompletedEventHandler handler = null; + handler = (s, e) => SendMailAsyncCompletedHandler (tcs, e, handler, this); + SendCompleted += handler; + SendAsync (message, tcs); + return tcs.Task; + } + + public Task SendMailAsync (string from, string recipients, string subject, string body) + { + return SendMailAsync (new MailMessage (from, recipients, subject, body)); + } + + static void SendMailAsyncCompletedHandler (TaskCompletionSource source, AsyncCompletedEventArgs e, SendCompletedEventHandler handler, SmtpClient client) + { + if (handler != e.UserState) + return; + + client.SendCompleted -= handler; + + if (e.Error != null) { + source.SetException (e.Error); + return; + } + + if (e.Cancelled) { + source.SetCanceled (); + return; + } + + source.SetResult (null); + } +#endif + private void SendDot() { writer.Write(".\r\n");