public static void SendJobAdEmailToFriend(string senderName, string senderEmail, string recipientName, string recipientEmail, string userMessage, string adId) { var ad = _jobAdsCommand.GetJobAd <JobAdEntry>(new Guid(adId)); var email = new SendJobToFriendEmail(recipientEmail, recipientName, senderEmail, senderName, ad, userMessage); Container.Current.Resolve <IEmailsCommand>().TrySend(email); }
public ActionResult EmailJobAds(EmailJobAdsModel emailJobAdsModel) { try { // If there is a current member then it needs to come from them. var member = CurrentMember; if (member != null) { emailJobAdsModel.FromName = member.FullName; emailJobAdsModel.FromEmailAddress = member.GetBestEmailAddress().Address; } emailJobAdsModel.Prepare(); emailJobAdsModel.Validate(); foreach (var jobAdId in emailJobAdsModel.JobAdIds) { var jobAd = _jobAdsQuery.GetJobAd <JobAdEntry>(jobAdId); if (jobAd == null) { return(JsonNotFound("job ad")); } // Send to each recipient. foreach (var to in emailJobAdsModel.Tos) { var email = new SendJobToFriendEmail(to.ToEmailAddress, to.ToName, emailJobAdsModel.FromEmailAddress, emailJobAdsModel.FromName, jobAd, null); _emailsCommand.TrySend(email); } } } catch (UserException ex) { ModelState.AddModelError(ex, new JobAdsErrorHandler()); } return(Json(new JsonResponseModel())); }
public void TestSendJobToFriendEmail() { var adToSend = CreateTestEmployerAndJobAd(); // With user entered message. var templateEmail = new SendJobToFriendEmail(RecipientAddress, RecipientDisplayName, SenderAddress, SenderDisplayName, adToSend, MessageText); _emailsCommand.TrySend(templateEmail); var email = _emailServer.AssertEmailSent(); email.AssertAddresses(new EmailRecipient(SenderAddress, SenderDisplayName), Return, new EmailRecipient(RecipientAddress, RecipientDisplayName)); email.AssertHtmlViewChecks(); email.AssertHtmlView(GetBody(templateEmail, new Member { EmailAddresses = new List <EmailAddress> { new EmailAddress { Address = RecipientAddress } } }, GetContent(templateEmail, MessageText, adToSend))); email.AssertNoAttachments(); // Without user entered message. templateEmail = new SendJobToFriendEmail(RecipientAddress, RecipientDisplayName, SenderAddress, SenderDisplayName, adToSend, string.Empty); _emailsCommand.TrySend(templateEmail); email = _emailServer.AssertEmailSent(); email.AssertAddresses(new EmailRecipient(SenderAddress, SenderDisplayName), Return, new EmailRecipient(RecipientAddress, RecipientDisplayName)); email.AssertHtmlViewChecks(); email.AssertHtmlView(GetBody(templateEmail, new Member { EmailAddresses = new List <EmailAddress> { new EmailAddress { Address = RecipientAddress } } }, GetContent(templateEmail, string.Empty, adToSend))); email.AssertNoAttachments(); }