コード例 #1
0
        public void SendEmail(EmailCommunicationDTO email, string token)
        {
            var communication = new Communication();
            communication.DomainId = 1;

            if (token == null && email.FromUserId == null)
            {
                throw (new InvalidOperationException("Must provide either email.FromUserId or an authentication token."));
            }

            communication.AuthorUserId = email.FromUserId ?? _communicationService.GetUserIdFromContactId(token, email.FromContactId);

            var sender = _personService.GetPerson(DefaultContactEmailId);
            var from = new Contact { ContactId = sender.ContactId, EmailAddress = sender.EmailAddress };
            communication.FromContact = from;
            communication.ReplyToContact = from;

            var receiver = _personService.GetPerson(email.ToContactId);
            var recipient = new Contact {ContactId = receiver.ContactId, EmailAddress = receiver.EmailAddress};
            communication.ToContacts.Add(recipient);

            var template = _communicationService.GetTemplate(email.TemplateId);
            communication.TemplateId = email.TemplateId;
            communication.EmailBody = template.Body;
            communication.EmailSubject = template.Subject;

            communication.MergeData = email.MergeData;

            _communicationService.SendMessage(communication);
        }
コード例 #2
0
 public void SendEmail(CommunicationDTO emailData)
 {
     var sender = _personService.GetPerson(DefaultContactEmailId);
     var from = new Contact {ContactId = DefaultContactEmailId, EmailAddress = sender.EmailAddress};
     var comm = new Communication
     {
         AuthorUserId = 1,
         DomainId = 1,
         EmailBody = emailData.Body,
         EmailSubject = emailData.Subject,
         FromContact = from,
         ReplyToContact = from,
         MergeData = new Dictionary<string, object>(),
         ToContacts = new List<Contact>()
     };
     foreach (var to in emailData.ToContactIds)
     {
         var contact = new Contact();
         contact.ContactId = to;
         contact.EmailAddress = _communicationService.GetEmailFromContactId(to);
         comm.ToContacts.Add(contact);
     }
     _communicationService.SendMessage(comm);
 }
コード例 #3
0
        public void SendCommunityGroupConfirmationEmail(int participantId, int groupId, bool waitlist, bool childcareNeeded)
        {
            var emailTemplate = _communicationService.GetTemplate(waitlist ? CommunityGroupWaitListConfirmationTemplateId : CommunityGroupConfirmationTemplateId);
            var toContact = _contactService.GetContactIdByParticipantId(participantId);
            var toContactInfo = _contactService.GetContactById(toContact);
            var groupInfo = getGroupDetails(groupId);

            var mergeData = new Dictionary<string, object>
            {
                {"Nickname", toContactInfo.Nickname},
                {"Group_Name", groupInfo.Name},
                {"Congregation_Name", groupInfo.Congregation},
                {"Childcare_Needed", (childcareNeeded) ? _contentBlockService["communityGroupChildcare"].Content : ""}
            };

            var domainId = Convert.ToInt32(AppSettings("DomainId"));
            var from = new Contact()
            {
                ContactId = DefaultEmailContactId,
                EmailAddress = _communicationService.GetEmailFromContactId(DefaultEmailContactId)
            };

            var to = new List<Contact>
            {
                new Contact {
                    ContactId = toContact,
                    EmailAddress = toContactInfo.Email_Address
                }
            };

            var confirmation = new Communication 
            { 
                EmailBody = emailTemplate.Body, 
                EmailSubject = emailTemplate.Subject,
                AuthorUserId = 5,
                DomainId = domainId,
                FromContact = from,
                MergeData = mergeData,
                ReplyToContact = from,
                TemplateId = CommunityGroupConfirmationTemplateId,
                ToContacts = to
            };
            _communicationService.SendMessage(confirmation);
        }
