19 package org.turro.mail.provider;
21 import java.util.Objects;
23 import javax.naming.NamingException;
24 import org.apache.commons.mail.EmailException;
25 import org.apache.commons.mail.HtmlEmail;
26 import org.turro.elephant.context.ElephantContext;
27 import org.turro.string.Strings;
28 import org.turro.util.Comparison;
37 private String hostname;
39 private boolean tls, ssl;
40 private String user, password;
42 private Set<MailRecipient> replies;
43 private Set<MailRecipient> ccs;
44 private Set<MailRecipient> bccs;
59 this.hostname = hostname;
99 this.password = password;
115 this.replies = replies;
122 public void setCcs(Set<MailRecipient> ccs) {
130 public void setBccs(Set<MailRecipient> bccs) {
136 public void setupMail(HtmlEmail email)
throws NamingException, EmailException {
137 if (hostname.startsWith(
"java:")) {
138 email.setMailSessionFromJNDI(hostname);
140 email.setHostName(hostname);
142 if(port !=
null) email.setSmtpPort(port);
144 email.setSSLOnConnect(
true);
145 if(port !=
null) email.setSslSmtpPort(String.valueOf(port));
147 if(tls) email.setStartTLSEnabled(
true);
148 if(!Strings.isBlank(user) && !Strings.isBlank(password)) {
151 if(email.getFromAddress() ==
null) {
169 return Comparison.ascendant().compare(
id, o.id).get();
175 return Strings.isBlank(
id) || Strings.isBlank(hostname) || from.
isEmpty();
179 id = Strings.nullIfBlank(
id);
180 hostname = Strings.nullIfBlank(hostname);
181 user = Strings.nullIfBlank(user);
182 password = Strings.nullIfBlank(password);
183 from = from.
isEmpty() ? null : from;
184 if(replies !=
null) replies.removeIf(r -> r.isEmpty());
185 if(ccs !=
null) ccs.removeIf(c -> c.isEmpty());
186 if(bccs !=
null) bccs.removeIf(b -> b.isEmpty());
192 hash = 67 * hash + Objects.hashCode(this.
id);
204 if (getClass() != obj.getClass()) {
208 return Objects.
equals(this.
id, other.id);
static String getEncoding()
static byte[] decrypt(byte[] value)
Set< MailRecipient > getBccs()
void setCcs(Set< MailRecipient > ccs)
Set< MailRecipient > getCcs()
boolean equals(Object obj)
void setHostname(String hostname)
void setFrom(MailRecipient from)
void setUser(String user)
void setPort(Integer port)
void setBccs(Set< MailRecipient > bccs)
void setupMail(HtmlEmail email)
void setReplies(Set< MailRecipient > replies)
int compareTo(MailProvider o)
void setPassword(String password)
Set< MailRecipient > getReplies()