001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.settings.childSections; 019 020import io.stallion.settings.SettingMeta; 021 022import java.util.ArrayList; 023import java.util.List; 024import java.util.regex.Pattern; 025 026import static io.stallion.utils.Literals.or; 027 028 029public class EmailSettings implements SettingsSection { 030 @SettingMeta 031 private String host; 032 @SettingMeta 033 private String username; 034 @SettingMeta 035 private String password; 036 @SettingMeta(valBoolean = true) 037 private Boolean tls; 038 @SettingMeta(valLong = 587L) 039 private Long port; 040 @SettingMeta 041 private String defaultFromAddress; 042 @SettingMeta 043 private String canSpamText; 044 @SettingMeta(cls=ArrayList.class) 045 private List<String> adminEmails; 046 @SettingMeta() 047 private Boolean restrictOutboundEmails; 048 @SettingMeta(cls=ArrayList.class) 049 private List<String> allowedOutboundEmails; 050 @SettingMeta(cls=ArrayList.class) 051 private List<String> allowedTestingOutboundEmailPatterns; 052 @SettingMeta(cls=ArrayList.class) 053 private List<Pattern> allowedTestingOutboundEmailCompiledPatterns; 054 @SettingMeta() 055 private String outboundEmailTestAddress; 056 057 /** 058 * The SMTP host 059 * @return 060 */ 061 public String getHost() { 062 return host; 063 } 064 065 public void setHost(String host) { 066 this.host = host; 067 } 068 069 /** 070 * The username with which to connect to the SMTP server 071 * @return 072 */ 073 public String getUsername() { 074 return username; 075 } 076 077 public void setUsername(String username) { 078 this.username = username; 079 } 080 081 /** 082 * The password with which to connect to the SMTP server 083 * @return 084 */ 085 public String getPassword() { 086 return password; 087 } 088 089 public void setPassword(String password) { 090 this.password = password; 091 } 092 093 /** 094 * Whether to use TLS to connect, defaults to true 095 * @return 096 */ 097 public Boolean getTls() { 098 return tls; 099 } 100 101 public void setTls(Boolean tls) { 102 this.tls = tls; 103 } 104 105 /** 106 * The SMTP port to try to connect to, defaults to 587 107 * @return 108 */ 109 public Long getPort() { 110 return port; 111 } 112 113 public void setPort(Long port) { 114 this.port = port; 115 } 116 117 /** 118 * The default email address for the "From" field. 119 * 120 * @return 121 */ 122 public String getDefaultFromAddress() { 123 return defaultFromAddress; 124 } 125 126 public void setDefaultFromAddress(String defaultFromAddress) { 127 this.defaultFromAddress = defaultFromAddress; 128 } 129 130 /** 131 * The name and postal address of the sender, for compliance with the CAN-SPAM law 132 * @return 133 */ 134 public String getCanSpamText() { 135 return or(canSpamText, ""); 136 } 137 138 public void setCanSpamText(String canSpamText) { 139 this.canSpamText = canSpamText; 140 } 141 142 /** 143 * A list of email addresses for admins, these addresses will get exception emails 144 * and other other system emails. 145 * 146 * @return 147 */ 148 public List<String> getAdminEmails() { 149 return adminEmails; 150 } 151 152 public EmailSettings setAdminEmails(List<String> adminEmails) { 153 this.adminEmails = adminEmails; 154 return this; 155 } 156 157 /** 158 * If true, will restrict outbound email address sending to a whitelist of addresses, 159 * all other emails will be converted into a white-listed form using the "+" section. 160 * So if this is true, and the outboundEmailTestAddress email is admin@stallion.io, and you are trying to email 161 * barack@whitehouse.gov, then the to address will be converted to admin+barack-whitehouse-gov@stallion.io 162 * 163 * This is setting is true in local and QA mode. The purpose of this setting is to prevent accidentally 164 * sending real emails to people from the development mode. 165 * 166 * @return 167 */ 168 public Boolean getRestrictOutboundEmails() { 169 return restrictOutboundEmails; 170 } 171 172 public EmailSettings setRestrictOutboundEmails(Boolean restrictOutboundEmails) { 173 this.restrictOutboundEmails = restrictOutboundEmails; 174 return this; 175 } 176 177 /** 178 * A list of regualar expressions, email addresses matching the patterns will be permitted outbound email 179 * addresses even if restrictOutboundEmails is true. 180 * 181 * @return 182 */ 183 public List<String> getAllowedTestingOutboundEmailPatterns() { 184 return allowedTestingOutboundEmailPatterns; 185 } 186 187 public EmailSettings setAllowedTestingOutboundEmailPatterns(List<String> allowedTestingOutboundEmailPatterns) { 188 this.allowedTestingOutboundEmailPatterns = allowedTestingOutboundEmailPatterns; 189 return this; 190 } 191 192 /** 193 * A list of whitelisted outbound email addresses 194 */ 195 public List<String> getAllowedOutboundEmails() { 196 return allowedOutboundEmails; 197 } 198 199 public EmailSettings setAllowedOutboundEmails(List<String> allowedOutboundEmails) { 200 this.allowedOutboundEmails = allowedOutboundEmails; 201 return this; 202 } 203 204 /** 205 * Compiled regular expressions for getAllowedTestingOutboundEmailPatterns() 206 * @return 207 */ 208 public List<Pattern> getAllowedTestingOutboundEmailCompiledPatterns() { 209 return allowedTestingOutboundEmailCompiledPatterns; 210 } 211 212 public EmailSettings setAllowedTestingOutboundEmailCompiledPatterns(List<Pattern> allowedTestingOutboundEmailCompiledPatterns) { 213 this.allowedTestingOutboundEmailCompiledPatterns = allowedTestingOutboundEmailCompiledPatterns; 214 return this; 215 } 216 217 /** 218 * The email address that all outbound emails are routed to in local and QA mode. 219 * 220 * @return 221 */ 222 public String getOutboundEmailTestAddress() { 223 return outboundEmailTestAddress; 224 } 225 226 public EmailSettings setOutboundEmailTestAddress(String outboundEmailTestAddress) { 227 this.outboundEmailTestAddress = outboundEmailTestAddress; 228 return this; 229 } 230}