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.email;
019
020import io.stallion.users.User;
021
022import java.net.MalformedURLException;
023import java.util.Map;
024
025import static io.stallion.utils.Literals.*;
026import static io.stallion.Context.*;
027
028/**
029 * Simple implementation of ContactableEmailer that can send an email
030 * jus using an email address, template, and email subject.
031 */
032public class AddressEmailer extends ContactableEmailer {
033    private String template = "";
034    private String subject = "";
035
036    public AddressEmailer(String emailAddress, String template, String subject) {
037        this(emailAddress, template, subject, map());
038
039    }
040
041    /**
042     *
043     * @param emailAddress
044     * @param template - path to a jinja template
045     * @param subject
046     * @param context - gets passed to the template context
047     */
048    public AddressEmailer(String emailAddress, String template, String subject, Map<String, Object> context) {
049        super(new User()
050                .setDisplayName(emailAddress)
051                .setEmail(emailAddress)
052                .setUsername(emailAddress), context);
053        this.template = template;
054        this.subject = subject;
055    }
056
057
058    @Override
059    public boolean isTransactional() {
060        return true;
061    }
062
063    @Override
064    public String getTemplate() {
065        return template;
066    }
067
068    @Override
069    public String getSubject() {
070        return subject;
071    }
072}