Search in sources :

Example 1 with Mail

use of com.storedobject.mail.Mail in project SODevelopment by syampillai.

the class MailForm method process.

@Override
protected boolean process() {
    String s = emails(addressField);
    if (s.isEmpty()) {
        warning("Please select the address to send to");
        return false;
    }
    Mail m = new Mail();
    SenderGroup sg = getSenderGroup();
    if (sg != null) {
        m.setSenderGroup(sg);
    } else {
        m.setSenderGroup(senderField.getObject());
    }
    m.setToAddress(s);
    s = emails(ccField);
    if (!s.isEmpty()) {
        m.setCCAddress(s);
    }
    m.setSubject(subjectField.getValue());
    m.setMessage(contentField.getValue());
    FileData[] a = null;
    if (attachments != null) {
        try {
            a = attachments.files();
        } catch (SOException e) {
            warning(e);
            return false;
        }
    }
    if (a == null) {
        if (!transact(m::save)) {
            return false;
        }
    } else {
        if (!m.attach(getTransactionManager(), a)) {
            error("Error while attaching files");
            return false;
        }
    }
    try {
        m.reload();
        addOtherAttachments(m);
        m.ready();
    } catch (Throwable e) {
        error(e);
        return false;
    }
    transact(m::save);
    warning("Mail created successfully for sending...");
    return true;
}
Also used : SenderGroup(com.storedobject.mail.SenderGroup) SOException(com.storedobject.common.SOException) Mail(com.storedobject.mail.Mail)

Aggregations

SOException (com.storedobject.common.SOException)1 Mail (com.storedobject.mail.Mail)1 SenderGroup (com.storedobject.mail.SenderGroup)1