Ejemplo n.º 1
0
        /// <summary>
        ///     Final method for sending emails to the user.
        /// </summary>
        /// <param name="mailWrapper">MailSendingWrapper which will contain a server object and a mail message</param>
        /// <param name="async"></param>
        /// <param name="userToken"></param>
        /// <param name="sendCompletedEventHandler"></param>
        /// <param name="disposeMailWrapper">At the end dispose mail wrapper to free the memory and any blocking of files.</param>
        /// <returns></returns>
        public void SendMail(
            MailSendingWrapper mailWrapper,
            bool async       = true,
            object userToken = null,
            SendCompletedEventHandler sendCompletedEventHandler = null,
            bool disposeMailWrapper = true)
        {
            var server  = mailWrapper.MailServer;
            var message = mailWrapper.MailMessage;

            if (server != null && message != null)
            {
                if (async)
                {
                    //userToken = userToken ?? "None";
                    new Thread(() => {
                        server.Send(message);
                        //if (disposeMailWrapper) {
                        //    Dispose(mailWrapper);
                        //}
                    }).Start();
                }
                else
                {
                    server.Send(message);
                    //if (disposeMailWrapper) {
                    //    Dispose(mailWrapper);
                    //}
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Dispose wrapper object.
 /// </summary>
 /// <param name="wrapper"></param>
 public void Dispose(MailSendingWrapper wrapper)
 {
     wrapper.MailServer.Dispose();
     wrapper.MailMessage.Dispose();
     wrapper.MailMessage = null;
     wrapper.MailServer  = null;
     wrapper             = null;
     GC.Collect();
 }