コード例 #4
0
        public void SendTwoRsvpEmails()
        {
            const int daysBefore = 999;
            const int emailTemplateId = 77;
            const int unassignedContact = 7386594;
            var participants = new List<EventParticipant>
            {
                new EventParticipant
                {
                    ParticipantId = 1,
                    EventId = 123,
                    ContactId = 987654
                },
                new EventParticipant
                {
                    ParticipantId = 2,
                    EventId = 456,
                    ContactId = 456123
                }
            };

            var mockPrimaryContact = new Contact
            {
                ContactId = 98765,
                EmailAddress = "*****@*****.**"
            };

            var defaultContact = new MyContact
            {
                Contact_ID = 123456,
                Email_Address = "*****@*****.**"
            };

            var mockEvent1 = new Event {EventType = "Childcare", PrimaryContact = mockPrimaryContact};
            var mockEvent2 = new Event {EventType = "DoggieDaycare", PrimaryContact = mockPrimaryContact};
            var mockEvents = new List<Event> {mockEvent1, mockEvent2};

            _configurationWrapper.Setup(m => m.GetConfigIntValue("NumberOfDaysBeforeEventToSend")).Returns(daysBefore);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("ChildcareRequestTemplate")).Returns(emailTemplateId);
            _communicationService.Setup(m => m.GetTemplate(emailTemplateId)).Returns(new MessageTemplate());            
            _eventParticipantService.Setup(m => m.GetChildCareParticipants(daysBefore)).Returns(participants);
            _communicationService.Setup(m => m.SendMessage(It.IsAny<Communication>())).Verifiable();

            var kids = new List<Participant> { new Participant { ContactId = 456321987 } };
            _crdsEventService.Setup(m => m.EventParticpants(987654321, It.IsAny<string>())).Returns(kids);
            var mockChildcareEvent = new Event {EventId = 987654321};
            var mockContact = new Contact
            {
                ContactId = 8888888,
                EmailAddress = "*****@*****.**"
            };
            mockChildcareEvent.PrimaryContact = mockContact;
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[0].EventId)).Returns(mockChildcareEvent);
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[1].EventId)).Returns(mockChildcareEvent);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(1234);
            _contactService.Setup(mocked => mocked.GetContactById(1234)).Returns(defaultContact); 
            var myKids = new List<Participant>();
            _crdsEventService.Setup(m => m.MyChildrenParticipants(987654, kids, It.IsAny<string>())).Returns(myKids);

            _fixture.SendRequestForRsvp();

            _configurationWrapper.VerifyAll();
            _communicationService.VerifyAll();
            _contactService.VerifyAll();
            _eventParticipantService.VerifyAll();
            _communicationService.VerifyAll();
            _communicationService.Verify(m => m.SendMessage(It.IsAny<Communication>()), Times.Exactly(2));
            _eventService.VerifyAll();
        }
