Пример #1
0
        private void SendEmail(List<string> roleNames, List<UserInfo> users, ref string message, ref ModuleMessage.ModuleMessageType messageType)
        {
            //it is awkward to ensure that email is disposed correctly because when sent asynch it should be disposed by the  asynch thread
            var email = new SendTokenizedBulkEmail(roleNames, users, /*removeDuplicates*/ true, txtSubject.Text, ConvertToAbsoluteUrls(teMessage.Text));

            bool isValid;
            try
            {
                isValid = PrepareEmail(email, ref message, ref messageType);
            }
            catch (Exception)
            {
                email.Dispose();
                throw;
            }

            if (isValid)
            {

                if (optSendAction.SelectedItem.Value == "S")
                {
                    try
                    {
                        SendMailSynchronously(email, out message, out messageType);
                    }
                    finally
                    {
                        email.Dispose();
                    }
                }
                else
                {
                    SendMailAsyncronously(email, out message, out messageType);
                    //dispose will be handled by async thread
                }
            }
        }