Rev 23388 | Rev 23568 | Go to most recent revision | 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 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.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 {@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@profitmandi.com", "ProfitMandi Admin");helper.setTo("help@profitmandi.com");helper.setFrom(senderAddress);mailSender.send(message);return responseSender.ok(true);}}