Hi! What I have below is a program I've been working on that draws from two massive text documents of questions and answers to give users access to my musings on things in an impersonal, database format. Everything works up until void sendMail, which is a bit of broken code from another user that I hope can be stitched back together to address my problem. What I want it to do is send me an email every time it encounters a question that I haven't answered yet, so I can add it and its answer to my text documents. What I don't know is how to set the message text to be the question that my user asked... Would I somehow convert the "cur" or "to_match" to a text string and then set that text string as the body of the automated email? It's quite over my head, and any advice would be much appreciated! The email-sending code is from http://shiffman.net/2007/11/13/e-mail-processing/
String[] to_match = {
"HELLO?",
"WHO ARE YOU?",
"WHERE AM I?",
"OK?"
};
String[] resps = {
"Hello!", //"HELLO?",
"My name is Jack Miller.", // "WHO ARE YOU?",
"You are here.", //"WHERE AM I?",
"It will all be ok." //"OK?"
};
String top = "Ask me anything.";
String cur = "";
final int QUERY_LIMIT = 35;
void setup() {
size(1200, 500);
textSize(20);
fill(0);
PFont jackFont;
jackFont = loadFont("CourierNewPSMT-48.vlw");
textFont(jackFont);
to_match = loadStrings("to_match_file.txt");
resps = loadStrings("resps_file.txt");
}
void draw() {
background(255);
fill(0);
text(top, 20,20, 1200,500);
fill(225, 0, 0);
text("> "+ cur+((millis()%1000)<500?(" "):("_")), 20,440, 1200,400);
}
void keyPressed() {
if (key>='a'&&key<='z') {
if (cur.length()<=QUERY_LIMIT) cur = cur + char(key+'A'-'a');
}
if (key>='A'&&key<='Z') {
if (cur.length()<=QUERY_LIMIT) cur = cur + char(key);
}
if (key==' '&&(cur.length()<=QUERY_LIMIT)) cur=cur+' ';
if (key=='?'&&(cur.length()<=QUERY_LIMIT)) cur=cur+'?';
if (key==DELETE||key==BACKSPACE) {
if (cur.length()>0) cur=cur.substring(0, cur.length()-1);
}
if (key==ENTER||key==RETURN) {
if(cur.charAt(cur.length()-1)!='?'){
top = "Please ask a QUESTION.";
} else {
top = "I don't know. Ask something else.";
sendMail();
}
for(int i=0; i < to_match.length; i++){
if(cur.equals(to_match[i])){
top=resps[i];
}
}
cur="";
}
}
void sendMail() {
// Create a session
String host="smtp.gmail.com";
Properties props=new Properties();
Properties props = System.getProperties();
props.put("mail.pop3.host", "pop.gmail.com");
// SMTP Session
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "25");
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
{
// Make a new message
MimeMessage message = new MimeMessage(session);
// Who is this message from
message.setFrom(new InternetAddress("jackstarcat@gmail.com", "Ask Me Anything"));
// Who is this message to (we could do fancier things like make a list or add CC's)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("jackstarcat@gmail.com", false));
// Subject and body
message.setSubject("Quick Question:");
message.setText("????????????????????????????????????????????????????????????");
// We can do more here, set the date, the headers, etc.
Transport.send(message);
println("Mail sent!");
}
catch(Exception e)
{
e.printStackTrace();
}
}