Search in sources :

Example 1 with SenderGroup

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

the class MailForm method buildFields.

@Override
protected void buildFields() {
    String userEmail = getTransactionManager().getUser().getPerson().getContact("email");
    senderField = new ObjectField<>("From", SenderGroup.class, ObjectField.Type.CHOICE);
    senderField.setValue((Id) null);
    senderField.setFilter(g -> {
        for (Sender s : StoredObject.list(Sender.class, "SenderGroup=" + g.getId(), true)) {
            if (s.getFromAddress().equalsIgnoreCase(userEmail) || s.getReplyToAddress().equalsIgnoreCase(userEmail)) {
                senderGroup = g;
                return true;
            }
        }
        return false;
    });
    addField(senderField);
    if (senderGroup != null) {
        senderField.setValue(senderGroup);
        senderGroup = null;
    }
    addressField = new TokensField<>("To");
    addField(addressField);
    ccField = new TokensField<>("CC");
    addField(ccField);
    subjectField = new TextField("Subject");
    addField(subjectField);
    setAllowAttachments(allowAttachments);
    contentField = new TextArea("Content");
    addField(contentField);
}
Also used : Sender(com.storedobject.mail.Sender) SenderGroup(com.storedobject.mail.SenderGroup) TextArea(com.vaadin.flow.component.textfield.TextArea)

Example 2 with SenderGroup

use of com.storedobject.mail.SenderGroup 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

SenderGroup (com.storedobject.mail.SenderGroup)2 SOException (com.storedobject.common.SOException)1 Mail (com.storedobject.mail.Mail)1 Sender (com.storedobject.mail.Sender)1 TextArea (com.vaadin.flow.component.textfield.TextArea)1