public IHttpActionResult Email(EmailFriendRequest request) { var siteRoot = SiteRootContext.Item; // VERIFY CAPTCHA if (!RecaptchaService.Verify(request.RecaptchaResponse)) { return(Ok(new { success = false })); } if (string.IsNullOrWhiteSpace(request.RecipientEmail) || string.IsNullOrWhiteSpace(request.SenderEmail) || string.IsNullOrWhiteSpace(request.SenderName) || string.IsNullOrWhiteSpace(request.ArticleNumber)) { _logger.Warn($"Field is null"); return(Ok(new { success = false })); } //var emailFrom = GetValue(siteRoot?.Email_From_Address); var emailFrom = string.Format("{0} <{1}>", siteRoot.Publication_Name, GetValue(siteRoot?.Email_From_Address)); var allEmails = request.RecipientEmail.Split(';'); var result = true; var emailBody = GetEmailBody(request.SenderEmail, request.SenderName, request.ArticleNumber, request.PersonalMessage); foreach (var eachEmail in allEmails) { string specificEmailBody = emailBody .ReplacePatternCaseInsensitive("#friend_name#", eachEmail) .ReplacePatternCaseInsensitive("#RECIPIENT_EMAIL#", eachEmail); var friendEmail = new Email { To = eachEmail, Subject = request.ArticleTitle, From = emailFrom, Body = specificEmailBody, IsBodyHtml = true }; var isEmailSent = EmailSender.Send(friendEmail); if (!isEmailSent) { _logger.Warn($"Email sender failed"); result = false; } } return(Ok(new { success = result })); }
public IHttpActionResult EmailToAnalyst(EmailAnalyst request) { var siteRoot = SiteRootContext.Item; // VERIFY CAPTCHA if (!RecaptchaService.Verify(request.RecaptchaResponse)) { return(Ok(new { success = false })); } if (string.IsNullOrWhiteSpace(request.AskTheAnalystEmail) || string.IsNullOrWhiteSpace(request.SenderEmail) || string.IsNullOrWhiteSpace(request.SenderName) || string.IsNullOrWhiteSpace(request.ArticleNumber) || string.IsNullOrWhiteSpace(request.CompanyName) || string.IsNullOrWhiteSpace(request.PhoneNumber) || string.IsNullOrWhiteSpace(request.PublicationName)) { _logger.Warn($"Field is null"); return(Ok(new { success = false })); } var emailFrom = string.Format("{0} <{1}>", siteRoot.Publication_Name, GetValue(siteRoot?.Email_From_Address)); var allEmails = request.AskTheAnalystEmail;// request.RecipientEmail.Split(';'); var result = true; var emailBody = GetEmailBody(request.SenderEmail, request.SenderName, request.ArticleNumber, request.PersonalQuestion, request.CompanyName, request.PhoneNumber); string specificEmailBody = emailBody .ReplacePatternCaseInsensitive("#friend_name#", request.AskTheAnalystEmail) .ReplacePatternCaseInsensitive("#RECIPIENT_EMAIL#", request.AskTheAnalystEmail) .ReplacePatternCaseInsensitive("#publication name#", request.PublicationName); var analystEmail = new Email { To = request.AskTheAnalystEmail, Subject = TextTranslator.Translate("Article.ATA.SubjectText") + " - " + request.ArticleTitle, From = emailFrom, Body = specificEmailBody, IsBodyHtml = true }; var isEmailSent = EmailSender.Send(analystEmail); if (!isEmailSent) { _logger.Warn($"Email sender failed"); result = false; } return(Ok(new { success = result })); }