anonymous
2011-10-03 18:50:27 UTC
some of the code got cut off and it put "..." at the end by default, but i'm sure if you're good at this you will be able to fix it and help me. I'm a beginner.
this is the 3rd post and no answers so far on the other post...
Code
// Quiz And Sends Email With A Results Attachment
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.util.Properties;
public class QuizEmail {
private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final int SMTP_HOST_PORT = 465;
private static final String SMTP_AUTH_USER = "myEmail@gmail.com";
private static final String SMTP_AUTH_PWD = "myPassword";
private static final String fileAttachment = "C:/Users/myUsername/Desktop/results.txt…
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException, Exception {
QuizEmail quiz = new QuizEmail();
quiz.test();
}
public void test() throws FileNotFoundException, Exception {
String x;
PrintWriter outFile = new PrintWriter("C:/Users/myUsername/Desktop…
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String z = "Please answer the following questions to complete the survey.";
JOptionPane.showMessageDialog(null, z, "Quiz", JOptionPane.PLAIN_MESSAGE);
JFrame frame = new JFrame();
Object result0 = JOptionPane.showInputDialog(frame, "Question");
outFile.print("Question");
outFile.print(result0);
outFile.close();
Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", SMTP_HOST_NAME);
props.put("mail.smtps.auth", "true");
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Testing SMTP-SSL");
MimeBodyPart messageBodyPart =
new MimeBodyPart();
//fill message
messageBodyPart.setText("Hi");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachme…
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
message.addRecipient(Message.RecipientTy…
new InternetAddress("anotherEmail@hotmail.co…
transport.connect
(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
transport.sendMessage(message, message.getRecipients(Message.RecipientT…
transport.close();
}
}