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.asyncTasks.AsyncCoordinator;
021import io.stallion.asyncTasks.AsyncTaskHandlerBase;
022
023/**
024 * Basic task handler for sending an email asynchronously, given an email address,
025 * template, and subject.
026 */
027public class AsyncEmailSender extends AsyncTaskHandlerBase {
028    private String emailAddress = "";
029    private String template = "";
030    private String subject = "";
031
032    public AsyncEmailSender() {
033
034    }
035
036    public AsyncEmailSender(String email, String template, String subject) {
037        this.emailAddress = email;
038        this.template = template;
039        this.subject = subject;
040    }
041
042    public void process() {
043        AddressEmailer emailer = new AddressEmailer(emailAddress, template, subject);
044        emailer.sendEmail();
045    }
046
047    public void submit() {
048        AsyncCoordinator.instance().enqueue(this);
049    }
050
051
052    public String getEmailAddress() {
053        return emailAddress;
054    }
055
056    public AsyncEmailSender setEmailAddress(String emailAddress) {
057        this.emailAddress = emailAddress;
058        return this;
059    }
060
061    public String getTemplatePath() {
062        return template;
063    }
064
065    public AsyncEmailSender setTemplatePath(String template) {
066        this.template = template;
067        return this;
068    }
069
070    public String getSubject() {
071        return subject;
072    }
073
074    public AsyncEmailSender setSubject(String subject) {
075        this.subject = subject;
076        return this;
077    }
078}