private void cmdSubscribe_Click(object sender, System.EventArgs e) { string emailAddress = txtEmail.Text; if (emailAddress == null || emailAddress == string.Empty) { AddErrorMessage(Translate("/bvnetwork/sendmail/subscribe/errornoemail")); return; } emailAddress = emailAddress.Trim(); EPiMailEngine engine = new EPiMailEngine(); ArrayList resultArray = new ArrayList(); EmailAddresses importedItems = new EmailAddresses(); foreach(ListItem itm in this.chkNewsLetterLists.Items) { if (itm.Selected) { // Check that the user does not belong to the groups // already. RecipientList list = RecipientList.Load(Convert.ToInt32(itm.Value)); SubscriptionStatus status = new SubscriptionStatus(); status.RecipientListName = list.Name; //Load and check if the email typed by the user exists. EmailAddress emailItem = EmailAddress.Load(list.Id, emailAddress); if (emailItem == null) { // Create it, and save it. It is automatically // added to the WorkItems collection emailItem = list.CreateEmailAddress(emailAddress); // Save emailItem.Save(); status.SubscriptionResult = true; } else { // Already subscribes status.SubscriptionResult = true; status.Message = Translate("/bvnetwork/sendmail/subscribe/alreadysubscribe") ; } resultArray.Add(status); } } // Done adding, now show the result rptResult.DataSource = resultArray; rptResult.DataBind(); }
private void cmdUnsubscribe_Click(object sender, System.EventArgs e) { string emailAddress = txtEmail.Text; if (emailAddress == null || emailAddress == string.Empty) { AddErrorMessage(Translate("/bvnetwork/sendmail/unsubscribe/errornoemail")); return; } emailAddress = emailAddress.Trim(); EPiMailEngine engine = new EPiMailEngine(); ArrayList resultArray = new ArrayList(); EmailAddresses importedItems = new EmailAddresses(); foreach (ListItem itm in this.chkNewsLetterLists.Items) { if (itm.Selected) { //Load the selected recipient list RecipientList list = RecipientList.Load(Convert.ToInt32(itm.Value)); SubscriptionStatus status = new SubscriptionStatus(); status.RecipientListName = list.Name; //load user email address EmailAddress emailItem = EmailAddress.Load(list.Id, emailAddress); if (emailItem != null) { //Delete the user from the list, and show a confirm message emailItem.Delete(); status.SubscriptionResult = true; status.Message = Translate("/bvnetwork/sendmail/unsubscribe/recipientremoved"); } else { status.SubscriptionResult = false; status.Message = Translate("/bvnetwork/sendmail/unsubscribe/nosubscriptionfound"); } //add the result to the array list. resultArray.Add(status); } } // Done adding, now show the result rptResult.DataSource = resultArray; rptResult.DataBind(); }