How to send saved frames as attachments with processing's JAVAMAIL library?

edited March 2015 in Library Questions

Hey guys so I got this so far, the website is there, also this is from: https://processing.org/discourse/beta/num_1204669725.html

So how would I include my saved frames, that are in my data folder? I just want to send the whole folder, but I do not know what to do. When I do the code below, i get:

javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.FileNotFoundException: c:\image.jpg.jpg (The system cannot find the file specified) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1244) at javax.mail.Transport.send0(Transport.java:254) at javax.mail.Transport.send(Transport.java:124) at Email.sendMail(Email.java:134) at Email.setup(Email.java:62) at processing.core.PApplet.handleDraw(PApplet.java:2361) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source) Caused by: java.io.FileNotFoundException: c:\image.jpg.jpg (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(Unknown Source) at javax.activation.FileDataSource.getInputStream(Unknown Source) at javax.activation.DataHandler.writeTo(Unknown Source) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1608) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:961) at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:553) at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103) at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source) at javax.activation.DataHandler.writeTo(Unknown Source) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1608) at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1849) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1196) ... 8 more

So please help me on what I need to do. Thanks in advance: |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv CODE BELOW vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

// Daniel Shiffman
// http://www.shiffman.net

                                            // Example functions that send mail (smtp)
                                            // You can also do imap, but that's not included here

                                            // A function to check a mail account


                                            // A function to send mail
                                            void sendMail() {
                                              // Create a session
                                              String host="smtp.gmail.com";
                                              Properties props=new Properties();

                                              // SMTP Session
                                              props.put("mail.transport.protocol", "smtp");
                                              props.put("mail.smtp.host", host);
                                              props.put("mail.smtp.port", "587");
                                              props.put("mail.smtp.auth", "true");
                                              // We need TTLS, which gmail requires
                                              props.put("mail.smtp.starttls.enable","true");

                                              // Create a session
                                              Session session = Session.getDefaultInstance(props, new Auth());

                                              try
                                              {
                                                MimeMessage msg=new MimeMessage(session);
                                                msg.setFrom(new InternetAddress("myemal@gmail.com", "Name"));
                                                msg.addRecipient(Message.RecipientType.TO,new InternetAddress("myemail@gmail.com"));
                                                msg.setSubject("Email with Processing");
                                                BodyPart messageBodyPart = new MimeBodyPart();
                                             // Fill the message
                                                messageBodyPart.setText("Email sent with Processing");
                                                Multipart multipart = new MimeMultipart();
                                                multipart.addBodyPart(messageBodyPart);
                                               // Part two is attachment
                                                messageBodyPart = new MimeBodyPart();
                                                DataSource source = new FileDataSource("c:\\image.jpg");
                                                messageBodyPart.setDataHandler(new DataHandler(source));
                                                messageBodyPart.setFileName("image.jpg");
                                                multipart.addBodyPart(messageBodyPart);
                                                msg.setContent(multipart);
                                                msg.setSentDate(new Date());
                                                Transport.send(msg);
                                                println("Mail sent!");
                                              }
                                              catch(Exception e)
                                              {
                                                println("this is the problem:");
                                                e.printStackTrace();
                                              }

                                            }

Answers

Sign In or Register to comment.