Issue Details (XML | Word | Printable)

Key: APF-930
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Matt Raible
Reporter: Laurent ROCHE
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
AppFuse

default.From not working for SMTP (new MailEngine.sendMessage method)

Created: 08/Oct/07 09:38 AM   Updated: 24/Oct/07 01:46 AM   Resolved: 24/Oct/07 01:46 AM
Component/s: Service Layer
Affects Version/s: 1.9.4
Fix Version/s: 2.0.1

Environment:
Win XP and Tomcat
(but it should be identical in other environments)


 Description  « Hide
Hi,

I had troubles sending emails with attachement.
I was using a remote SMTP server (from my internet provider) but there will be the same problems with a local SMTP server.

From what I have gathered there are two flaws in MailEngine method to send attachments
( sendMessage(String[] emailAddresses, ClassPathResource resource, String bodyText, String subject, String attachmentName) )

 - No from:
There is no "helper.setFrom" call, so the from field is defined with sytem variables (login@machine_name) and not with the mail.default.from (from the mail.properties file): I suppose THAT'S A BUG.
Then the SMTP server from my internet provider refuses it because it's not a valid internet email address (on windows machine name are juste machine name not in the internet form) ... otherwise that would not be too important (I assume a local SMTP server would not care).

 - ClassPathResource attached file
The file is read using ClassPathResource, but the file I want to send by email is not in the Class Path and I would expect that would be the case for quite a few developments.


So I created a new sendMessage method defining a from address (I think it's still necessary to have, even if mail.default.from would work) and an attachment as a File (see below) !
Whether it is interesting enough to integrate into the latest AppFuse, it's up to you to decide.


Cheers,
L@u
The Computing Froggy


===================== sendMessage =========
     /**
     * Convenience method for sending messages with attachments with a from source and File
     *
     * @param emailAddresses
     * @param attachedFile
     * @param bodyText
     * @param subject
     * @param attachmentName
     * @throws MessagingException
     * @author Ben Gill
     */
    public void sendMessage(String fromAdress, String[] emailAddresses,
                            File attachedFile, String bodyText,
                            String subject, String attachmentName)
    throws MessagingException {
        MimeMessage message =
            ((JavaMailSenderImpl) mailSender).createMimeMessage();

        // use the true flag to indicate you need a multipart message
        MimeMessageHelper helper = new MimeMessageHelper(message, true);

        helper.setTo(emailAddresses);
        helper.setText(bodyText);
        helper.setSubject(subject);
        helper.setFrom(fromAdress);

        helper.addAttachment(attachmentName, attachedFile);
 
        ((JavaMailSenderImpl) mailSender).send(message);
    }
================================

Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.