spring mail

Solutions on MaxInterview for spring mail by the best coders in the world

showing results for - "spring mail"
Jaden
14 Mar 2018
1// of course you would use DI in any real-world cases
2JavaMailSenderImpl sender = new JavaMailSenderImpl();
3sender.setHost("mail.host.com");
4
5MimeMessage message = sender.createMimeMessage();
6MimeMessageHelper helper = new MimeMessageHelper(message);
7helper.setTo("test@host.com");
8helper.setText("Thank you for ordering!");
9
10sender.send(message);
Luis
03 Mar 2019
1public interface OrderManager {
2
3    void placeOrder(Order order);
4}
Lia
04 Jan 2019
1import javax.mail.Message;
2import javax.mail.MessagingException;
3import javax.mail.internet.InternetAddress;
4import javax.mail.internet.MimeMessage;
5
6import javax.mail.internet.MimeMessage;
7import org.springframework.mail.MailException;
8import org.springframework.mail.javamail.JavaMailSender;
9import org.springframework.mail.javamail.MimeMessagePreparator;
10
11public class SimpleOrderManager implements OrderManager {
12
13    private JavaMailSender mailSender;
14
15    public void setMailSender(JavaMailSender mailSender) {
16        this.mailSender = mailSender;
17    }
18
19    public void placeOrder(final Order order) {
20
21        // Do the business calculations...
22
23        // Call the collaborators to persist the order...
24
25        MimeMessagePreparator preparator = new MimeMessagePreparator() {
26
27            public void prepare(MimeMessage mimeMessage) throws Exception {
28
29                mimeMessage.setRecipient(Message.RecipientType.TO,
30                        new InternetAddress(order.getCustomer().getEmailAddress()));
31                mimeMessage.setFrom(new InternetAddress("mail@mycompany.com"));
32                mimeMessage.setText(
33                    "Dear " + order.getCustomer().getFirstName() + " "
34                        + order.getCustomer().getLastName()
35                        + ", thank you for placing order. Your order number is "
36                        + order.getOrderNumber());
37            }
38        };
39        try {
40            this.mailSender.send(preparator);
41        }
42        catch (MailException ex) {
43            // simply log it and go on...
44            System.err.println(ex.getMessage());
45        }
46    }
47}
Emma
03 Feb 2017
1import org.springframework.mail.MailException;
2import org.springframework.mail.MailSender;
3import org.springframework.mail.SimpleMailMessage;
4
5public class SimpleOrderManager implements OrderManager {
6
7    private MailSender mailSender;
8    private SimpleMailMessage templateMessage;
9
10    public void setMailSender(MailSender mailSender) {
11        this.mailSender = mailSender;
12    }
13
14    public void setTemplateMessage(SimpleMailMessage templateMessage) {
15        this.templateMessage = templateMessage;
16    }
17
18    public void placeOrder(Order order) {
19
20        // Do the business calculations...
21
22        // Call the collaborators to persist the order...
23
24        // Create a thread safe "copy" of the template message and customize it
25        SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
26        msg.setTo(order.getCustomer().getEmailAddress());
27        msg.setText(
28            "Dear " + order.getCustomer().getFirstName()
29                + order.getCustomer().getLastName()
30                + ", thank you for placing order. Your order number is "
31                + order.getOrderNumber());
32        try{
33            this.mailSender.send(msg);
34        }
35        catch(MailException ex) {
36            // simply log it and go on...
37            System.err.println(ex.getMessage());
38        }
39    }
40}
Miranda
22 Jul 2016
1<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
2  <property name="host" value="mail.mycompany.com"/>
3</bean>
4
5<!-- this is a template message that we can pre-load with default state -->
6<bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage">
7  <property name="from" value="customerservice@mycompany.com"/>
8  <property name="subject" value="Your order"/>
9</bean>
10
11<bean id="orderManager" class="com.mycompany.businessapp.support.SimpleOrderManager">
12  <property name="mailSender" ref="mailSender"/>
13  <property name="templateMessage" ref="templateMessage"/>
14</bean>
queries leading to this page
spring boot mail apimail spring webcustom email generation in spring bootspring mailermail in java spring bootmailmessage in springbootspring mail serversend email java controlerspring boot send mailsending email spring bootmail springjava mail in spring bootspring mail username and passwordspring boot send emailshow to use spring mailjava spring mail managementmail spring bootspring boot email examplejava mail sender spring bootspring boot emailsend mail with spring bootsend email spring bootspring emailsapring boot mailspring boot send emailspring boot mailspring boot mail support tutorialsprin boot mailersend email in spring boot examplehow to send email in java spring bootjava mail spring bootmailing in spring boot 27java mailsenderspring send emails using gmail smtpsend email springemail spring boot servicespring java mailemail notification backend spring bootspring boot java mail senderspring mail properties mail smtp socketfactory classspring boot email servicehow to send email in spring boot using javamailsenderspring mail exampleemail server client project springspring mail propertiesspring mailspring boot mail get email contentspring boot email sending examplespring mail protocolspring boot java mail examplemailjet spring bootjava spring boot mail sespring boot mailingsend email from spring boot applicationjava mail senderspring boot mailssend emails spring bootsend email using java spring bootmimemailmessage spring exampleemail service provider java springjavamailsender smtp frommime message baeuldungspring test java mailspring boot mail propertiesspring send mailspring boot mail get contentspringboot mailerspring boot html emailmail sender spring bootsend email in java spring bootjava mail with springbootspring mail propertiesspring boot javamailsenderspring mail