Exemplo n.º 1
0
        private bool PrepareEmail(SendTokenizedBulkEmail email, ref string message, ref ModuleMessage.ModuleMessageType messageType)
        {
            bool isValid = true;

            switch (teMessage.Mode)
            {
                case "RICH":
                    email.BodyFormat = MailFormat.Html;
                    break;
                default:
                    email.BodyFormat = MailFormat.Text;
                    break;
            }

            switch (cboPriority.SelectedItem.Value)
            {
                case "1":
                    email.Priority = MailPriority.High;
                    break;
                case "2":
                    email.Priority = MailPriority.Normal;
                    break;
                case "3":
                    email.Priority = 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 = SendTokenizedBulkEmail.AddressMethods.Send_TO;
                    break;
                case "BCC":
                    email.AddressMethod = SendTokenizedBulkEmail.AddressMethods.Send_BCC;
                    break;
                case "RELAY":
                    email.AddressMethod = SendTokenizedBulkEmail.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;
        }