Rev 34264 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import javax.servlet.http.HttpServletRequest;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.web.req.ContactUsRequest;import org.apache.logging.log4j.Logger;import org.apache.logging.log4j.LogManager;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.MediaType;import org.springframework.http.ResponseEntity;import org.springframework.mail.javamail.JavaMailSender;import org.springframework.mail.javamail.MimeMessageHelper;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.spice.profitmandi.common.model.UserInfo;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.dao.config.WebDBContextConfigure;import com.spice.profitmandi.dao.entity.dtr.User;import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;import com.spice.profitmandi.dao.repository.dtr.UserRepository;import com.spice.profitmandi.web.req.FeedbackRequest;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiImplicitParams;@Controller@Transactional(rollbackFor=Throwable.class)public class ContactUsController {private static final Logger LOGGER = LogManager.getLogger(ContactUsController.class);@Autowiredprivate JavaMailSender mailSender;@Autowiredprivate ResponseSender<?> responseSender;@Autowiredprivate UserRepository userRepository;@RequestMapping(value = "/contact-us/feedback" , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",required = true, dataType = "string", paramType = "header")})public ResponseEntity<?> sendCrmMail(HttpServletRequest request, @RequestBody FeedbackRequest feedbackRequest) throws Throwable {UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");User user = userRepository.selectById(userInfo.getUserId());MimeMessage message = mailSender.createMimeMessage();MimeMessageHelper helper = new MimeMessageHelper(message);helper.setSubject("New Contact Us message");StringBuffer messageText = new StringBuffer();messageText.append("User Id : ").append(userInfo.getUserId()).append("\n\n");messageText.append("Email : ").append(user.getEmailId()).append("\n\n");messageText.append("Mobile : ").append(user.getMobileNumber()).append("\n\n");messageText.append("Subject : ").append(feedbackRequest.getSubject()).append("\n\n");messageText.append("Message : ").append(feedbackRequest.getMessage());helper.setText(messageText.toString());String[] cc = {"neeraj.arya@smartdukaan.com","rahul.kandpal@smartdukaan.com", "ritesh.chauhan@smartdukaan.com", "krishna.kumar@smartdukaan.com"};//String[] cc = {"amit.gupta@shop2020.in"};helper.setCc(cc);InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");helper.setTo("help@smartdukaan.com");helper.setFrom(senderAddress);mailSender.send(message);LOGGER.info("message send Successfully.....");return responseSender.ok(true);}@RequestMapping(value="/contact-us",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam( name ="Auth-Token",value="Auth-Token",required=true, dataType="string", paramType="header")})public ResponseEntity<?> sendContactMail(HttpServletRequest request, @RequestBody ContactUsRequest contactUsRequest) throws Throwable {if ((contactUsRequest.getMobile() == null || contactUsRequest.getMobile().isEmpty()) && (contactUsRequest.getName() == null || contactUsRequest.getName().isEmpty()) && (contactUsRequest.getEmail() == null || contactUsRequest.getEmail().isEmpty())) {throw new ProfitMandiBusinessException("error", "", "all field are required");}MimeMessage message = mailSender.createMimeMessage();MimeMessageHelper helper = new MimeMessageHelper(message);helper.setSubject("New Contact Us message");String emailContent = "<html>"+ "<body style='font-family: Arial, sans-serif;'>"+ "<h2 style='color: #333;'>New Contact Us Message</h2>"+ "<p><strong>Name:</strong> " + contactUsRequest.getName() + "</p>"+ "<p><strong>Email:</strong> " + contactUsRequest.getEmail() + "</p>"+ "<p><strong>Mobile:</strong> " + contactUsRequest.getMobile() + "</p>"+ "<p><strong>Message:</strong></p>"+ "<p style='background: #f4f4f4; padding: 10px; border-radius: 5px;'>"+ contactUsRequest.getMessage() + "</p>"+ "<br>"+ "<p style='color: #777;'>This email was sent via the Contact Us form.</p>"+ "</body></html>";helper.setText(emailContent, true);String[] cc={"sdtech@smartdukaan.com","manoj.singh1@smartdukaan.com"};helper.setCc(cc);InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", contactUsRequest.getName());helper.setFrom(senderAddress);helper.setReplyTo(contactUsRequest.getEmail());helper.setTo("care@smartdukaan.com");mailSender.send(message);LOGGER.info("message send Successfully"+message);return responseSender.ok(true);}}