We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Sending images over email
Page Index Toggle Pages: 1
Sending images over email (Read 1825 times)
Sending images over email
Mar 4th, 2008, 11:28pm
 
Hey hey. I was wondering if there is an easy way to send saved Processing frames over email?

Is there a library to attach images and text to an email and then sending it?

If not, I guess I would need to program my own lightweight email client using the Network library. Any pointers on how to do this? I know it's not that hard, just send some specific commands to the email server, the stream of bytes of the message, right?

Thanks a lot.
Re: Sending images over email
Reply #1 - Mar 5th, 2008, 2:38am
 
these 2 links may get you started. both are using javax.mail

daniel shiffman's e-mail processing example
example code from daniel shiffman for checking a POP3 account and sending emails from processing via SMTP.

Send Mail With Attachment Using JavaMail

for the latter example you would need to save the frame as a file first and then attach the file from the saved path to your mail.

best,
andi

Re: Sending images over email
Reply #2 - Mar 5th, 2008, 3:27am
 
Thanks a lot. I'll check them out and tell you how it went.
Re: Sending images over email
Reply #3 - Mar 5th, 2008, 4:47am
 
Yeey. It works. I can now send image files over email.

Thanks again.
Re: Sending images over email
Reply #4 - Mar 5th, 2008, 5:41am
 
great to hear.
would you mind sharing the code in case others have the same or similar questions. (if code is too long, maybe only the part where you save the image and put together the email)
best,
andi
Re: Sending images over email
Reply #5 - Mar 5th, 2008, 7:44am
 
Ok. Here's the code. I took it right from http://www.shiffman.net. And just replaced the message with a multipart message.

Three files.

save_attachment.pde
Code:

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

// Simple E-mail Checking
// This code requires the Java mail library
// smtp.jar, pop3.jar, mailapi.jar, imap.jar, activation.jar
// Download:// http://java.sun.com/products/javamail/

import javax.mail.*;
import javax.mail.internet.*;

void setup() {
size(200,200);

sendMail();
println("Finished");
noLoop();
}


Auth.pde
Code:

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

// Simple Authenticator
// Careful, this is terribly unsecure!!

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

public class Auth extends Authenticator {

public Auth() {
super();
}

public PasswordAuthentication getPasswordAuthentication() {
String username, password;
username = "username@gmail.com";
password = "password";
System.out.println("authenticating. . ");
return new PasswordAuthentication(username, password);
}
}



MailStuff
Code:

// 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("username@gmail.com", "Name"));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress("recipient@address.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)
{
e.printStackTrace();
}

}


I haven't found a way to send the file with a relative path, without the "c:\" (by the way, you need double \ so you escape one of them).

I don't have the part where I save the file, but it's not hard just to save it to "c:\image.jpg" and send that one.

I used my gmail account with that port and everything went well, although I don't know if the account/password are sent in the clear or encrypted, so you might wanna check first.
Re: Sending images over email
Reply #6 - Jan 2nd, 2009, 6:27am
 
hello, I'm studying processing recentrly. I want to send image over email. so this topic is very usefull for me.
but I don't know how can I send Image file. not text.
I'm a korean student, I'm not good at speaking English.
sorry for typographical errors.
thank you.
Re: Sending images over email
Reply #7 - Jan 2nd, 2009, 10:32am
 
This is in acapulco's last message. Look at "Part two is attachment" comment, code to attach an image is there.
Re: Sending images over email
Reply #8 - Jan 3rd, 2009, 9:21am
 
oh.. PhiLho. I missed last comment. Thanks again.
Page Index Toggle Pages: 1