Пример #1
0
        /// <summary>
        /// Sends a Reminder Email to a Partner.
        /// </summary>
        /// <param name="APartnerReminderDR">DataRow containing the Reminder data.</param>
        /// <param name="AReadWriteTransaction">Already instantiated DB Transaction.</param>
        /// <param name="Sender">Already instantiated SMTP sender.</param>
        /// <returns>True if the sending of the Reminder Email succeeded, otherwise false.</returns>
        private static bool SendReminderEmail(PPartnerReminderRow APartnerReminderDR, TDBTransaction AReadWriteTransaction, TSmtpSender Sender)
        {
            string Destination = APartnerReminderDR.EmailAddress;
            string PartnerShortName;
            string LanguageCode = "en";
            string FirstName    = "";
            string LastName     = "";

            if ((Destination == String.Empty) && (APartnerReminderDR.UserId != String.Empty))
            {
                // Get the email and language code of the user
                GetEmailOfUser(APartnerReminderDR.UserId, AReadWriteTransaction,
                               out Destination, out LanguageCode, out FirstName, out LastName);
            }

            // Retrieve ShortName of the Partner about whom the Reminder Email should be sent
            PartnerShortName = GetPartnerName(APartnerReminderDR.PartnerKey, AReadWriteTransaction);

            string Domain      = TAppSettingsManager.GetValue("Server.Url");
            string EMailDomain = TAppSettingsManager.GetValue("Server.EmailDomain");
            Dictionary <string, string> emailparameters = new Dictionary <string, string>();

            emailparameters.Add("FirstName", FirstName);
            emailparameters.Add("LastName", LastName);
            emailparameters.Add("Domain", Domain);
            emailparameters.Add("partnername", PartnerShortName);
            emailparameters.Add("partnerkey", string.Format("{0:0000000000}", APartnerReminderDR.PartnerKey));

            if (!APartnerReminderDR.IsContactIdNull() && APartnerReminderDR.ContactId != 0)
            {
                emailparameters.Add("ContactDetails", GetContactDetails(APartnerReminderDR.ContactId, AReadWriteTransaction));
            }

            if (!APartnerReminderDR.IsReminderReasonNull())
            {
                emailparameters.Add("Reason", APartnerReminderDR.ReminderReason);
            }

            if (!APartnerReminderDR.IsEventDateNull())
            {
                emailparameters.Add("EventDate", String.Format("{0}", StringHelper.DateToLocalizedString(APartnerReminderDR.EventDate)));
            }

            emailparameters.Add("Comment", APartnerReminderDR.Comment);

            if (!APartnerReminderDR.IsNextReminderDateNull())
            {
                emailparameters.Add("NextReminderDate", String.Format("{0}", StringHelper.DateToLocalizedString(APartnerReminderDR.NextReminderDate)));
            }

            if (APartnerReminderDR.ReminderActive == false)
            {
                emailparameters.Add("ReminderDisabled", "true");
            }

            // Send Email (this picks up the SmtpHost AppSetting from the Server Config File)
            return(Sender.SendEmailFromTemplate(
                       "no-reply@" + EMailDomain,
                       "OpenPetra Admin",
                       Destination,
                       "reminder",
                       LanguageCode,
                       emailparameters));
        }