-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
432 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM linagora/james-jpa-sample:3.0.1 | ||
|
||
RUN chgrp -R 0 /root /logs /var && \ | ||
chmod -R g=u /root /logs /var && \ | ||
sed -i s/:143/:1143/g /root/conf/imapserver.xml && \ | ||
sed -i s/:993/:1993/g /root/conf/imapserver.xml && \ | ||
sed -i s/:110/:1110/g /root/conf/pop3server.xml && \ | ||
sed -i s/:25/:1025/g /root/conf/smtpserver.xml && \ | ||
sed -i s/:465/:1465/g /root/conf/smtpserver.xml && \ | ||
sed -i s/:587/:1587/g /root/conf/smtpserver.xml | ||
|
||
RUN echo "touch /root/done.mark" >> /root/initialdata.sh | ||
|
||
ENTRYPOINT ["/root/startup.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,14 @@ batch | |
/subsystem=mail/mail-session=MyOtherMail:add(jndi-name=java:jboss/mail/MyOtherMail,debug=true) | ||
|
||
# Configure the custom SMTP, POP3, and IMAP socket binding groups | ||
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=my-smtp-binding:add(host=localhost,port=25) | ||
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=my-pop3-binding:add(host=localhost,port=110) | ||
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=my-imap-binding:add(host=localhost,port=143) | ||
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=my-smtp-binding:add(host=localhost,port=1025) | ||
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=my-pop3-binding:add(host=localhost,port=1110) | ||
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=my-imap-binding:add(host=localhost,port=1143) | ||
|
||
# Add the custom socket binding groups to the custom MyOtherMail mail session | ||
/subsystem=mail/mail-session=MyOtherMail/server=smtp:add(outbound-socket-binding-ref=my-smtp-binding,username=nobody,password=pass,tls=true) | ||
/subsystem=mail/mail-session=MyOtherMail/server=smtp:add(outbound-socket-binding-ref=my-smtp-binding,username="[email protected]",password=1234) | ||
/subsystem=mail/mail-session=MyOtherMail/server=pop3:add(outbound-socket-binding-ref=my-pop3-binding) | ||
/subsystem=mail/mail-session=MyOtherMail/server=imap:add(outbound-socket-binding-ref=my-imap-binding,username=nobody,password=pass) | ||
/subsystem=mail/mail-session=MyOtherMail/server=imap:add(outbound-socket-binding-ref=my-imap-binding, username="[email protected]",password=1234) | ||
|
||
# Run the batch commands | ||
run-batch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
services: | ||
quickstart-mail-server: | ||
image: "apache/james:demo-3.8.0" | ||
container_name: "apache-james" | ||
hostname: "james.local" | ||
ports: | ||
- "1465:465" | ||
- "1993:993" | ||
- "1025:25" | ||
- "1110:110" | ||
- "1587:587" | ||
- "1143:143" | ||
volumes: | ||
- "./mail-server-conf/imapserver.xml:/root/conf/imapserver.xml" | ||
- "./mail-server-conf/pop3server.xml:/root/conf/pop3server.xml" | ||
- "./mail-server-conf/smtpserver.xml:/root/conf/smtpserver.xml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<imapservers> | ||
<imapserver enabled="true"> | ||
<jmxName>imapserver</jmxName> | ||
<bind>0.0.0.0:143</bind> | ||
<connectionBacklog>200</connectionBacklog> | ||
<tls socketTLS="false" startTLS="true"> | ||
<privateKey>file://conf/private.key</privateKey> | ||
<certificates>file://conf/private.csr</certificates> | ||
</tls> | ||
<connectionLimit>0</connectionLimit> | ||
<connectionLimitPerIP>0</connectionLimitPerIP> | ||
<plainAuthDisallowed>false</plainAuthDisallowed> | ||
<gracefulShutdown>false</gracefulShutdown> | ||
</imapserver> | ||
</imapservers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<pop3servers> | ||
<pop3server enabled="true"> | ||
<jmxName>pop3server</jmxName> | ||
<bind>0.0.0.0:110</bind> | ||
<connectionBacklog>200</connectionBacklog> | ||
<tls socketTLS="false" startTLS="true"> | ||
<privateKey>file://conf/private.key</privateKey> | ||
<certificates>file://conf/private.csr</certificates> | ||
</tls> | ||
<connectiontimeout>1200</connectiontimeout> | ||
<connectionLimit>0</connectionLimit> | ||
<connectionLimitPerIP>0</connectionLimitPerIP> | ||
<handlerchain> | ||
<handler class="org.apache.james.pop3server.core.CoreCmdHandlerLoader"/> | ||
</handlerchain> | ||
</pop3server> | ||
</pop3servers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<smtpservers> | ||
<smtpserver enabled="true"> | ||
<jmxName>smtpserver-global</jmxName> | ||
<bind>0.0.0.0:25</bind> | ||
<connectionBacklog>200</connectionBacklog> | ||
<tls socketTLS="false" startTLS="true"> | ||
<privateKey>file://conf/private.key</privateKey> | ||
<certificates>file://conf/private.csr</certificates> | ||
</tls> | ||
<connectiontimeout>360</connectiontimeout> | ||
<connectionLimit>0</connectionLimit> | ||
<connectionLimitPerIP>0</connectionLimitPerIP> | ||
<auth> | ||
<announce>never</announce> | ||
<requireSSL>false</requireSSL> | ||
</auth> | ||
<verifyIdentity>false</verifyIdentity> | ||
<maxmessagesize>0</maxmessagesize> | ||
<addressBracketsEnforcement>true</addressBracketsEnforcement> | ||
<smtpGreeting>Apache JAMES awesome SMTP Server</smtpGreeting> | ||
<handlerchain> | ||
<handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/> | ||
<handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/> | ||
</handlerchain> | ||
</smtpserver> | ||
</smtpservers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,23 @@ | |
*/ | ||
package org.jboss.as.quickstarts.mail; | ||
|
||
import java.io.Serializable; | ||
|
||
import jakarta.annotation.Resource; | ||
import jakarta.enterprise.context.SessionScoped; | ||
import jakarta.faces.application.FacesMessage; | ||
import jakarta.faces.context.FacesContext; | ||
import jakarta.faces.view.ViewScoped; | ||
import jakarta.inject.Named; | ||
import jakarta.mail.Address; | ||
import jakarta.mail.Folder; | ||
import jakarta.mail.Message; | ||
import jakarta.mail.MessagingException; | ||
import jakarta.mail.Session; | ||
import jakarta.mail.Store; | ||
import jakarta.mail.Transport; | ||
import jakarta.mail.internet.InternetAddress; | ||
import jakarta.mail.internet.MimeMessage; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* <p> | ||
* {@link Email} contains all the business logic for the application, and also serves as the controller for the JSF view. | ||
|
@@ -36,15 +41,17 @@ | |
* It contains address, subject, and content for the <code>email</code> to be sent. | ||
* </p> | ||
* <p> | ||
* The {@link #send()} method provides the business logic to send the email | ||
* The {@link #send()} method provides the business logic to send the email. | ||
* The {@link #retrievePop3()} method retrieves all the emails sent to a specific email account using POP3. | ||
* The {@link #retrieveImap()} method retrieves all the emails sent to an account whose credentials are configured in | ||
* the Mail subsystem using IMAP. | ||
* </p> | ||
* | ||
* @author Joel Tosi | ||
* | ||
*/ | ||
|
||
@Named | ||
@SessionScoped | ||
@ViewScoped | ||
public class Email implements Serializable { | ||
|
||
private static final long serialVersionUID = 1544680932114626710L; | ||
|
@@ -56,14 +63,129 @@ public class Email implements Serializable { | |
@Resource(mappedName = "java:jboss/mail/MyOtherMail") | ||
private Session mySession; | ||
|
||
private String to; | ||
private String to = "[email protected]"; | ||
|
||
private String from; | ||
private String from = "[email protected]"; | ||
|
||
private String subject; | ||
|
||
private String body; | ||
|
||
private String pop3User = "[email protected]"; | ||
private String pop3Password = "1234"; | ||
private String pop3Emails; | ||
|
||
private String imapEmails; | ||
|
||
/** | ||
* Method to send the email based upon values entered in the JSF view. Exception should be handled in a production usage but | ||
* is not handled in this example. | ||
*/ | ||
public void send() { | ||
try { | ||
Message message = new MimeMessage(mySession); | ||
message.setFrom(new InternetAddress(from)); | ||
Address toAddress = new InternetAddress(to); | ||
message.addRecipient(Message.RecipientType.TO, toAddress); | ||
message.setSubject(subject); | ||
message.setContent(body, "text/plain"); | ||
Transport.send(message); | ||
|
||
FacesContext context = FacesContext.getCurrentInstance(); | ||
FacesMessage facesMessage = new FacesMessage("Email sent to " + to); | ||
context.addMessage(null, facesMessage); | ||
} catch (Exception e) { | ||
FacesContext context = FacesContext.getCurrentInstance(); | ||
FacesMessage facesMessage = new FacesMessage("Error sending the Email. " + e.getMessage()); | ||
context.addMessage(null, facesMessage); | ||
} | ||
} | ||
|
||
public void resetSmtp() { | ||
from = "[email protected]"; | ||
to = "[email protected]"; | ||
subject = null; | ||
body = null; | ||
} | ||
|
||
public void retrievePop3() throws Exception { | ||
try { | ||
pop3Emails = retrieveEmails("pop3", pop3User, pop3Password); | ||
} catch (Exception e) { | ||
FacesContext context = FacesContext.getCurrentInstance(); | ||
FacesMessage facesMessage = new FacesMessage("Error retrieving emails using Pop3. " + e.getMessage()); | ||
context.addMessage(null, facesMessage); | ||
} | ||
} | ||
|
||
public void resetPop3() { | ||
pop3User = "[email protected]"; | ||
pop3Password = "1234"; | ||
pop3Emails = null; | ||
} | ||
|
||
public void retrieveImap() throws Exception { | ||
try { | ||
imapEmails = retrieveEmails("imap"); | ||
} catch (Exception e) { | ||
FacesContext context = FacesContext.getCurrentInstance(); | ||
FacesMessage facesMessage = new FacesMessage("Error retrieving emails using Pop3. " + e.getMessage()); | ||
context.addMessage(null, facesMessage); | ||
} | ||
} | ||
|
||
public void resetImap() { | ||
imapEmails = null; | ||
} | ||
|
||
private String retrieveEmails(String protocol) throws MessagingException { | ||
return retrieveEmails(protocol, null, null); | ||
} | ||
|
||
private String retrieveEmails(String protocol, String user, String password) throws MessagingException { | ||
Store store = mySession.getStore(protocol); | ||
if (user != null && !user.trim().isEmpty()) { | ||
store.connect(user, password); | ||
} else { | ||
// Users the credentials configured in the Mail Subsystem | ||
store.connect(); | ||
} | ||
|
||
Folder inbox = store.getFolder("Inbox"); | ||
inbox.open(Folder.READ_ONLY); | ||
|
||
// get the list of inbox messages | ||
Message[] messages = inbox.getMessages(); | ||
|
||
if (messages.length == 0) { | ||
FacesContext context = FacesContext.getCurrentInstance(); | ||
FacesMessage facesMessage = new FacesMessage("No message found for " + user); | ||
context.addMessage(null, facesMessage); | ||
|
||
return null; | ||
} | ||
|
||
StringBuilder sb = new StringBuilder("Emails retrieved via ").append(protocol).append("\n"); | ||
for (int i = 0; i < messages.length; i++) { | ||
// stop after listing ten messages | ||
if (i > 10) { | ||
inbox.close(true); | ||
store.close(); | ||
} | ||
|
||
sb.append("Message ").append((i + 1)).append("\n"); | ||
sb.append("From : ").append(messages[i].getFrom()[0]).append("\n"); | ||
sb.append("Subject : ").append(messages[i].getSubject()).append("\n"); | ||
sb.append("Sent Date : ").append(messages[i].getSentDate()).append("\n"); | ||
sb.append("----------------------------------").append("\n"); | ||
} | ||
|
||
inbox.close(true); | ||
store.close(); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
public String getTo() { | ||
return to; | ||
} | ||
|
@@ -96,19 +218,35 @@ public void setBody(String body) { | |
this.body = body; | ||
} | ||
|
||
/** | ||
* Method to send the email based upon values entered in the JSF view. Exception should be handled in a production usage but | ||
* is not handled in this example. | ||
* | ||
* @throws Exception | ||
*/ | ||
public void send() throws Exception { | ||
Message message = new MimeMessage(mySession); | ||
message.setFrom(new InternetAddress(from)); | ||
Address toAddress = new InternetAddress(to); | ||
message.addRecipient(Message.RecipientType.TO, toAddress); | ||
message.setSubject(subject); | ||
message.setContent(body, "text/plain"); | ||
Transport.send(message); | ||
public String getPop3User() { | ||
return pop3User; | ||
} | ||
|
||
public void setPop3User(String pop3User) { | ||
this.pop3User = pop3User; | ||
} | ||
|
||
public String getPop3Password() { | ||
return pop3Password; | ||
} | ||
|
||
public void setPop3Password(String pop3Password) { | ||
this.pop3Password = pop3Password; | ||
} | ||
|
||
public String getPop3Emails() { | ||
return pop3Emails; | ||
} | ||
|
||
public void setPop3Emails(String pop3Emails) { | ||
this.pop3Emails = pop3Emails; | ||
} | ||
|
||
public String getImapEmails() { | ||
return imapEmails; | ||
} | ||
|
||
public void setImapEmails(String imapEmails) { | ||
this.imapEmails = imapEmails; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.