0

我有点卡在这里。我想编辑使用存储过程从数据库中获取的某些字段。我正在尝试发送已将所有内容存储在“电子邮件”表中的电子邮件信息。从“电子邮件”表中获取信息后,我想编辑从数据库中获取的正文信息,然后使用我创建的电子邮件服务将其发送给用户。以下是我到目前为止所做的。我创建了一个哈希表并在那里存储了值:

MembershipUser qiUser = ((GenericMembershipProvider)Membership.Provider).GetUser(objSubAccount.CreatedByUser, false);

            Hashtable mailKeywords = new Hashtable();
            mailKeywords.Add("[AccountNumber]", objSubAccount.AccountNumber);
            mailKeywords.Add("[AccountSubmissionDate]", objSubAccount.SubmittedOn.ToString());
            mailKeywords.Add("[FBONameTitle]", objSubAccount.FBO1FirstName.Trim().Length == 0 && objSubAccount.FBO1MiddleInitial.Trim().Length == 0 && objSubAccount.FBO1LastName.Trim().Length == 0
            ? objSubAccount.FBO1AccountTitling : objSubAccount.FBO1FirstName + " " + objSubAccount.FBO1MiddleInitial + " " + objSubAccount.FBO1LastName);
            mailKeywords.Add("[QIName]", objSubAccount.CompanyName);
            mailKeywords.Add("[QIUserName]", qiUser.UserName);
            mailKeywords.Add("[QIUserEmailAddress]", qiUser.Email);
            mailKeywords.Add("[WireEmailNotification1]", objSubAccount.WireEmailNotification1);
            mailKeywords.Add("[WireEmailNotification2]", objSubAccount.WireEmailNotification2);
            mailKeywords.Add("[WireEmailNotification3]", objSubAccount.WireEmailNotification3);

现在我已将这些值分配给类 EmailContent 的不同属性,如下所示:

EmailContent objEmailContent = new EmailContent();
            objEmailContent = EmailContent.GetEmailContentType(EmailContentType.WireroomGroup);
            objEmailContent.To = BancorpConfig.WireroomReceiverEmail;
            objEmailContent.Sender = BancorpConfig.WireRoomSenderEmail;
            objEmailContent.Subject = EmailContent.ReplacePlaceHolder(objEmailContent.Subject, mailKeywords);
            objEmailContent.Body = EmailContent.ReplacePlaceHolder(objEmailContent.Body, mailKeywords);
            objEmailContent.From = BancorpConfig.WireRoomSenderEmail;
            objEmailContent.MailDate = System.DateTime.Now;

现在我想要做的是,当我在 objEmailContent.Body 中获得值时,我想编辑它,就好像它们在 WireEmailNotificaion1 列中没有值一样,然后应该删除括号“()”。如果它们是 WireEmailNotification1,则该值应显示为 (aa@gmail.com) 否则不应显示任何值,也应删除括号。

邮件正文如下:

New QI Sub Account Application Submitted<br />
Account Number: ([AccountNumber])<br />
FBO Name/Account Title: ([FBONameTitle]) <br />
Application Submitted Date: ([AccountSubmissionDate])<br />
QI Name: ([QIName])<br />QI User Name: ([QIUserName])<br />
QI User Email Address: ([QIUserEmailAddress])<br />
Wire Email Notification 1: ([WireEmailNotification1])<br/>
Wire Email Notification 2: ([WireEmailNotification2])<br/>
Wire Email Notification 3: ([WireEmailNotification3])<br/>
Please add account to the Caller ID’s on Schedule A of the Wire Agreement.

如果它们在 WireEmailNotification1、WireEmailNotification2、WireEmailNotification3 中没有值,我将如何从正文中删除括号?

4

2 回答 2

0

如果我理解正确,您有一个模板,并且您想从数据库中获取一些值并将其放入消息正文中。当我有这个要求时,我实际上创建了 HTML 模板以及您想要放置动态内容的位置,定义了一些标签(就像您所做的那样),然后找到每个标签并将其替换为相应的字段。

其他选项(不是很好),那么既然您在数据库中拥有所有内容,您可以编写一个程序给您最终的消息正文(很容易在程序中映射字段)。您可以为此使用 Exec 'select * from '。

于 2012-09-12T14:57:26.143 回答
0

这对你来说有可能吗?:

  • 从模板中删除括号。
  • 仅在需要时使用三元运算符添加它们

例子:

mailKeywords.Add("[WireEmailNotification1]", objSubAccount.WireEmailNotification1 != "" ? "(" + objSubAccount.WireEmailNotification1 + ")" : "" );

这与说(注意括号)相同:

        if (objSubAccount.WireEmailNotification1 != "")
        {
            mailKeywords.Add("[WireEmailNotification1]", "(" + objSubAccount.WireEmailNotification1+ ")" ); 
        }
        else
        {
            mailKeywords.Add("[WireEmailNotification1]","");
        }
于 2012-09-12T16:05:54.433 回答