Send Email FileNotFoundException

891 views
Skip to first unread message

Diogenes Buarque

unread,
Jul 9, 2011, 5:47:21 PM7/9/11
to play-framework
Hello, I have tried sent a email with file attached, but i get
FileNotFoundException error.

My form:
#{form action:@doApply(), enctype:'multipart/form-
data',id:'apply', method:"POST" }
<input type="text" name="name" class="validation" value="" />
<input type="file" name="file" class="validation"/>
#{/form}
My Controller:

public static void doApply(String name, File file) {
User u = new User("diogenes...@gmail.com", "1231231465564",
name);
u.save();
Mails.apply(file, u);
apply();
}

My Notifier:

public static void apply(File file, User u) {
setSubject("Welcome","");
addRecipient(u.email);
setFrom("con...@performanz.com.br");
EmailAttachment attachment = new EmailAttachment();
attachment.setDescription("Sampler Document");
attachment.setPath(file.getPath());
addAttachment(attachment);
send(u);
}

Error:
------------------------------------------------------------------------------------------------------------------------------------------------
@673baljij
The email has not been sent

Mail error
A mail error occured : Error while sending email

play.exceptions.MailException: Error while sending email
at play.libs.Mail$2.call(Mail.java:183)
at play.libs.Mail$2.call(Mail.java:175)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.commons.mail.EmailException: Sending the email
to the following server failed : smtp.gmail.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at play.libs.Mail$2.call(Mail.java:180)
... 6 more
Caused by: javax.mail.MessagingException: IOException while sending
message;
nested exception is:
java.io.FileNotFoundException: C:\Users\dbuarque\workspace\appmail\tmp
\uploads\1310247453265_0000000000\file\Teste Document.doc (The system
cannot find the path specified)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:
930)
at javax.mail.Transport.send0(Transport.java:191)
at javax.mail.Transport.send(Transport.java:120)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 8 more

Ronald Haring

unread,
Jul 10, 2011, 11:37:38 AM7/10/11
to play-framework
Probably your file only exists while the request is active. Try saving
the file first to somewhere on your file system and then send that
file

Regards
Ronald

On 9 jul, 23:47, Diogenes Buarque <diogenes.buar...@gmail.com> wrote:
> Hello, I have tried sent a email with file attached, but i get
> FileNotFoundException error.
>
> My form:
>                         #{form  action:@doApply(), enctype:'multipart/form-
> data',id:'apply', method:"POST" }
>                                                                 <input type="text" name="name" class="validation" value="" />
>                                                                 <input type="file" name="file" class="validation"/>
>                         #{/form}
> My Controller:
>
>      public static void doApply(String name, File file) {
>         User u = new User("diogenes.buar...@gmail.com", "1231231465564",
> name);
>         u.save();
>         Mails.apply(file, u);
>         apply();
>     }
>
> My Notifier:
>
>                    public static void apply(File file, User u) {
>                       setSubject("Welcome","");
>                       addRecipient(u.email);
>                       setFrom("cont...@performanz.com.br");

Diogenes Buarque

unread,
Jul 10, 2011, 8:00:52 PM7/10/11
to play-framework
Hi, i save in other folder, its works tks.
Reply all
Reply to author
Forward
0 new messages