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);
}
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;
}
Aggregations