Untitled
unknown
plain_text
3 years ago
1.6 kB
9
Indexable
//applicationproperties
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=project.foodapp.70@gmail.com
spring.mail.password=dzhcyrjvewvtllrq
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
//billrest
	@PostMapping(path="/sendEmail")
	String sendMail(@RequestBody Map<String, Object> requestMap) throws MessagingException;
//billrestimpl
@Override
	public String sendMail(Map<String, Object> requestMap) throws MessagingException {
		 
		 String data=billService.sendMail(requestMap);
		 
		 return data;
}
//billservice
String sendMail(Map<String, Object> requestMap) throws MailException, MessagingException;
//billserviceimpl
@Value("${spring.mail.username}")
	private String sender;
	
	
	@Autowired
	private JavaMailSender mailSender;
	@Override
	public String sendMail(Map<String, Object> requestMap) throws MailException, MessagingException {
		MimeMessage message = mailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		
		
		try {
			// Creating a simple mail message
			SimpleMailMessage mailMessage = new SimpleMailMessage();
			// Setting up necessary details
			mailMessage.setFrom(sender);
			mailMessage.setTo(bill.getEmail());
			mailMessage.setText(bill.getName());
			mailMessage.setText(bill.getContactNumber());
			mailMessage.setText(bill.getCreatedBy());
			mailMessage.setText(bill.getProductDetail());
			// Sending the mail
			mailSender.send(mailMessage);
			return "Mail Sent Successfully...";
		}
		catch (Exception e) {
			return "Error while Sending Mail";
		}
}
Editor is loading...