[JBoss JIRA] (FORGE-2411) Being able to send emails
by Antonio Goncalves (JIRA)
Antonio Goncalves created FORGE-2411:
----------------------------------------
Summary: Being able to send emails
Key: FORGE-2411
URL: https://issues.jboss.org/browse/FORGE-2411
Project: Forge
Issue Type: Sub-task
Components: Java EE
Affects Versions: 2.17.0.Final
Reporter: Antonio Goncalves
Fix For: 2.x Future
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 :
{code}
email-add-send-message-method --named sendMessage
{code}
This would inject the default {{javax.mail.Session}} and add a method to send an email :
{code}
@Resource
Session session;
public void sendMessage() {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from(a)email.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to(a)email.com"));
message.setSubject("Subject");
message.setText("Body");
Transport t = session.getTransport();
t.connect("user", "password");
t.sendMessage(message, message.getAllRecipients());
}
{code}
We could customize optional parameters such as :
{code}
mail-add-send-message-method --named sendMessage --mailSession java:comp/myMailSession --from antonio.goncalves(a)gmail.com --to ggastaldi@gmail.com,lincoln(a)gmail.com --subject Here is an email subject --body And here is the body --user tiger --password scott
{code}
{code}
@Resource(lookup = "java:comp/myMailSession")
Session session;
public void sendMessage() {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("antonio.goncalves(a)gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ggastaldi@gmail.com,lincoln(a)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());
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)