saving and sending a file

4 views
Skip to first unread message

Isaac4given

unread,
Aug 21, 2007, 11:18:05 AM8/21/07
to WITL (Walk In The Light)
Finally, here is a program to take a screen shot, save it to a file,
and then send the screen shot file as an email attachment (and
JavaMail is not required!):

ImageIO.write(new Robot().createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize())), "png", new File(
"shot.png"));
Socket socket = new Socket(JOptionPane
.showInputDialog("Your SMTP server name?"), 25);
BufferedReader in = new BufferedReader(new InputStreamReader(socket
.getInputStream(), "8859_1"));
out = new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream(), "8859_1"));
String boundary = "DataSeparatorString";
for (String s : new String[] { "HELO theWorld",
"MAIL FROM: <i...@users.sourceforge.net>",
"RCPT TO: <i...@users.sourceforge.net>", "DATA" }) {
out.write(s + "\r\n");
out.flush();
s = in.readLine();
}
for (String s : new String[] { "MIME-Version: 1.0",
"Content-Type: multipart/mixed; boundary=\"" + boundary + "\"",
"\r\n--" + boundary,
"Content-Type: text/plain; charset=\"us-ascii\"\r\n",
"test\r\n\r\n", "\r\n--" + boundary,
"Content-Type:text/plain; name=shot.png",
"Content-Disposition: attachment;filename=\"shot.png\"",
"Content-transfer-encoding: base64\r\n", "{data}",
"\r\n--" + boundary, "\r\n\r\n--" + boundary + "--\r\n" }) {
if (s.equals("{data}")) {
MIMEBase64.encode("shot.png");
} else {
out.write(s + "\r\n");
out.flush();
}
}
for (String s : new String[] { ".", "QUIT" }) {
out.write(s + "\r\n");
out.flush();
s = in.readLine();
}
socket.close();
System.exit(0);

The whole program:

http://witl.googlegroups.com/web/OneTime.java

Reply all
Reply to author
Forward
0 new messages