use of i2p.bote.email.NoIdentityForSenderException in project i2p.i2p-bote by i2p.
the class SendEmailTag method doEndTag.
@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
Email email = new Email(includeSentTime);
String statusMessage;
if (recipients.isEmpty())
statusMessage = _t("Error: Please add at least one recipient.");
else
try {
// set addresses
InternetAddress ia = new InternetAddress(senderAddress);
email.setFrom(ia);
// We must continue to set "Sender:" even with only one mailbox
// in "From:", which is against RFC 2822 but required for older
// Bote versions to see a sender (and validate the signature).
email.setSender(ia);
email.setSubject(subject, "UTF-8");
for (Recipient recipient : recipients) email.addRecipient(recipient.type, recipient.address);
// TODO: Comment out until we determine if this is necessary
// email.fixAddresses();
// set the text and add attachments
email.setContent(message, attachments);
// send the email
I2PBote.getInstance().sendEmail(email);
// delete attachment temp files
for (Attachment attachment : attachments) {
if (!attachment.clean())
log.error("Can't clean up attachment: <" + attachment + ">");
}
statusMessage = _t("The email has been queued for sending.");
} catch (PasswordException e) {
throw new JspException(e);
} catch (NoIdentityForSenderException e) {
statusMessage = _t("Error sending email: {0}", _t("No identity matches the sender/from field: {0}", e.getSender()));
log.error("Error sending email", e);
} catch (AddressException e) {
statusMessage = _t("Error sending email: {0}", _t("Address doesn't contain an Email Destination or an external address: {0}", e.getRef()));
log.error("Error sending email", e);
} catch (Exception e) {
statusMessage = _t("Error sending email: {0}", e.getLocalizedMessage());
log.error("Error sending email", e);
}
try {
out.println(statusMessage);
} catch (IOException e) {
log.error("Can't write output to HTML page", e);
}
return EVAL_PAGE;
}
use of i2p.bote.email.NoIdentityForSenderException in project i2p.i2p-bote by i2p.
the class I2PBote method sendEmail.
public void sendEmail(Email email) throws MessagingException, PasswordException, IOException, GeneralSecurityException {
email.checkAddresses();
// sign email unless sender is anonymous
if (!email.isAnonymous()) {
String sender = email.getOneFromAddress();
EmailIdentity senderIdentity = identities.extractIdentity(sender);
if (senderIdentity == null)
throw new NoIdentityForSenderException(sender);
email.sign(senderIdentity, identities);
}
// set the signature flag so the signature isn't reverified every time the email is loaded
email.setSignatureFlag();
outbox.add(email);
if (outboxProcessor != null)
outboxProcessor.checkForEmail();
}
Aggregations