#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
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;
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
Send (new MailMessage (from, to, subject, body));
}
+#if NET_4_5
+ public Task SendMailAsync (MailMessage message)
+ {
+ var tcs = new TaskCompletionSource<object> ();
+ 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<object> 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");