Unzip and run mvn clean install
Navigate to Spring-Mail.xml in src/main/resources folder.
Set your gmail email and password like this:
- <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
- <property name="host" value="smtp.gmail.com" />
- <property name="port" value="587" />
- <property name="username" value="yourgmailaddress@gmail.com" />
- <property name="password" value="gmailpassword" />
- <property name="javaMailProperties">
- <props>
- <prop key="mail.smtp.auth">true</prop>
- <prop key="mail.smtp.starttls.enable">true</prop>
- </props>
- </property>
- </bean>
A look of the email bean:
- public class HTMLMail
- {
- private JavaMailSender mailSender;
- public void setMailSender(JavaMailSender mailSender) {
- this.mailSender = mailSender;
- }
- public void sendMail(String from, String to, String subject, String msg) {
- try {
- MimeMessage message = mailSender.createMimeMessage();
- message.setSubject(subject);
- MimeMessageHelper helper;
- helper = new MimeMessageHelper(message, true);
- helper.setFrom(from);
- helper.setTo(to);
- helper.setText(msg, true);
- mailSender.send(message);
- } catch (MessagingException ex) {
- Logger.getLogger(HTMLMail.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
No comments:
Post a Comment