本文介绍了限制每天向用户发送一封电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编码,只要用户点击按钮就会发送电子邮件。现在的任务是,我们需要将发送给用户的电子邮件限制为每天一封,尽管每天都会多次点击按钮。我到目前为止所做的代码是
I have till now coded to send email whenever the user clicks on the button. Now the task is that we need to restrict the emails sent to the user to one per day in spite of clicking the button several times a day. The code I have done till now is
protected void SendUnlockRequest()
{
if (SessionContents.CurrentSchool != null && SessionContents.CurrentUser != null)
{
ContactCollection contactsToEmail = new ContactCollection();
string emailMessage = "";
string emailSubject = "";
if (SessionContents.CurrentUser.UserType.Name == "YTA")
{
var schoolContacts = from p in SessionContents.CurrentSchool.SchoolContacts
where p.PrimaryContact == true
select p;
if (schoolContacts != null)
{
foreach (SchoolContact thisSchoolContact in schoolContacts)
{
if (thisSchoolContact.Contact != null)
{
contactsToEmail.Add(thisSchoolContact.Contact);
}
}
}
emailSubject = "TfL Stars Project unlock request";
emailMessage = "A YTA user at your school, " + SessionContents.CurrentUser.Contact.ContactName + "("
+ SessionContents.CurrentUser.Contact.EmailAddress + "), has requested that their project be unlocked.";
}
else
{
UserDetailService userDetailsService = new UserDetailService();
var boroughContacts = from p in SessionContents.CurrentSchool.Borough.BoroughContacts
select p;
if (boroughContacts != null)
{
foreach (BoroughContact thisBoroughContact in boroughContacts)
{
if (thisBoroughContact.Contact != null)
{
UserDetailCollection userWithReceiveMail = userDetailsService.ReadAllUserWithRecieveMail((int)SessionContents.CurrentBorough.BoroughID, (int)thisBoroughContact.Contact.ContactID);
if (userWithReceiveMail.Count > 0)
{
contactsToEmail.Add(thisBoroughContact.Contact);
}
}
}
}
emailSubject = "TfL Stars Travel Plan unlock request";
emailMessage = "A school user at a school within your Borough, " + SessionContents.CurrentSchool.Name + " - "
+ SessionContents.CurrentUser.Contact.ContactName + "("
+ SessionContents.CurrentUser.Contact.EmailAddress + "), has requested that their travel plan be unlocked.";
}
foreach (Contact thisContact in contactsToEmail)
{
//CDS.Framework.Library cdsLibrary = new CDS.Framework.Library(Common.ApplicationName);
ApplicationSettings appSettings = new ApplicationSettings(Common.ApplicationName);
//string userPassword = cdsLibrary.DecryptString(thisUserDetail.Password, true);
//string emailSubject = "TfL Stars Account";
StringBuilder sbEmailBody = new StringBuilder();
sbEmailBody.Append("Dear Stars User\n\n");
sbEmailBody.Append(emailMessage);
sbEmailBody.Append("\n\n");
sbEmailBody.Append("If you have any problems please contact the Stars support team.\n\n");
EmailUtil.SendEmail(appSettings.SupportFromEmailAddress, "TfL Stars", thisContact.EmailAddress,
thisContact.ContactName, emailSubject, sbEmailBody.ToString());
}
}
}
我尝试了什么:
任何人都可以帮我完成这项任务。
What I have tried:
Can anyone please help me to complete this task.
推荐答案
这篇关于限制每天向用户发送一封电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!