コード例 #5
0
        public void ShouldSendReminderEmails()
        {
            const int pageId = 2203;
            const string apiToken = "1234";
            const int defaultEmailTemplate = 14567;

            var now = DateTime.Now;

            var fakeServeReminder = new ServeReminder()
            {
                OpportunityTitle = "Some Title",
                EventEndDate = now,
                EventStartDate = now,
                EventTitle = "Whatever",
                OpportunityContactId = fakeGroupContact.Contact_ID,
                OpportunityEmailAddress = fakeGroupContact.Email_Address,
                ShiftEnd = new TimeSpan(0, 7, 0, 0),
                ShiftStart = new TimeSpan(0, 9, 0, 0),
                SignedupContactId = fakeMyContact.Contact_ID,
                SignedupEmailAddress = fakeMyContact.Email_Address
            };

            var fakePageView = new MPServeReminders()
            {
                Opportunity_Title = fakeServeReminder.OpportunityTitle,               
                Opportunity_Contact_Id = fakeServeReminder.OpportunityContactId,
                Opportunity_Email_Address = fakeServeReminder.OpportunityEmailAddress,
                Event_End_Date = now,
                Event_Start_Date = now,
                Event_Title = fakeServeReminder.EventTitle,
                Signedup_Contact_Id = fakeMyContact.Contact_ID,
                Signedup_Email_Address = fakeMyContact.Email_Address,
                Template_Id = null,
                Shift_Start = fakeServeReminder.ShiftStart,
                Shift_End = fakeServeReminder.ShiftEnd
            };

            var fakeList = new List<MPServeReminders> ()
            {
                fakePageView
            };

            const int defaultContactEmailId = 1519180;
            

            var token = _apiUserService.Setup(m => m.GetToken()).Returns(apiToken);
            _responseService.Setup(m => m.GetServeReminders(apiToken)).Returns(fakeList);
            _contactService.Setup(m => m.GetContactById(defaultContactEmailId)).Returns(fakeGroupContact);

            fakeList.ForEach(f =>
            {
                var mergeData = new Dictionary<string, object>(){
                    {"Opportunity_Title", fakeServeReminder.OpportunityTitle},
                    {"Nickname", fakeMyContact.Nickname},
                    {"Event_Start_Date", fakeServeReminder.EventStartDate.ToShortDateString()},
                    {"Event_End_Date", fakeServeReminder.EventEndDate.ToShortDateString()},
                    {"Shift_Start", fakeServeReminder.ShiftStart},
                    {"Shift_End", fakeServeReminder.ShiftEnd}
                 };

                var contact = new Contact() {ContactId = fakeGroupContact.Contact_ID, EmailAddress = fakeGroupContact.Email_Address};
                var toContact = new Contact() {ContactId = fakeMyContact.Contact_ID, EmailAddress = fakeMyContact.Email_Address};
                var fakeCommunication = new Communication()
                {
                    AuthorUserId = fakeGroupContact.Contact_ID,
                    DomainId = 1,
                    EmailBody = "Some Email Body",
                    EmailSubject = "Whatever",
                    FromContact = contact,
                    MergeData = mergeData,
                    ReplyToContact = contact,
                    TemplateId = defaultEmailTemplate,
                    ToContacts = new List<Contact>() {toContact}
                };

                _contactService.Setup(m => m.GetContactById(fakeServeReminder.SignedupContactId)).Returns(fakeMyContact);
                _communicationService.Setup(m => m.GetTemplateAsCommunication(defaultEmailTemplate,
                                                                              fakeGroupContact.Contact_ID,
                                                                              fakeGroupContact.Email_Address,
                                                                              fakeServeReminder.OpportunityContactId,
                                                                              fakeServeReminder.OpportunityEmailAddress,
                                                                              fakeMyContact.Contact_ID,
                                                                              fakeMyContact.Email_Address,
                                                                              mergeData)).Returns(fakeCommunication);
                _communicationService.Setup(m => m.SendMessage(fakeCommunication));
                _communicationService.Verify();

            });
            _responseService.Verify();
        }
コード例 #6
0
        public void SendMessageFromDonor(int pledgeId, string message)
        {
            var toDonor = _pledgeService.GetDonorForPledge(pledgeId);
            var donorContact = _donorService.GetEmailViaDonorId(toDonor);
            var template = _communicationService.GetTemplate(_tripDonationMessageTemplateId);

            var toContacts = new List<Contact> {new Contact {ContactId = donorContact.ContactId, EmailAddress = donorContact.Email}};

            var from = new Contact()
            {
                ContactId = 5,
                EmailAddress = "*****@*****.**"
            };

            var defaultContactId = AppSetting("DefaultContactEmailId");
            var defaultContactEmail = _communicationService.GetEmailFromContactId(defaultContactId);

            var comm = new Communication
            {
                AuthorUserId = 5,
                DomainId = 1,
                EmailBody = message,
                EmailSubject = template.Subject,
                FromContact = from,
                ReplyToContact = from,
                ToContacts = toContacts,
                MergeData = new Dictionary<string, object>()
            };
            _communicationService.SendMessage(comm);
        }