• Icon: Sub-task Sub-task
    • Resolution: Unresolved
    • Icon: Major Major
    • 3.x Future
    • 2.17.0.Final
    • Java EE

      It would be good to have a command to quickly add code to allow sending an email. The following command would create the needed code using all the defaults :

      email-add-send-message-method --named sendMessage
      

      This would inject the default javax.mail.Session and add a method to send an email :

      @Resource
      Session session;
      
      public void sendMessage() {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("from@email.com"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to@email.com"));
        message.setSubject("Subject");
        message.setText("Body");
      
        Transport t = session.getTransport();
        t.connect("user", "password");
        t.sendMessage(message, message.getAllRecipients());
      }
      

      We could customize optional parameters such as :

      mail-add-send-message-method --named sendMessage --mailSession java:comp/myMailSession --from antonio.goncalves@gmail.com --to ggastaldi@gmail.com,lincoln@gmail.com --subject Here is an email subject --body And here is the body --user tiger --password scott
      
      @Resource(lookup = "java:comp/myMailSession")
      Session session;
      
      public void sendMessage() {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("antonio.goncalves@gmail.com"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ggastaldi@gmail.com,lincoln@gmail.com"));
        message.setSubject("Here is an email subject");
        message.setText("And here is the body");
      
        Transport t = session.getTransport();
        t.connect("tiger", "scott");
        t.sendMessage(message, message.getAllRecipients());
      }
      

              Unassigned Unassigned
              agoncal Antonio Goncalves (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: