// Path: jcart-core/src/main/java/com/sivalabs/jcart/JCartException.java
// public class JCartException extends RuntimeException
// {
// 	private static final long serialVersionUID = 1L;
// 
// 	public JCartException()
// 	{
// 		super();
// 	}
// 
// 	public JCartException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
// 	{
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public JCartException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// 	public JCartException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public JCartException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 	
// }


import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import com.sivalabs.jcart.JCartException;
/**
 * 
 */
package com.sivalabs.jcart.common.services;





/**
 * @author Siva
 *
 */
@Component
public class EmailService 
{
	private static final JCLogger logger = JCLogger.getLogger(EmailService.class);
	
	@Autowired JavaMailSender javaMailSender;
	
	@Value("${support.email}") String supportEmail;
	
    public void sendEmail(String to, String subject, String content)
	{
        try
		{
        	// Prepare message using a Spring helper
            final MimeMessage mimeMessage = this.javaMailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            message.setSubject(subject);
            message.setFrom(supportEmail);
            message.setTo(to);
            message.setText(content, true /* isHtml */);
            
			javaMailSender.send(message.getMimeMessage());
		} 
        catch (MailException | MessagingException e)
		{
        	logger.error(e);
// Path: jcart-core/src/main/java/com/sivalabs/jcart/JCartException.java
// public class JCartException extends RuntimeException
// {
// 	private static final long serialVersionUID = 1L;
// 
// 	public JCartException()
// 	{
// 		super();
// 	}
// 
// 	public JCartException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
// 	{
// 		super(message, cause, enableSuppression, writableStackTrace);
// 	}
// 
// 	public JCartException(String message, Throwable cause)
// 	{
// 		super(message, cause);
// 	}
// 
// 	public JCartException(String message)
// 	{
// 		super(message);
// 	}
// 
// 	public JCartException(Throwable cause)
// 	{
// 		super(cause);
// 	}
// 	
// }


// Path: jcart-core/src/main/java/com/sivalabs/jcart/common/services/EmailService.java
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import com.sivalabs.jcart.JCartException;

/**
 * 
 */
package com.sivalabs.jcart.common.services;





/**
 * @author Siva
 *
 */
@Component
public class EmailService 
{
	private static final JCLogger logger = JCLogger.getLogger(EmailService.class);
	
	@Autowired JavaMailSender javaMailSender;
	
	@Value("${support.email}") String supportEmail;
	
    public void sendEmail(String to, String subject, String content)
	{
        try
		{
        	// Prepare message using a Spring helper
            final MimeMessage mimeMessage = this.javaMailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            message.setSubject(subject);
            message.setFrom(supportEmail);
            message.setTo(to);
            message.setText(content, true /* isHtml */);
            
			javaMailSender.send(message.getMimeMessage());
		} 
        catch (MailException | MessagingException e)
		{
        	logger.error(e);
			throw new JCartException("Unable to send email");