Search in sources :

Example 1 with NoIdentityForSenderException

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;
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) JspException(javax.servlet.jsp.JspException) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException) AddressException(javax.mail.internet.AddressException) Attachment(i2p.bote.email.Attachment) FileAttachment(i2p.bote.email.FileAttachment) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) AddressException(javax.mail.internet.AddressException) PasswordException(i2p.bote.fileencryption.PasswordException) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException)

Example 2 with NoIdentityForSenderException

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();
}
Also used : NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException) EmailIdentity(i2p.bote.email.EmailIdentity)

Aggregations

NoIdentityForSenderException (i2p.bote.email.NoIdentityForSenderException)2 Attachment (i2p.bote.email.Attachment)1 Email (i2p.bote.email.Email)1 EmailIdentity (i2p.bote.email.EmailIdentity)1 FileAttachment (i2p.bote.email.FileAttachment)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 IOException (java.io.IOException)1 AddressException (javax.mail.internet.AddressException)1 InternetAddress (javax.mail.internet.InternetAddress)1 JspException (javax.servlet.jsp.JspException)1 JspWriter (javax.servlet.jsp.JspWriter)1