コード例 #1
0
 private void SendAndDispose(LocalSendTokenizedBulkEmail email)
 {
     using (email)
     {
         email.Send();
     }
 }
コード例 #2
0
        private void SendMailSynchronously(LocalSendTokenizedBulkEmail email, out string strResult, out ModuleMessage.ModuleMessageType msgResult)
        {
            int mailsSent = email.SendMails();

            if (mailsSent > 0)
            {
                strResult = string.Format(Localization.GetString("MessagesSentCount", LocalResourceFile), mailsSent);
                msgResult = ModuleMessage.ModuleMessageType.GreenSuccess;
            }
            else
            {
                strResult = string.Format(Localization.GetString("NoMessagesSent", LocalResourceFile), email.SendingUser.Email);
                msgResult = ModuleMessage.ModuleMessageType.YellowWarning;
            }
        }
コード例 #3
0
        private void SendMailAsyncronously(LocalSendTokenizedBulkEmail email, out string message, out ModuleMessage.ModuleMessageType messageType)
        {
            //First send off a test message
            var strStartSubj = Localization.GetString("EMAIL_BulkMailStart_Subject.Text", Localization.GlobalResourceFile);

            if (!string.IsNullOrEmpty(strStartSubj))
            {
                strStartSubj = string.Format(strStartSubj, txtSubject.Text);
            }

            var strStartBody = Localization.GetString("EMAIL_BulkMailStart_Body.Text", Localization.GlobalResourceFile);

            if (!string.IsNullOrEmpty(strStartBody))
            {
                strStartBody = string.Format(strStartBody, txtSubject.Text, UserInfo.DisplayName, email.Recipients().Count);
            }

            var sendMailResult = DotNetNuke.Services.Mail.Mail.SendMail(txtFrom.Text,
                                                                        txtFrom.Text,
                                                                        "",
                                                                        "",
                                                                        DotNetNuke.Services.Mail.MailPriority.Normal,
                                                                        strStartSubj,
                                                                        DotNetNuke.Services.Mail.MailFormat.Text,
                                                                        Encoding.UTF8,
                                                                        strStartBody,
                                                                        "",
                                                                        Host.SMTPServer,
                                                                        Host.SMTPAuthentication,
                                                                        Host.SMTPUsername,
                                                                        Host.SMTPPassword,
                                                                        Host.EnableSMTPSSL);

            if (string.IsNullOrEmpty(sendMailResult))
            {
                var objThread = new Thread(() => SendAndDispose(email));
                objThread.Start();
                message     = Localization.GetString("MessageSent", LocalResourceFile);
                messageType = ModuleMessage.ModuleMessageType.GreenSuccess;
            }
            else
            {
                message     = string.Format(Localization.GetString("NoMessagesSentPlusError", LocalResourceFile), sendMailResult);
                messageType = ModuleMessage.ModuleMessageType.YellowWarning;
            }
        }
コード例 #4
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 LocalSendTokenizedBulkEmail(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
                }
            }
        }
コード例 #5
0
        private bool PrepareEmail(LocalSendTokenizedBulkEmail email, ref string message, ref ModuleMessage.ModuleMessageType messageType)
        {
            bool isValid = true;

            switch (teMessage.Mode)
            {
            case "RICH":
                email.BodyFormat = DotNetNuke.Services.Mail.MailFormat.Html;
                break;

            default:
                email.BodyFormat = DotNetNuke.Services.Mail.MailFormat.Text;
                break;
            }

            switch (cboPriority.SelectedItem.Value)
            {
            case "1":
                email.Priority = DotNetNuke.Services.Mail.MailPriority.High;
                break;

            case "2":
                email.Priority = DotNetNuke.Services.Mail.MailPriority.Normal;
                break;

            case "3":
                email.Priority = DotNetNuke.Services.Mail.MailPriority.Low;
                break;

            default:
                isValid = false;
                break;
            }

            if (txtFrom.Text != string.Empty && email.SendingUser.Email != txtFrom.Text)
            {
                var myUser = email.SendingUser ?? new UserInfo();
                myUser.Email      = txtFrom.Text;
                email.SendingUser = myUser;
            }

            if (txtReplyTo.Text != string.Empty && email.ReplyTo.Email != txtReplyTo.Text)
            {
                var myUser = new UserInfo {
                    Email = txtReplyTo.Text
                };
                email.ReplyTo = myUser;
            }

            if (selLanguage.Visible && selLanguage.SelectedLanguages != null)
            {
                email.LanguageFilter = selLanguage.SelectedLanguages;
            }

            if (ctlAttachment.Url.StartsWith("FileID="))
            {
                int fileId      = int.Parse(ctlAttachment.Url.Substring(7));
                var objFileInfo = FileManager.Instance.GetFile(fileId);
                //TODO: support secure storage locations for attachments! [sleupold 06/15/2007]
                email.AddAttachment(FileManager.Instance.GetFileContent(objFileInfo),
                                    new ContentType {
                    MediaType = objFileInfo.ContentType, Name = objFileInfo.FileName
                });
            }

            switch (cboSendMethod.SelectedItem.Value)
            {
            case "TO":
                email.AddressMethod = LocalSendTokenizedBulkEmail.AddressMethods.Send_TO;
                break;

            case "BCC":
                email.AddressMethod = LocalSendTokenizedBulkEmail.AddressMethods.Send_BCC;
                break;

            case "RELAY":
                email.AddressMethod = LocalSendTokenizedBulkEmail.AddressMethods.Send_Relay;
                if (string.IsNullOrEmpty(txtRelayAddress.Text))
                {
                    message     = string.Format(Localization.GetString("MessagesSentCount", LocalResourceFile), -1);
                    messageType = ModuleMessage.ModuleMessageType.YellowWarning;
                    isValid     = false;
                }
                else
                {
                    email.RelayEmailAddress = txtRelayAddress.Text;
                }
                break;
            }

            email.SuppressTokenReplace = !chkReplaceTokens.Checked;

            return(isValid);
        }