ThirdPartyMailClient(MailProperties mailProperties, String productName) { this.username = mailProperties.getSMTPUsername(); this.password = mailProperties.getSMTPPassword(); this.host = mailProperties.getSMTPHost(); log.info("Initializing SparkPost smtp mail transport. Username : {}. SMTP host : {}:{}", username, host, mailProperties.getSMTPort()); this.session = Session.getInstance(mailProperties); try { String mailFrom = mailProperties.getProperty("mail.from"); if (mailFrom != null) { mailFrom = mailFrom.replace(Placeholders.PRODUCT_NAME, productName); } this.from = new InternetAddress(mailFrom); } catch (AddressException e) { throw new RuntimeException("Error initializing MailWrapper."); } }
public MailWrapper(MailProperties mailProperties, String productName) { String host = mailProperties.getProperty("mail.smtp.host"); if (host != null) { mailProperties.put("mail.smtp.ssl.trust", host); } if (host != null && (host.endsWith("sparkpostmail.com") || host.endsWith("amazonaws.com"))) { // Amazon AWS Simple Email Service uses an account (mail.from) distinct from the username, // which is just like SparkPost. client = new ThirdPartyMailClient(mailProperties, productName); } else { client = new GMailClient(mailProperties); } this.reportBody = FileLoaderUtil.readReportEmailTemplate(); this.productName = productName; }
public static void main(String[] args) throws Exception { Map<String, String> cmdProperties = ArgumentsParser.parse(args); ServerProperties serverProperties = new ServerProperties(cmdProperties); LoggerUtil.configureLogging(serverProperties); //required for logging dynamic context System.setProperty("data.folder", serverProperties.getProperty("data.folder")); //required to avoid dependencies within model to server.properties setGlobalProperties(serverProperties); MailProperties mailProperties = new MailProperties(cmdProperties); SmsProperties smsProperties = new SmsProperties(cmdProperties); GCMProperties gcmProperties = new GCMProperties(cmdProperties); TwitterProperties twitterProperties = new TwitterProperties(cmdProperties); Security.addProvider(new BouncyCastleProvider()); boolean restore = Boolean.parseBoolean(cmdProperties.get(ArgumentsParser.RESTORE_OPTION)); start(serverProperties, mailProperties, smsProperties, gcmProperties, twitterProperties, restore); }
this.reportScheduler = new ReportScheduler(1, downloadUrl, mailWrapper, reportingDiskDao, userDao.users); String contactEmail = serverProperties.getProperty("contact.email", mailProperties.getSMTPUsername()); this.sslContextHolder = new SslContextHolder(props, contactEmail); this.tokensPool = new TokensPool(serverProperties.getReportingFolder());
@GET @Path("/{name}") public Response getConfigByName(@PathParam("name") String name) { switch (name) { case TOKEN_MAIL_BODY : return ok(new Config(name, textHolder.tokenBody).toString()); case SERVER_PROPERTIES_FILENAME : return ok(new Config(name, serverProperties).toString()); case MAIL_PROPERTIES_FILENAME : return ok(new Config(name, new MailProperties(Collections.emptyMap())).toString()); case GCM_PROPERTIES_FILENAME : return ok(new Config(name, new GCMProperties(Collections.emptyMap())).toString()); case TWITTER_PROPERTIES_FILENAME : return ok(new Config(name, new TwitterProperties(Collections.emptyMap())).toString()); default : return badRequest(); } }
GMailClient(MailProperties mailProperties) { String username = mailProperties.getSMTPUsername(); String password = mailProperties.getSMTPPassword(); log.info("Initializing gmail smtp mail transport. Username : {}. SMTP host : {}:{}", username, mailProperties.getSMTPHost(), mailProperties.getSMTPort()); this.session = Session.getInstance(mailProperties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { this.from = new InternetAddress(username); } catch (AddressException e) { throw new RuntimeException("Error initializing MailWrapper." + e.getMessage()); } }